Fixing HtmlCoverageReport so it properly enables the test subject class as best it can.

This commit is contained in:
mark_story 2011-05-21 13:34:24 -04:00
parent bfcfa4c06e
commit ed68368201
2 changed files with 19 additions and 6 deletions

View file

@ -90,7 +90,6 @@ abstract class BaseCoverageReport {
/**
* Gets the base path that the files we are interested in live in.
* If appTest ist
*
* @return void
*/

View file

@ -56,7 +56,7 @@ HTML;
* @return string HTML diff.
*/
public function generateDiff($filename, $fileLines, $coverageData) {
$output = '';
$output = '';
$diff = array();
list($covered, $total) = $this->_calculateCoveredLines($fileLines, $coverageData);
@ -72,8 +72,7 @@ HTML;
$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';
@ -86,13 +85,28 @@ HTML;
}
$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.
*
@ -171,4 +185,4 @@ HTML;
public function coverageFooter() {
return "</pre></div></div>";
}
}
}