From ed6836820179425d7b235c671ec400200129d041 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 21 May 2011 13:34:24 -0400 Subject: [PATCH] Fixing HtmlCoverageReport so it properly enables the test subject class as best it can. --- .../TestSuite/Coverage/BaseCoverageReport.php | 1 - .../TestSuite/Coverage/HtmlCoverageReport.php | 24 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php b/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php index 377211e50dc..f658abec4ee 100644 --- a/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php +++ b/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php @@ -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 */ diff --git a/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php b/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php index e57e9e3de2f..6810da25bb8 100644 --- a/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php +++ b/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php @@ -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); @@ -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'; @@ -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. * @@ -171,4 +185,4 @@ public function coverageHeader($filename, $percent) { public function coverageFooter() { return ""; } -} \ No newline at end of file +}