Skip to content

Commit

Permalink
Support Cobertura code coverage format
Browse files Browse the repository at this point in the history
  • Loading branch information
zk-kb4 authored Oct 11, 2020
1 parent 1f5b39a commit e97df9c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions c3.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ function __c3_build_crap4j_report(PHP_CodeCoverage $codeCoverage, $path)
return $path . '.crap4j.xml';
}

function __c3_build_cobertura_report(PHP_CodeCoverage $codeCoverage, $path)
{
if (!class_exists(\SebastianBergmann\CodeCoverage\Report\Cobertura::class)) {
throw new Exception("Cobertura report requires php-code-coverage >= 9.2");
}
$writer = new \SebastianBergmann\CodeCoverage\Report\Cobertura();
$writer->process($codeCoverage, $path . '.cobertura.xml');

return $path . '.cobertura.xml';
}

function __c3_build_phpunit_report(PHP_CodeCoverage $codeCoverage, $path)
{
$writer = new PHP_CodeCoverage_Report_XML(\PHPUnit_Runner_Version::id());
Expand Down Expand Up @@ -339,6 +350,13 @@ function __c3_clear()
__c3_error($e->getMessage());
}
return __c3_exit();
case 'cobertura':
try {
__c3_send_file(__c3_build_cobertura_report($codeCoverage, $path));
} catch (Exception $e) {
__c3_error($e->getMessage());
}
return __c3_exit();
}
} else {
list($codeCoverage, ) = __c3_factory(null);
Expand Down

0 comments on commit e97df9c

Please sign in to comment.