Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Doctrine orm 是否有更好的方法为测试设置数据库?_Doctrine Orm_Phpunit - Fatal编程技术网

Doctrine orm 是否有更好的方法为测试设置数据库?

Doctrine orm 是否有更好的方法为测试设置数据库?,doctrine-orm,phpunit,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 = $t

我有以下测试课程:

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秒还不算太糟糕,但我计划给这个文件添加一个垃圾加载更多的测试,它只会随着时间的推移而增长


是否有办法设置模式,然后在下一次检查时检查该模式是否存在?如果是,什么也不做?然后在拆卸时,例如,从数据库中删除所有数据,但不要使用模式?

您可以使用静态方法setUpBeforeClass创建一次模式。可能需要阅读关于数据库测试的一章以获得更多提示。您没有说正在使用哪个数据库,但sqlite可能是最快的。您可能还会问自己,为什么需要这么多功能测试。也许可以使用嘲弄。