开发者

Separate seeds in PHPUnit

How do I create a separate seed for some test inside one test class? PHPUnit documentation includes this example

<?php
require_once 'PHPUnit/Extensions/Database/TestCase.php';

class DatabaseTest extends PHPUnit_Extensions_Database_TestCase
{
    protected function getConnection()
    {
        $pdo = new PDO('mysql:host=localhost;dbname=testdb', 'root', '');
        return $this->createDefaultDBConnection($pdo, 'testdb');
    }

    protected function getDataSet()
    {
        return $this->createFlatXMLDataSet(dirname(__FILE__).'/开发者_Go百科_files/bank-account-seed.xml');
    }
}
?>

But in this example I have one seed for all the tests inside my class.


I've found the answer. One possible way to do it is to use setDataSet method.

Example:

$newSet =   $this->createFlatXmlDataSet(dirname( __FILE__ ) . '/_files/members.xml');        
$this->getDatabaseTester()->setDataSet($newSet);
$this->getDatabaseTester()->onSetUp();

If you put it in your test function, it will reset default seed to any other, that you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜