added coverage-renderer option

This commit is contained in:
tmont 2009-07-01 06:06:46 +00:00
parent 0557fc93dd
commit aca040b78a
5 changed files with 52 additions and 34 deletions

View File

@ -96,14 +96,14 @@
protected function postRun() { protected function postRun() {
$html = $this->getOption('coverage-html'); $html = $this->getOption('coverage-html');
$console = $this->getOption('coverage-console'); $console = $this->getOption('coverage-console');
if ($html || $console) { if ($html !== null || $console === true) {
$coverage = xdebug_get_code_coverage(); $coverage = xdebug_get_code_coverage();
xdebug_stop_code_coverage(); xdebug_stop_code_coverage();
if ($console !== null) { if ($console === true) {
CoverageReporter::createConsoleReport($coverage); CoverageReporter::createConsoleReport($coverage);
} }
if ($html !== null) { if ($html !== null) {
CoverageReporter::createHtmlReport($html, $coverage); CoverageReporter::createHtmlReport($html, $coverage, $this->getOption('coverage-renderer'));
} }
unset($coverage); unset($coverage);
@ -171,6 +171,13 @@
throw new TUnitException('Could not create directory: ' . $options['coverage-html']); 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']);
}
}
} }
} }
} }
@ -186,11 +193,11 @@
*/ */
public function getAllowableOptions() { public function getAllowableOptions() {
return array( return array(
'bootstrap' => null, 'bootstrap' => null,
'recursive' => false, 'recursive' => false,
//'coverage-xml' => null, 'coverage-html' => null,
'coverage-html' => null, 'coverage-renderer' => null,
'coverage-console' => false 'coverage-console' => false
); );
} }

View File

@ -40,7 +40,7 @@
class CoveragePieChart extends ezcGraphPieChart { class CoveragePieChart extends ezcGraphPieChart {
public function __construct() { public function __construct($renderer) {
parent::__construct(); parent::__construct();
$this->palette = new CoveragePalette(); $this->palette = new CoveragePalette();
@ -50,6 +50,7 @@
$this->options->label = '%2$s (%3$.1f%%)'; $this->options->label = '%2$s (%3$.1f%%)';
$this->legend->position = ezcGraph::BOTTOM; $this->legend->position = ezcGraph::BOTTOM;
//use renderer here...
$this->renderer = new CoverageRenderer(); $this->renderer = new CoverageRenderer();
$this->renderer->options->pieChartRotation = .6; $this->renderer->options->pieChartRotation = .6;

View File

@ -110,7 +110,7 @@
fwrite(STDOUT, " Executable: " . ($totloc - $totdloc) . " (" . round($totcloc / ($totloc - $dloc) * 100, 2) . "%)\n"); 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); $coverageData = CoverageFilter::filter($coverageData);
$baseDir = array(); $baseDir = array();
@ -135,10 +135,10 @@
$classData = self::parseCoverageData($coverageData); $classData = self::parseCoverageData($coverageData);
foreach ($coverageData as $file => $data) { 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 //copy css over
$template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR; $template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR;
@ -146,7 +146,7 @@
copy($template . 'tunit.js', $coverageDir . DIRECTORY_SEPARATOR . 'tunit.js'); 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 //summary view
$fileCoverage = ''; $fileCoverage = '';
$classCoverage = ''; $classCoverage = '';
@ -178,7 +178,9 @@
$methodCoverage .= "<tr class=\"method-coverage\"><th>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#line-$methodStartLine\">$methodDeclaration</a></th>"; $methodCoverage .= "<tr class=\"method-coverage\"><th>&nbsp;&nbsp;&nbsp;&nbsp;<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-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 .= "<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']; $classLoc += $methodData['loc'];
$classDloc += $methodData['dloc']; $classDloc += $methodData['dloc'];
@ -190,7 +192,9 @@
$classCoverage .= "<tr class=\"class-coverage\"><th>&nbsp;&nbsp;<a href=\"#line-$classStartLine\">$class</a></th>"; $classCoverage .= "<tr class=\"class-coverage\"><th>&nbsp;&nbsp;<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-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 .= "<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; $classCoverage .= $methodCoverage;
} }
@ -202,7 +206,9 @@
$fileCoverage = "<tr class=\"file-coverage\"><th>$sourceFile</th>"; $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-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 .= "<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; $fileCoverage .= $classCoverage;
unset($classCoverage, $methodCoverage, $classData, $refClass); unset($classCoverage, $methodCoverage, $classData, $refClass);
@ -280,7 +286,7 @@
return file_put_contents($newFile, $template); 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(); $dirData = array();
foreach ($coverageData as $file => $data) { foreach ($coverageData as $file => $data) {
$dirs = preg_split('@\\' . DIRECTORY_SEPARATOR . '@', str_replace($baseDir, '', dirname($file) . DIRECTORY_SEPARATOR), -1, PREG_SPLIT_NO_EMPTY); $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-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 .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td>";
$info .= "</tr>\n"; $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 //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-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 .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td>";
$info .= "</tr>\n"; $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( $temp = str_replace(
@ -446,8 +456,8 @@
return $color; return $color;
} }
private static function getDataUri($loc, $dloc, $cloc) { private static function getDataUri($loc, $dloc, $cloc, $renderer) {
$graph = new CoveragePieChart(); $graph = new CoveragePieChart($renderer);
return $graph->renderToDataUri(300, 225, $loc - $cloc - $dloc, $dloc, $cloc); return $graph->renderToDataUri(300, 225, $loc - $cloc - $dloc, $dloc, $cloc);
} }

View File

@ -3,7 +3,7 @@
/** /**
* Autoload manifest * 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 * @package TUnit
* @version 0.5.0 * @version 0.5.0
@ -20,11 +20,11 @@
'ConsoleListener' => 'TUnit/framework/listeners/ConsoleListener.php', 'ConsoleListener' => 'TUnit/framework/listeners/ConsoleListener.php',
'ConsoleTestRunner' => 'TUnit/framework/ConsoleTestRunner.php', 'ConsoleTestRunner' => 'TUnit/framework/ConsoleTestRunner.php',
'Constraint' => 'TUnit/framework/constraints/Constraint.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', 'CoverageFilter' => 'TUnit/framework/reporting/CoverageFilter.php',
'CoveragePalette' => 'TUnit/framework/reporting/CoveragePieChart.php', 'CoveragePalette' => 'TUnit/framework/reporting/CoverageGraphs.php',
'CoveragePieChart' => 'TUnit/framework/reporting/CoveragePieChart.php', 'CoveragePieChart' => 'TUnit/framework/reporting/CoverageGraphs.php',
'CoverageRenderer' => 'TUnit/framework/reporting/CoveragePieChart.php', 'CoverageRenderer' => 'TUnit/framework/reporting/CoverageGraphs.php',
'CoverageReporter' => 'TUnit/framework/reporting/CoverageReporter.php', 'CoverageReporter' => 'TUnit/framework/reporting/CoverageReporter.php',
'DefaultConstraint' => 'TUnit/framework/constraints/DefaultConstraint.php', 'DefaultConstraint' => 'TUnit/framework/constraints/DefaultConstraint.php',
'EmptyConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php', 'EmptyConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',

View File

@ -43,14 +43,14 @@
global $switches; global $switches;
$switches = new CliSwitchCollection(); $switches = new CliSwitchCollection();
$switches->addSwitch(new CliSwitch(null, null, true, '<files>', 'Files and/or directories to parse for test cases')) $switches->addSwitch(new CliSwitch(null, null, true, '<files>', 'Files and/or directories to parse for test cases'))
->addSwitch(new CliSwitch('help', 'h', false, null, 'Display this help message (also --usage)')) ->addSwitch(new CliSwitch('help', 'h', false, null, 'Display this help message (also --usage)'))
->addSwitch(new CliSwitch('usage', null, false, null, 'Display this help message')) ->addSwitch(new CliSwitch('usage', null, false, null, 'Display this help message'))
->addSwitch(new CliSwitch('recursive', null, false, null, 'Recurse into subdirectories')) ->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('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-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')); ->addSwitch(new CliSwitch('coverage-console', null, false, null, 'Generate code coverage report suitable for console viewing'));
array_shift($argv); array_shift($argv);
$args = Cli::parseArgs($argv, $switches); $args = Cli::parseArgs($argv, $switches);