graphs for code coverage
This commit is contained in:
parent
00ff9f5b61
commit
a283acd7be
105
src/TUnit/framework/reporting/CoveragePieChart.php
Normal file
105
src/TUnit/framework/reporting/CoveragePieChart.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
class CoveragePalette extends ezcGraphPalette {
|
||||
protected $elementBorderWidth = 0;
|
||||
protected $fontName = 'Verdana';
|
||||
protected $fontColor = '#000000';
|
||||
protected $chartBackground = '#FFFFFF';
|
||||
protected $dataSetSymbol = array(ezcGraph::BULLET);
|
||||
protected $padding = 1;
|
||||
protected $margin = 1;
|
||||
protected $dataSetColor = array(
|
||||
'#009900', //covered
|
||||
'#990000', //uncovered
|
||||
'#999999' //dead
|
||||
);
|
||||
}
|
||||
|
||||
class CoverageDriver extends ezcGraphGdDriver {
|
||||
|
||||
public function getDataUri() {
|
||||
ob_start();
|
||||
$this->render(null);
|
||||
$data = ob_get_clean();
|
||||
|
||||
return 'data:image/png;base64,' . base64_encode($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CoverageRenderer extends ezcGraphRenderer3d {
|
||||
|
||||
public function renderToDataUri() {
|
||||
$this->finish();
|
||||
$data = $this->driver->getDataUri();
|
||||
$this->resetRenderer();
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CoveragePieChart extends ezcGraphPieChart {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->palette = new CoveragePalette();
|
||||
|
||||
$this->options->font = dirname(__FILE__) . '/data/consolas.ttf';
|
||||
$this->options->font->maxFontSize = 10;
|
||||
$this->options->label = '%2$s (%3$.1f%%)';
|
||||
$this->legend->position = ezcGraph::BOTTOM;
|
||||
|
||||
$this->renderer = new CoverageRenderer();
|
||||
|
||||
$this->renderer->options->pieChartRotation = .6;
|
||||
$this->renderer->options->pieChartShadowTransparency = .7;
|
||||
$this->renderer->options->pieChartShadowSize = 10;
|
||||
|
||||
$this->renderer->options->pieChartShadowColor = '#666666';
|
||||
|
||||
$this->renderer->options->moveOut = .2;
|
||||
$this->renderer->options->pieChartOffset = 45;
|
||||
$this->renderer->options->pieChartGleam = .1;
|
||||
$this->renderer->options->pieChartGleamColor = '#000000';
|
||||
$this->renderer->options->pieChartGleamBorder = 1;
|
||||
|
||||
$this->renderer->options->legendSymbolGleam = .4;
|
||||
$this->renderer->options->legendSymbolGleamSize = .9;
|
||||
$this->renderer->options->legendSymbolGleamColor = '#FFFFFF';
|
||||
|
||||
$this->renderer->options->symbolSize = 3.0;
|
||||
$this->renderer->options->showSymbol = true;
|
||||
$this->renderer->options->pieChartSymbolColor = '#66666666';
|
||||
//$this->options->labelCallback = 'label_callback';
|
||||
|
||||
$this->driver = new CoverageDriver();
|
||||
$this->driver->options->supersampling = 1;
|
||||
$this->driver->options->imageFormat = IMG_PNG;
|
||||
|
||||
$this->title = 'Code Coverage';
|
||||
$this->title->font->maxFontSize = 15;
|
||||
$this->title->font->textShadow = true;
|
||||
$this->title->font->textShadowOffset = 1;
|
||||
$this->title->font->textShadowColor = '#CCCCCC';
|
||||
}
|
||||
|
||||
public function renderToDataUri($width, $height, $uloc, $dloc, $cloc) {
|
||||
|
||||
$this->data['Code Coverage'] = new ezcGraphArrayDataSet(
|
||||
array(
|
||||
'Covered' => $cloc,
|
||||
'Uncovered' => $uloc,
|
||||
'Dead' => $dloc
|
||||
)
|
||||
);
|
||||
|
||||
$this->data['Code Coverage']->highlight['Covered'] = true;
|
||||
|
||||
$this->renderElements($width, $height);
|
||||
return $this->renderer->renderToDataUri();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -143,6 +143,7 @@
|
||||
//copy css over
|
||||
$template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR;
|
||||
copy($template . 'style.css', $coverageDir . DIRECTORY_SEPARATOR . 'style.css');
|
||||
copy($template . 'tunit.js', $coverageDir . DIRECTORY_SEPARATOR . 'tunit.js');
|
||||
}
|
||||
|
||||
private static function writeHtmlFile($sourceFile, $baseDir, $coverageDir, array $classData, array $coverageData) {
|
||||
@ -177,6 +178,7 @@
|
||||
$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>';
|
||||
|
||||
$classLoc += $methodData['loc'];
|
||||
$classDloc += $methodData['dloc'];
|
||||
@ -188,6 +190,7 @@
|
||||
$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>';
|
||||
$classCoverage .= $methodCoverage;
|
||||
}
|
||||
|
||||
@ -199,6 +202,7 @@
|
||||
$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>';
|
||||
$fileCoverage .= $classCoverage;
|
||||
unset($classCoverage, $methodCoverage, $classData, $refClass);
|
||||
|
||||
@ -440,6 +444,11 @@
|
||||
return $color;
|
||||
}
|
||||
|
||||
private static function getDataUri($loc, $dloc, $cloc) {
|
||||
$graph = new CoveragePieChart();
|
||||
return $graph->renderToDataUri(300, 225, $loc - $cloc - $dloc, $dloc, $cloc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
BIN
src/TUnit/framework/reporting/data/consolas.ttf
Normal file
BIN
src/TUnit/framework/reporting/data/consolas.ttf
Normal file
Binary file not shown.
@ -6,6 +6,7 @@
|
||||
<title>${title}</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||
<link rel="stylesheet" type="text/css" href="./style.css"/>
|
||||
<script type="text/javascript" src="./tunit.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -6,6 +6,7 @@
|
||||
<title>${title}</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||
<link rel="stylesheet" type="text/css" href="./style.css"/>
|
||||
<script type="text/javascript" src="./tunit.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -88,6 +88,9 @@ thead th {
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.coverage-graph td {
|
||||
text-align: center;
|
||||
}
|
||||
.coverage-percentage {
|
||||
text-align: center;
|
||||
}
|
||||
|
63
src/TUnit/framework/reporting/template/tunit.js
Normal file
63
src/TUnit/framework/reporting/template/tunit.js
Normal file
@ -0,0 +1,63 @@
|
||||
(function(){
|
||||
|
||||
var addEvent = function(evt, func, node) {
|
||||
node = node || window;
|
||||
if (node.addEventListener) {
|
||||
node.addEventListener(evt, func, true);
|
||||
} else if (node.attachEvent) {
|
||||
node.attachEvent("on" + evt, func);
|
||||
}
|
||||
}
|
||||
|
||||
var getElementsByClass = function(cls, root, tag) {
|
||||
root = root || document;
|
||||
tag = tag || "*";
|
||||
|
||||
var els = root.getElementsByTagName(tag), len = els.length, i, retval = [];
|
||||
var regex = new RegExp("(^|\\s)" + cls + "($|\\s)", "i");
|
||||
for (i = 0; i < len; i++) {
|
||||
if (els[i].className.match(regex) != null)
|
||||
retval.push(els[i]);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
var init = function() {
|
||||
var graphs = getElementsByClass("coverage-graph", document.getElementById("summary"), "tr");
|
||||
for (var i = 0, len = graphs.length, toggler; i < len; i++) {
|
||||
toggler = graphs[i].previousSibling.previousSibling;
|
||||
toggler.style.cursor = "pointer";
|
||||
|
||||
toggler.onmouseover = function() {
|
||||
var child = this.firstChild;
|
||||
do {
|
||||
if (child.nodeName === "TD" || child.nodeName === "TH") {
|
||||
child.style.backgroundColor = "#990099";
|
||||
child.style.color = "#FFFFFF";
|
||||
}
|
||||
} while (child = child.nextSibling);
|
||||
}
|
||||
|
||||
toggler.onmouseout = function() {
|
||||
var child = this.firstChild;
|
||||
do {
|
||||
if (child.nodeName === "TD" || child.nodeName === "TH") {
|
||||
child.style.backgroundColor = "";
|
||||
child.style.color = "";
|
||||
}
|
||||
} while (child = child.nextSibling);
|
||||
}
|
||||
|
||||
toggler.onclick = function() {
|
||||
var display = this.nextSibling.nextSibling.style.display;
|
||||
this.nextSibling.nextSibling.style.display = (display === "none") ? "table-row" : "none";
|
||||
}
|
||||
|
||||
graphs[i].style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
addEvent("load", init);
|
||||
|
||||
}());
|
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Autoload manifest
|
||||
*
|
||||
* Autogenerated by manifester.php on 2009-06-30 01:05:55
|
||||
* Autogenerated by manifester.php on 2009-06-30 20:59:11
|
||||
*
|
||||
* @package TUnit
|
||||
* @version 0.5.0
|
||||
@ -20,7 +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',
|
||||
'CoverageFilter' => 'TUnit/framework/reporting/CoverageFilter.php',
|
||||
'CoveragePalette' => 'TUnit/framework/reporting/CoveragePieChart.php',
|
||||
'CoveragePieChart' => 'TUnit/framework/reporting/CoveragePieChart.php',
|
||||
'CoverageRenderer' => 'TUnit/framework/reporting/CoveragePieChart.php',
|
||||
'CoverageReporter' => 'TUnit/framework/reporting/CoverageReporter.php',
|
||||
'DefaultConstraint' => 'TUnit/framework/constraints/DefaultConstraint.php',
|
||||
'EmptyConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
|
Loading…
Reference in New Issue
Block a user