我想知道如何在
WebTestCase 实例。
例如查看在测试运行期间是否真的在 DB 中创建了实体。
有什么想法吗?
最佳答案
您可以通过内核检索 DIC(依赖注入(inject)容器),内核是 WebTestCase 的 protected 成员。
您可以在 WebTestCase 中执行此操作:
$em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager');
更新
根据您自己的评论,甚至有一个捷径(因为无论如何您都会有一个客户):
$client = $this->getClient();
$container = $client->getContainer();
原样 mentioned in the docs .
关于dependency-injection - 如何在 Symfony2 的 webtestcases 中获取 EntityManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5716433/