Skip to content

Commit 7cbeb70

Browse files
tobiasstadlerDavertMik
authored andcommitted
Added the ability to export the code coverage data in PHPUnit xml format (#33)
1 parent f08f20b commit 7cbeb70

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

c3.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class_alias('SebastianBergmann\CodeCoverage\Report\PHP', 'PHP_CodeCoverage_Repor
5656
class_alias('SebastianBergmann\CodeCoverage\Report\Clover', 'PHP_CodeCoverage_Report_Clover');
5757
class_alias('SebastianBergmann\CodeCoverage\Report\Crap4j', 'PHP_CodeCoverage_Report_Crap4j');
5858
class_alias('SebastianBergmann\CodeCoverage\Report\Html\Facade', 'PHP_CodeCoverage_Report_HTML');
59+
class_alias('SebastianBergmann\CodeCoverage\Report\Xml\Facade', 'PHP_CodeCoverage_Report_PHPUnit');
5960
class_alias('SebastianBergmann\CodeCoverage\Exception', 'PHP_CodeCoverage_Exception');
6061
}
6162

@@ -162,6 +163,37 @@ function __c3_build_crap4j_report(PHP_CodeCoverage $codeCoverage, $path)
162163
return $path . '.crap4j.xml';
163164
}
164165

166+
function __c3_build_phpunit_report(PHP_CodeCoverage $codeCoverage, $path)
167+
{
168+
$writer = new PHP_CodeCoverage_Report_PHPUnit();
169+
$writer->process($codeCoverage, $path . 'phpunit');
170+
171+
if (file_exists($path . '.tar')) {
172+
unlink($path . '.tar');
173+
}
174+
175+
$phar = new PharData($path . '.tar');
176+
$phar->setSignatureAlgorithm(Phar::SHA1);
177+
$files = $phar->buildFromDirectory($path . 'phpunit');
178+
array_map('unlink', $files);
179+
180+
if (in_array('GZ', Phar::getSupportedCompression())) {
181+
if (file_exists($path . '.tar.gz')) {
182+
unlink($path . '.tar.gz');
183+
}
184+
185+
$phar->compress(\Phar::GZ);
186+
187+
// close the file so that we can rename it
188+
unset($phar);
189+
190+
unlink($path . '.tar');
191+
rename($path . '.tar.gz', $path . '.tar');
192+
}
193+
194+
return $path . '.tar';
195+
}
196+
165197
function __c3_send_file($filename)
166198
{
167199
if (!headers_sent()) {
@@ -285,6 +317,13 @@ function __c3_clear()
285317
__c3_error($e->getMessage());
286318
}
287319
return __c3_exit();
320+
case 'phpunit':
321+
try {
322+
__c3_send_file(__c3_build_phpunit_report($codeCoverage, $path));
323+
} catch (Exception $e) {
324+
__c3_error($e->getMessage());
325+
}
326+
return __c3_exit();
288327
}
289328

290329
} else {

0 commit comments

Comments
 (0)