Skip to content

Commit

Permalink
Added the ability to export the code coverage data in PHPUnit xml for…
Browse files Browse the repository at this point in the history
…mat (#33)
  • Loading branch information
tobiasstadler authored and DavertMik committed Oct 19, 2017
1 parent f08f20b commit 7cbeb70
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions c3.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class_alias('SebastianBergmann\CodeCoverage\Report\PHP', 'PHP_CodeCoverage_Repor
class_alias('SebastianBergmann\CodeCoverage\Report\Clover', 'PHP_CodeCoverage_Report_Clover');
class_alias('SebastianBergmann\CodeCoverage\Report\Crap4j', 'PHP_CodeCoverage_Report_Crap4j');
class_alias('SebastianBergmann\CodeCoverage\Report\Html\Facade', 'PHP_CodeCoverage_Report_HTML');
class_alias('SebastianBergmann\CodeCoverage\Report\Xml\Facade', 'PHP_CodeCoverage_Report_PHPUnit');
class_alias('SebastianBergmann\CodeCoverage\Exception', 'PHP_CodeCoverage_Exception');
}

Expand Down Expand Up @@ -162,6 +163,37 @@ function __c3_build_crap4j_report(PHP_CodeCoverage $codeCoverage, $path)
return $path . '.crap4j.xml';
}

function __c3_build_phpunit_report(PHP_CodeCoverage $codeCoverage, $path)
{
$writer = new PHP_CodeCoverage_Report_PHPUnit();
$writer->process($codeCoverage, $path . 'phpunit');

if (file_exists($path . '.tar')) {
unlink($path . '.tar');
}

$phar = new PharData($path . '.tar');
$phar->setSignatureAlgorithm(Phar::SHA1);
$files = $phar->buildFromDirectory($path . 'phpunit');
array_map('unlink', $files);

if (in_array('GZ', Phar::getSupportedCompression())) {
if (file_exists($path . '.tar.gz')) {
unlink($path . '.tar.gz');
}

$phar->compress(\Phar::GZ);

// close the file so that we can rename it
unset($phar);

unlink($path . '.tar');
rename($path . '.tar.gz', $path . '.tar');
}

return $path . '.tar';
}

function __c3_send_file($filename)
{
if (!headers_sent()) {
Expand Down Expand Up @@ -285,6 +317,13 @@ function __c3_clear()
__c3_error($e->getMessage());
}
return __c3_exit();
case 'phpunit':
try {
__c3_send_file(__c3_build_phpunit_report($codeCoverage, $path));
} catch (Exception $e) {
__c3_error($e->getMessage());
}
return __c3_exit();
}

} else {
Expand Down

0 comments on commit 7cbeb70

Please sign in to comment.