正如标题所说,我想知道如何在方法中加载数据夹具setUpBeforeClass
。测试类扩展了Liip\FunctionalTestBundle\Test\WebTestCase
.
目前我有这个:
public function setUp()
{
$this->client = $this->createClient();
$this->fixtures = $this->loadFixtures([
'App\DataFixtures\MyFixtures',
// more fixtures
])->getReferenceRepository();
}
然而,测试似乎花费了太长时间,实际上没有必要在每次测试之前加载固定装置。
当我尝试在其中加载固定装置时setUpBeforeClass
出现错误:
错误:当不在 /home/cezar/phpprojects/livegene/vendor/liip/functional-test-bundle/src/Test/WebTestCase.php:252 的对象上下文中时使用 $this
查看LiipFunctionalTestBundle的源代码可以发现以下代码片段:
protected function loadFixtures(array $classNames = [], bool $append = false, ?string $omName = null, string $registryName = 'doctrine', ?int $purgeMode = null): ?AbstractExecutor
{
$container = $this->getContainer();
$dbToolCollection = $container->get('liip_functional_test.services.database_tool_collection');
$dbTool = $dbToolCollection->get($omName, $registryName, $purgeMode, $this);
$dbTool->setExcludedDoctrineTables($this->excludedDoctrineTables);
return $dbTool->loadFixtures($classNames, $append);
}
是否有可能做到这一点,我希望什么,如果可以,如何实现?