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秒。但它仍然非常緩慢,我想知道爲什麼這是如此之慢,我能做些什麼。我已經開始在自己的測試用例中創建服務,而不是使用容器。但這也意味着需要更多的努力來創建測試用例。