0
我对我的大多数测试用例使用LiipfunctionalBundle,即使它们是单元。仅仅因为那里的“便利”方法。最近我意识到我的测试性能非常糟糕,即使是单个服务单元测试。Symfony2容器/内核的测试性能
这个问题主要是如果我从容器中获得我的服务araises。其中在LiipTestBundle要求籽粒的创建和启动它:在“测试”环境
protected function getContainer()
{
if (!empty($this->kernelDir)) {
$tmpKernelDir = isset($_SERVER['KERNEL_DIR']) ? $_SERVER['KERNEL_DIR'] : null;
$_SERVER['KERNEL_DIR'] = getcwd().$this->kernelDir;
}
$cacheKey = $this->kernelDir.'|'.$this->environment;
if (empty($this->containers[$cacheKey])) {
$options = array(
'environment' => $this->environment
);
$kernel = $this->createKernel($options);
$start = microtime(true);
$kernel->boot();
$time = microtime(true) - $start;
print('boot:'.$time.PHP_EOL);
$this->containers[$cacheKey] = $kernel->getContainer();
}
if (isset($tmpKernelDir)) {
$_SERVER['KERNEL_DIR'] = $tmpKernelDir;
}
return $this->containers[$cacheKey];
}
在我的一些情况下,这启动花费6-10s。有时只有2秒。但它仍然非常缓慢,我想知道为什么这是如此之慢,我能做些什么。我已经开始在自己的测试用例中创建服务,而不是使用容器。但这也意味着需要更多的努力来创建测试用例。