将几个 xdebug 覆盖率结果整理成一份报告? [英] Collate several xdebug coverage results into one report?

查看:33
本文介绍了将几个 xdebug 覆盖率结果整理成一份报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 php-code-coverage 从一个 HTTP 收集覆盖信息请求(通过 apache).我想存储来自多个请求的覆盖率数据,然后将结果整理成一份综合报告.

I am using the php-code-coverage to collect coverage information from one HTTP request (thru apache). I'd like to store the coverage data from several requests, and then collate the results into one comprehensive report.

这容易做到吗?我希望得到以下内容:

Is this easy to do? I was hoping for something along the lines of:

<?php
require 'PHP/CodeCoverage/Autoload.php';

$coverage = new PHP_CodeCoverage;
$coverage->start('<some request>');

// ...

$coverage->stop();

$writer = new PHP_CodeCoverage_Report_XXX;
$writer->process($coverage, '/tmp/reportYYY.xml');


// at some later date, collate all the results.
$writer = new PHP_CodeCoverage_Report_HTML;
$writer->process('/tmp/reportX.xml');
// ...
$writer->process('/tmp/reportZ.xml');

推荐答案

我已经使用 phpcov(通过作曲家安装)如上所述:

I've managed to get this running using phpcov (installed via composer) as mentioned:

使用 Apache .htaccess 预先/追加将 PHP_CodeCoverage 对象序列化到文件的 php 脚本,您需要适当调整路径:

Using Apache .htaccess to prepend/append php scripts that serialize PHP_CodeCoverage object to file, you'll need to adjust paths appropriately:

.htaccess:

# 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:

prepend.php:

<?php
require_once '../vendor/autoload.php';
$coverage = new PHP_CodeCoverage;
$coverage->start('Site coverage');

append.php:

append.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:

Because I'm serializing the object I had to edit /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,创建报告:

Then using phpcov, create the report:

./vendor/bin/phpcov merge --html="./cov/report/" ./cov -vvv

这篇关于将几个 xdebug 覆盖率结果整理成一份报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆