[英]ZF2.4 takes to long to run phpunit with code coverage enabled
我在代碼覆蓋率的速度方面遇到了麻煩。
我正在將ZF2 2.4與作曲家安裝的十幾個模塊一起使用。 當我運行無代碼覆蓋的測試時,結果需要5分鍾。 在詹金斯,完整構建需要15分鍾。
啟用代碼覆蓋率后,整個構建過程從上午0:00到5:30。
檢查結果后,我意識到服務/存儲庫/控制器類的平均測試時間為2.10分鍾。 可怕的是。
我對tdd開發非常陌生,可以達到100%的代碼覆蓋率,該系統具有三個模塊和一個10個實體。
我發現的唯一問題是我精通創建模擬,然后無法模擬所有應用程序服務,例如,存儲庫/服務/控制器正在實時添加,讀取,更新和刪除測試數據庫。
由於時間有限,我的主要問題是問題是否真的是不正確的模擬,因為如果代碼覆蓋范圍使用讀取了哪個文件夾的元信息,則在您開始輸入Vendor文件夾Doctrine時應該會感到震驚等等
那么這可能是主要問題嗎? 還沒有模擬銀行的聯系?
以我目前的技術知識,模擬將大為不同,但是直到今天,我在這里工作的人都沒有使用模擬並試圖進行革新。
該原理已經應用了Internet帖子中描述的所有技術以及stackoverflow中的其他問題,是否有任何新技術可以加快代碼覆蓋范圍?
有手冊集中在如何加速PHP代碼覆蓋的完整說明上? 完整的解釋?
謝謝收聽。
編輯:
Codeception Suite模塊配置:
namespace: ColumnNotNull
actor: Tester
paths:
tests: test
log: build/coverage
data: test/_data
helpers: test/_support
settings:
strict_xml: true
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
coverage:
whitelist:
include:
- src/*
exclude:
- src/ColumnNotNull/Fixture/*
- src/ColumnNotNull/Module.php*
blacklist:
include:
- build/*
- data/*
- language/*
- public/*
- schema/*
- test/*
- view/*
- src/ColumnNotNull/Fixture/*
編碼接收單元套件模塊配置:
class_name: UnitTester
modules:
enabled: [Asserts, UnitHelper, Db]
config:
Db:
dsn: 'mysql:dbname=pibernews;host=localhost'
user: 'piber'
password: 'secret'
dump: data/column-not-null.mysql.sql
coverage:
enabled: true
remote_enable : false
編碼接收項目套件
include:
- module/Column
- module/ColumnImage
- module/ColumnNotNull
paths:
log: build
settings:
colors: true
通過代碼接收,我可以從具有合並結果的不同模塊運行多個測試。
是一個項目,具有三個模塊。 具有驗收和功能測試。 接受+功能需要15分鍾才能運行,帶有代碼覆蓋率的單元需要5個小時。
如果沒有代碼覆蓋,則需要10分鍾來運行所有單元測試。 可以接受 但是我想減少代碼覆蓋時間,因為五個小時是不可接受的。
編輯2:
<?php
// This is global bootstrap for autoloading
include 'unit/GearBaseTest/ZendServiceLocator.php';
$zendServiceLocator = new \GearBaseTest\ZendServiceLocator();
_bootstrap.php文件
<?php
namespace GearBaseTest;
use Zend\Loader\AutoloaderFactory;
use Zend\Mvc\Service\ServiceManagerConfig;
use Zend\ServiceManager\ServiceManager;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
class ZendServiceLocator
{
public function __construct()
{
$this->chroot();
$zf2ModulePaths = array(
dirname(dirname(realpath(__DIR__ . '/../../')))
);
if (($path = $this->findParentPath('vendor'))) {
$zf2ModulePaths[] = $path;
}
if (($path = $this->findParentPath('module')) !== $zf2ModulePaths[0]) {
$zf2ModulePaths[] = $path;
}
$this->initAutoloader();
$env = getenv('APP_ENV') ? : 'testing';
$applicationConfig = include \GearBase\Module::getProjectFolder().'/config/application.config.php';
$config = array(
'module_listener_options' => array(
'module_paths' => $zf2ModulePaths,
'config_glob_paths' => array(
sprintf('config/autoload/{,*.}{global,%s,local}.php', $env)
)
),
'modules' => $applicationConfig['modules']
);
$serviceLocator = new ServiceManager(new ServiceManagerConfig());
$serviceLocator->setService('ApplicationConfig', $config);
$serviceLocator->get('ModuleManager')->loadModules();
$this->serviceLocator = $serviceLocator;
}
public function getServiceManager()
{
return $this->getServiceLocator()->get('ServiceManager');
}
public function chroot()
{
$rootPath = dirname($this->findParentPath('module'));
chdir($rootPath);
}
protected function findParentPath($path)
{
$dir = __DIR__;
$previousDir = '.';
while (! is_dir($dir . '/' . $path)) {
$dir = dirname($dir);
if ($previousDir === $dir) {
return false;
}
$previousDir = $dir;
}
return $dir . '/' . $path;
}
public function getEntityManager()
{
if (!isset($this->entityManager)) {
$this->entityManager = $this->getServiceLocator()
->get('doctrine.entitymanager.orm_default');
}
return $this->entityManager;
}
public function getServiceLocator()
{
return $this->serviceLocator;
}
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
if (!isset($this->serviceLocator)) {
$this->serviceLocator = $serviceLocator;
}
return $this->serviceLocator;
}
protected function initAutoloader()
{
$vendorPath = $this->findParentPath('vendor');
$zf2Path = getenv('ZF2_PATH');
if (! $zf2Path) {
if (defined('ZF2_PATH')) {
$zf2Path = ZF2_PATH;
} elseif (is_dir($vendorPath . '/ZF2/library')) {
$zf2Path = $vendorPath . '/ZF2/library';
} elseif (is_dir($vendorPath . '/zendframework/zendframework/library')) {
$zf2Path = $vendorPath . '/zendframework/zendframework/library';
}
}
if (! $zf2Path) {
throw new RuntimeException(
'Unable to load ZF2. Run `php composer.phar install` or' . ' define a ZF2_PATH environment variable.'
);
}
if (file_exists($vendorPath . '/autoload.php')) {
include $vendorPath . '/autoload.php';
}
include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'autoregister_zf' => true,
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__
)
)
));
}
}
ZendServiceLocator.php采集器。
您只需要將modules文件夾列入白名單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.