Skip to content

Commit

Permalink
Fixing HtmlCoverageReport so it properly enables the test subject cla…
Browse files Browse the repository at this point in the history
…ss as best it can.
  • Loading branch information
markstory committed May 21, 2011
1 parent bfcfa4c commit ed68368
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion lib/Cake/TestSuite/Coverage/BaseCoverageReport.php
Expand Up @@ -90,7 +90,6 @@ public function setCoverage($coverage) {

/**
* Gets the base path that the files we are interested in live in.
* If appTest ist
*
* @return void
*/
Expand Down
24 changes: 19 additions & 5 deletions lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php
Expand Up @@ -56,7 +56,7 @@ public function report() {
* @return string HTML diff.
*/
public function generateDiff($filename, $fileLines, $coverageData) {
$output = '';
$output = '';
$diff = array();

list($covered, $total) = $this->_calculateCoveredLines($fileLines, $coverageData);
Expand All @@ -72,8 +72,7 @@ public function generateDiff($filename, $fileLines, $coverageData) {
$coveringTests = array();
foreach ($coverageData[$lineno] as $test) {
$testReflection = new ReflectionClass(current(explode('::', $test['id'])));
list($fileBasename,) = explode('.', basename($testReflection->getFileName()), 2);
$this->_testNames[] = $fileBasename;
$this->_testNames[] = $this->_guessSubjectName($testReflection);
$coveringTests[] = $test['id'];
}
$class = 'covered';
Expand All @@ -86,13 +85,28 @@ public function generateDiff($filename, $fileLines, $coverageData) {
}

$percentCovered = round(100 * $covered / $total, 2);

$output .= $this->coverageHeader($filename, $percentCovered);
$output .= implode("", $diff);
$output .= $this->coverageFooter();
return $output;
}

/**
* Guess the classname the test was for based on the test case filename.
*
* @param ReflectionClass $testReflection.
* @return string Possible test subject name.
*/
protected function _guessSubjectName($testReflection) {
$basename = basename($testReflection->getFilename());
if (strpos($basename, '.test') !== false) {
list($subject, ) = explode('.', $basename, 2);
return $subject;
}
$subject = str_replace('Test.php', '', $basename);
return $subject;
}

/**
* Renders the html for a single line in the html diff.
*
Expand Down Expand Up @@ -171,4 +185,4 @@ public function coverageHeader($filename, $percent) {
public function coverageFooter() {
return "</pre></div></div>";
}
}
}

0 comments on commit ed68368

Please sign in to comment.