Skip to content
Permalink
Browse files

Making coverage reports show what tests covered the line being hovere…

…d over. Updating CSS to help facilitate hover effects.
  • Loading branch information...
markstory committed May 13, 2010
1 parent 687eab9 commit cb9d6f478def88c781d6f312bd7758808d2e8b7b
Showing with 19 additions and 3 deletions.
  1. +16 −3 cake/tests/lib/coverage/html_coverage_report.php
  2. +3 −0 cake/tests/lib/templates/header.php
@@ -190,7 +190,11 @@ function generateDiff($filename, $fileLines, $coverageData) {
foreach ($fileLines as $lineno => $line) {
$class = 'ignored';
$coveringTests = array();
if (isset($coverageData['covered'][$lineno])) {
$coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests(
$this->_rawCoverage, $filename, $lineno
);
$class = 'covered';
$covered++;
$total++;
@@ -200,7 +204,7 @@ function generateDiff($filename, $fileLines, $coverageData) {
} elseif (isset($coverageData['dead'][$lineno])) {
$class .= ' dead';
}
$diff[] = $this->_paintLine($line, $lineno, $class);
$diff[] = $this->_paintLine($line, $lineno, $class, $coveringTests);
}
$percentCovered = round(100 * $covered / $total, 2);
@@ -216,10 +220,19 @@ function generateDiff($filename, $fileLines, $coverageData) {
*
* @return void
*/
protected function _paintLine($line, $linenumber, $class) {
protected function _paintLine($line, $linenumber, $class, $coveringTests) {
$coveredBy = '';
if (!empty($coveringTests)) {
$coveredBy = "Covered by:\n";
foreach ($coveringTests as &$test) {
$coveredBy .= $test->getName() . "\n";
}
}
return sprintf(
'<div class="code-line %s"><span class="line-num">%s</span><span class="content">%s</span></div>',
'<div class="code-line %s" title="%s"><span class="line-num">%s</span><span class="content">%s</span></div>',
$class,
$coveredBy,
$linenumber,
htmlspecialchars($line)
);
@@ -90,6 +90,9 @@
div.code-coverage-results div.uncovered span.content { background:#ecc; }
div.code-coverage-results div.covered span.content { background:#cec; }
div.code-coverage-results div.ignored span.content { color:#aaa; }
div.code-coverage-results div:hover { background:#e8e8e8;}
div.code-coverage-results div.covered:hover span.content { background:#b4edb4;}
div.code-coverage-results div.uncovered:hover span.content { background:#edb4b4;}
div.code-coverage-results span.line-num {
color:#666;
display:block;

0 comments on commit cb9d6f4

Please sign in to comment.
You can’t perform that action at this time.