如前所述,我已经设法使用phpcov(通过 composer 安装)运行它:
使用 Apache .htaccess 将 PHP_CodeCoverage 对象序列化到文件的前置/附加 php 脚本,您需要适当地调整路径:
.ht 访问:
# Prepend the file
php_value auto_prepend_file "prepend.php"
# Append file to bottom of page
php_value auto_append_file "append.php"
prepend.php:
<?php
require_once '../vendor/autoload.php';
$coverage = new PHP_CodeCoverage;
$coverage->start('Site coverage');
追加.php:
<?php
$coverage->stop();
$cov = serialize($coverage); //serialize object to disk
file_put_contents('../cov/site.' . date('U') . '.cov', $cov);
因为我正在序列化我必须编辑/vendor/phpunit/phpcov/src/MergeCommand.php 的对象:
protected function execute(InputInterface $input, OutputInterface $output)
{
$mergedCoverage = new PHP_CodeCoverage;
$finder = new FinderFacade(
array($input->getArgument('directory')),
array(),
array('*.cov')
);
foreach ($finder->findFiles() as $file) {
print "Merging $file" . PHP_EOL;
//$_coverage = include($file);
$_coverage = unserialize(file_get_contents($file));
$mergedCoverage->merge($_coverage);
unset($_coverage);
}
$this->handleReports($mergedCoverage, $input, $output);
}
然后使用 phpcov,创建报告:
./vendor/bin/phpcov merge --html="./cov/report/" ./cov -vvv