【发布时间】:2021-11-04 02:46:06
【问题描述】:
我正在使用 PHPUnit (9.5) 和 Symfony (5.3)。
对于我的测试,我使用 config/packages/test/doctrine.yaml 中的默认测试数据库配置:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
所以我的测试使用与 prod 相同的数据库,后缀为“_test”。
我在 tests/bootstrap.php 中添加了一些代码,以便在每次测试运行之前自动创建/重置数据库:
// delete database if exists, then create
passthru('php bin/console doctrine:database:drop --env=test --force --if-exists');
passthru('php bin/console doctrine:database:create --env=test');
// run migrations
passthru('php bin/console doctrine:migrations:migrate --env=test -n');
我使用 dama/doctrine-test-bundle 进行每个测试的自动交易。
效果很好,但我有一个问题:
有没有办法在测试运行结束时删除数据库? (就像我在 bootstrap.php 中所做的那样)
【问题讨论】:
标签: symfony testing doctrine-orm phpunit