本文介绍了phpunit合并两个或多个clover.xml报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个有关项目不同扩展名的clover.xml报告.我想将它们合并为一个clover.xml,然后将其创建为三叶草html.但是我看不到phpunit类PHP_CodeCoveragePHP_CodeCoverage_Report_HTMLPHP_CodeCoverage_Report_Clover.

I have several clover.xml reports of different extensions of a projects. I want to combine them into one clover.xml and then create it into a clover html. But i see no way with the phpunit classes PHP_CodeCoverage, PHP_CodeCoverage_Report_HTML, PHP_CodeCoverage_Report_Clover.

这些类都不接受现有的clover.xml.我以为我也许可以使用PHP_CodeCoverage的追加和合并方法.但这不接受文件.

None of these classes accept an existing clover.xml. I thought I might be able to work with the methods append and merge of PHP_CodeCoverage. But that does not accept files.

推荐答案

几年后,此问题仍然部分未解决. SB有一个项目,可以合并三叶草文件,但需要php 5.6.

Years later this issue is still partly unsolved. There is a project by SB that can merge clover files, but it requires php 5.6.

以上答案均无法很好地发挥作用. 这里是合并的要点.建设性的批评主义欢迎.

None of the answers above work sufficiently well. Here is a gist of a merge thrown together. Constructive critisism welcome.

用法:

php clover-merge.php -o merged.xml -f clover-phpunit.xml -f clover-phpspec.xml

也将其张贴在这里以供后代使用:

Posting it here for posterity too:

<?php
$options = getopt("f:o:");
if (! isset($options['f'])) {
    echo "Files have to be specified with -f\n";
    exit(1);
}
if (! isset($options['o'])) {
    echo "Output has to be specified with -o\n";
    exit(1);
}

$files = $options['f'];
if (! is_array($files)) {
    $files = array($files);
}
$output = $options['o'];

$buffer = '';
foreach ($files as $file) {
    if (! file_exists($file)) {
        echo "File '$file' doesn't exist\n";
        exit(2);
    }
    $report = simplexml_load_file($file);
    $buffer .= $report->project->asXML();
}

$fh = fopen($output ,'w');
if (! $fh) {
    echo "Cannot open '$output' for writing\n";
    exit(2);
}
fwrite($fh, sprintf('<?xml version="1.0" encoding="UTF-8"?><coverage>%s</coverage>', $buffer));
fclose($fh);

这篇关于phpunit合并两个或多个clover.xml报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 00:53