added coverage-renderer option
This commit is contained in:
parent
0557fc93dd
commit
aca040b78a
@ -96,14 +96,14 @@
|
||||
protected function postRun() {
|
||||
$html = $this->getOption('coverage-html');
|
||||
$console = $this->getOption('coverage-console');
|
||||
if ($html || $console) {
|
||||
if ($html !== null || $console === true) {
|
||||
$coverage = xdebug_get_code_coverage();
|
||||
xdebug_stop_code_coverage();
|
||||
if ($console !== null) {
|
||||
if ($console === true) {
|
||||
CoverageReporter::createConsoleReport($coverage);
|
||||
}
|
||||
if ($html !== null) {
|
||||
CoverageReporter::createHtmlReport($html, $coverage);
|
||||
CoverageReporter::createHtmlReport($html, $coverage, $this->getOption('coverage-renderer'));
|
||||
}
|
||||
|
||||
unset($coverage);
|
||||
@ -171,6 +171,13 @@
|
||||
throw new TUnitException('Could not create directory: ' . $options['coverage-html']);
|
||||
}
|
||||
}
|
||||
|
||||
//check the renderer
|
||||
if ($options['coverage-renderer'] !== null) {
|
||||
if (!in_array($options['coverage-renderer'], array('png'))) {
|
||||
throw new InvalidOptionException('coverage-renderer', 'unknown renderer: ' . $options['renderer']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,8 +195,8 @@
|
||||
return array(
|
||||
'bootstrap' => null,
|
||||
'recursive' => false,
|
||||
//'coverage-xml' => null,
|
||||
'coverage-html' => null,
|
||||
'coverage-renderer' => null,
|
||||
'coverage-console' => false
|
||||
);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@
|
||||
|
||||
class CoveragePieChart extends ezcGraphPieChart {
|
||||
|
||||
public function __construct() {
|
||||
public function __construct($renderer) {
|
||||
parent::__construct();
|
||||
|
||||
$this->palette = new CoveragePalette();
|
||||
@ -50,6 +50,7 @@
|
||||
$this->options->label = '%2$s (%3$.1f%%)';
|
||||
$this->legend->position = ezcGraph::BOTTOM;
|
||||
|
||||
//use renderer here...
|
||||
$this->renderer = new CoverageRenderer();
|
||||
|
||||
$this->renderer->options->pieChartRotation = .6;
|
@ -110,7 +110,7 @@
|
||||
fwrite(STDOUT, " Executable: " . ($totloc - $totdloc) . " (" . round($totcloc / ($totloc - $dloc) * 100, 2) . "%)\n");
|
||||
}
|
||||
|
||||
public static function createHtmlReport($coverageDir, array $coverageData) {
|
||||
public static function createHtmlReport($coverageDir, array $coverageData, $renderer = null) {
|
||||
$coverageData = CoverageFilter::filter($coverageData);
|
||||
|
||||
$baseDir = array();
|
||||
@ -135,10 +135,10 @@
|
||||
$classData = self::parseCoverageData($coverageData);
|
||||
|
||||
foreach ($coverageData as $file => $data) {
|
||||
self::writeHtmlFile($file, $baseDir, $coverageDir, $classData[$file], $data);
|
||||
self::writeHtmlFile($file, $baseDir, $coverageDir, $classData[$file], $data, $renderer);
|
||||
}
|
||||
|
||||
self::writeHtmlDirectories($coverageDir, $baseDir, $coverageData);
|
||||
self::writeHtmlDirectories($coverageDir, $baseDir, $coverageData, $renderer);
|
||||
|
||||
//copy css over
|
||||
$template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR;
|
||||
@ -146,7 +146,7 @@
|
||||
copy($template . 'tunit.js', $coverageDir . DIRECTORY_SEPARATOR . 'tunit.js');
|
||||
}
|
||||
|
||||
private static function writeHtmlFile($sourceFile, $baseDir, $coverageDir, array $classData, array $coverageData) {
|
||||
private static function writeHtmlFile($sourceFile, $baseDir, $coverageDir, array $classData, array $coverageData, $renderer) {
|
||||
//summary view
|
||||
$fileCoverage = '';
|
||||
$classCoverage = '';
|
||||
@ -178,7 +178,9 @@
|
||||
$methodCoverage .= "<tr class=\"method-coverage\"><th> <a href=\"#line-$methodStartLine\">$methodDeclaration</a></th>";
|
||||
$methodCoverage .= "<td class=\"coverage-ratio\" style=\"background-color: $percentageData[1]\">$methodData[cloc] / " . ($methodData['loc'] - $methodData['dloc']) . "</td>";
|
||||
$methodCoverage .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td></tr>\n";
|
||||
$methodCoverage .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($methodData['loc'], $methodData['dloc'], $methodData['cloc']) . '"/></td></tr>';
|
||||
if ($renderer !== null) {
|
||||
$methodCoverage .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($methodData['loc'], $methodData['dloc'], $methodData['cloc'], $renderer) . '"/></td></tr>';
|
||||
}
|
||||
|
||||
$classLoc += $methodData['loc'];
|
||||
$classDloc += $methodData['dloc'];
|
||||
@ -190,7 +192,9 @@
|
||||
$classCoverage .= "<tr class=\"class-coverage\"><th> <a href=\"#line-$classStartLine\">$class</a></th>";
|
||||
$classCoverage .= "<td class=\"coverage-ratio\" style=\"background-color: $percentageData[1]\">$classCloc / " . ($classLoc - $classDloc) . "</td>";
|
||||
$classCoverage .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td></tr>\n";
|
||||
$classCoverage .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($classLoc, $classDloc, $classCloc) . '"/></td></tr>';
|
||||
if ($renderer !== null) {
|
||||
$classCoverage .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($classLoc, $classDloc, $classCloc, $renderer) . '"/></td></tr>';
|
||||
}
|
||||
$classCoverage .= $methodCoverage;
|
||||
}
|
||||
|
||||
@ -202,7 +206,9 @@
|
||||
$fileCoverage = "<tr class=\"file-coverage\"><th>$sourceFile</th>";
|
||||
$fileCoverage .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$tcloc / " . ($tloc - $tdloc) . "</td>";
|
||||
$fileCoverage .= "<td class=\"coverage-ratio\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td></tr>\n";
|
||||
$fileCoverage .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($tloc, $tdloc, $tcloc) . '"/></td></tr>';
|
||||
if ($renderer !== null) {
|
||||
$fileCoverage .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($tloc, $tdloc, $tcloc, $renderer) . '"/></td></tr>';
|
||||
}
|
||||
$fileCoverage .= $classCoverage;
|
||||
unset($classCoverage, $methodCoverage, $classData, $refClass);
|
||||
|
||||
@ -280,7 +286,7 @@
|
||||
return file_put_contents($newFile, $template);
|
||||
}
|
||||
|
||||
private static function writeHtmlDirectories($coverageDir, $baseDir, array $coverageData) {
|
||||
private static function writeHtmlDirectories($coverageDir, $baseDir, array $coverageData, $renderer) {
|
||||
$dirData = array();
|
||||
foreach ($coverageData as $file => $data) {
|
||||
$dirs = preg_split('@\\' . DIRECTORY_SEPARATOR . '@', str_replace($baseDir, '', dirname($file) . DIRECTORY_SEPARATOR), -1, PREG_SPLIT_NO_EMPTY);
|
||||
@ -345,7 +351,9 @@
|
||||
$info .= '<td class="coverage-ratio" style="background-color: ' . $percentageData[1] . '">' . $subdata['cloc'] . ' / ' . ($subdata['loc'] - $subdata['dloc']) . '</td>';
|
||||
$info .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td>";
|
||||
$info .= "</tr>\n";
|
||||
$info .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($subdata['loc'], $subdata['dloc'], $subdata['cloc']) . '"/></td></tr>';
|
||||
if ($renderer !== null) {
|
||||
$info .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($subdata['loc'], $subdata['dloc'], $subdata['cloc'], $renderer) . '"/></td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
//regular files in current directory
|
||||
@ -355,7 +363,9 @@
|
||||
$info .= '<td class="coverage-ratio" style="background-color: ' . $percentageData[1] . '">' . $fileData['cloc'] . ' / ' . ($fileData['loc'] - $fileData['dloc']) . '</td>';
|
||||
$info .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td>";
|
||||
$info .= "</tr>\n";
|
||||
$info .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($fileData['loc'], $fileData['dloc'], $fileData['cloc']) . '"/></td></tr>';
|
||||
if ($renderer !== null) {
|
||||
$info .= '<tr class="coverage-graph"><td colspan="3"><img alt="Code Coverage results" src="' . self::getDataUri($fileData['loc'], $fileData['dloc'], $fileData['cloc'], $renderer) . '"/></td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
$temp = str_replace(
|
||||
@ -446,8 +456,8 @@
|
||||
return $color;
|
||||
}
|
||||
|
||||
private static function getDataUri($loc, $dloc, $cloc) {
|
||||
$graph = new CoveragePieChart();
|
||||
private static function getDataUri($loc, $dloc, $cloc, $renderer) {
|
||||
$graph = new CoveragePieChart($renderer);
|
||||
return $graph->renderToDataUri(300, 225, $loc - $cloc - $dloc, $dloc, $cloc);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Autoload manifest
|
||||
*
|
||||
* Autogenerated by manifester.php on 2009-06-30 20:59:11
|
||||
* Autogenerated by manifester.php on 2009-06-30 23:05:13
|
||||
*
|
||||
* @package TUnit
|
||||
* @version 0.5.0
|
||||
@ -20,11 +20,11 @@
|
||||
'ConsoleListener' => 'TUnit/framework/listeners/ConsoleListener.php',
|
||||
'ConsoleTestRunner' => 'TUnit/framework/ConsoleTestRunner.php',
|
||||
'Constraint' => 'TUnit/framework/constraints/Constraint.php',
|
||||
'CoverageDriver' => 'TUnit/framework/reporting/CoveragePieChart.php',
|
||||
'CoverageDriver' => 'TUnit/framework/reporting/CoverageGraphs.php',
|
||||
'CoverageFilter' => 'TUnit/framework/reporting/CoverageFilter.php',
|
||||
'CoveragePalette' => 'TUnit/framework/reporting/CoveragePieChart.php',
|
||||
'CoveragePieChart' => 'TUnit/framework/reporting/CoveragePieChart.php',
|
||||
'CoverageRenderer' => 'TUnit/framework/reporting/CoveragePieChart.php',
|
||||
'CoveragePalette' => 'TUnit/framework/reporting/CoverageGraphs.php',
|
||||
'CoveragePieChart' => 'TUnit/framework/reporting/CoverageGraphs.php',
|
||||
'CoverageRenderer' => 'TUnit/framework/reporting/CoverageGraphs.php',
|
||||
'CoverageReporter' => 'TUnit/framework/reporting/CoverageReporter.php',
|
||||
'DefaultConstraint' => 'TUnit/framework/constraints/DefaultConstraint.php',
|
||||
'EmptyConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
|
@ -48,8 +48,8 @@
|
||||
->addSwitch(new CliSwitch('usage', null, false, null, 'Display this help message'))
|
||||
->addSwitch(new CliSwitch('recursive', null, false, null, 'Recurse into subdirectories'))
|
||||
->addSwitch(new CliSwitch('bootstrap', 'b', false, 'file', 'File to include before tests are run'))
|
||||
//->addSwitch(new CliSwitch('coverage-xml', null, false, 'file', 'Generate code coverage report in XML clover format (requires xdebug)'))
|
||||
->addSwitch(new CliSwitch('coverage-html', null, false, 'dir', 'Generate code coverage report in HTML (requires xdebug, optionally uses ezComponents)'))
|
||||
->addSwitch(new CliSwitch('coverage-renderer', null, false, 'type', 'Use with coverage-html to render code coverage graphs; png is the only type supported right now'))
|
||||
->addSwitch(new CliSwitch('coverage-console', null, false, null, 'Generate code coverage report suitable for console viewing'));
|
||||
|
||||
array_shift($argv);
|
||||
|
Loading…
Reference in New Issue
Block a user