有没有更好的方法来设置测试数据库?

时间:2015-05-06 21:30:55

标签: doctrine-orm phpunit

我有以下测试类:

class UserTest extends PHPUnit_Framework_TestCase {

    protected $em;

    public function setUp() {
        $this->em = getEntityManager(true);
        $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);

        $mdFactory = $this->em->getMetadataFactory();
        $tool->dropSchema($mdFactory->getallMetadata());
        $tool->createSchema($mdFactory->getallMetadata());
        parent::setUp();
    }

    public function tearDown() {
        $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);

        $mdFactory = $this->em->getMetadataFactory();
        $tool->dropSchema($mdFactory->getallMetadata());
        parent::tearDown();
    }
    ...
}

setUp函数使用生产模式设置测试数据库,然后在每次测试后将其删除。现在我的出局就是:

Configuration read from /var/www/html/Grab-Project/phpunit.xml

...

Time: 8.03 seconds, Memory: 20.00Mb

OK (3 tests, 3 assertions)

8秒不是太糟糕了,但是我计划在这个文件中添加一个废话加载更多的测试,它只会及时增长。

有没有办法设置架构,然后在下次检查时检查架构是否存在?如果这样做什么?然后拆除说,删除数据库中的所有数据,但只保留架构?

0 个答案:

没有答案