我按照站点
Testing Symfony Apps with a Disposable Database教程.
我在我的测试用例中添加了Fixtures,并且在SetUp期间没有出现错误.如果我在灯具中添加一个错误(例如,将nullable = false字段留空),则会显示错误,因此此代码肯定会被执行.
我在我的测试用例中添加了Fixtures,并且在SetUp期间没有出现错误.如果我在灯具中添加一个错误(例如,将nullable = false字段留空),则会显示错误,因此此代码肯定会被执行.
我的配置:
- doctrine:
- dbal:
- default_connection: memory
- connections:
- memory:
- driver: pdo_sqlite
- memory: true
- charset: UTF8
我的WebTestCase中的SetUp:
- protected function setUp() {
- parent::setUp();
- self::bootKernel();
- DatabasePrimer::prime(self::$kernel);
- $this->loadFixtures([
- 'AppBundle\DataFixtures\ORM\UserData','AppBundle\DataFixtures\ORM\ArtistData'
- ]);
- }
然而,在我的WebTestCase中,似乎没有表存在.
输出抛出一个Doctrine异常,说我的表不存在.
- sqlSTATE[HY000]: General error: 1 no such table: my_user_table
如果我在文件中切换到sql_lite,一切正常,没有任何其他更改:
- dbal:
- default_connection: file
- connections:
- file:
- driver: pdo_sqlite
- path: %kernel.cache_dir%/test.db
- charset: UTF8
任何人都有成功的说教程或使用sqlite内存数据库进行单元测试,并有任何提示或想法?
更新:
我将我的安装程序更改为此以确保内核不会在其间关闭.它没有帮助:
- parent::setUp();
- $this->client = $this->getClient();
- MemoryDbPrimer::prime(self::$kernel);
- $this->loadFixtures([
- 'AppBundle\DataFixtures\ORM\UserData','AppBundle\DataFixtures\ORM\ArtistData'
- ]);