mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing HtmlCoverageReport so it properly enables the test subject class as best it can.
This commit is contained in:
parent
bfcfa4c06e
commit
ed68368201
2 changed files with 19 additions and 6 deletions
|
@ -90,7 +90,6 @@ abstract class BaseCoverageReport {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the base path that the files we are interested in live in.
|
* Gets the base path that the files we are interested in live in.
|
||||||
* If appTest ist
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -56,7 +56,7 @@ HTML;
|
||||||
* @return string HTML diff.
|
* @return string HTML diff.
|
||||||
*/
|
*/
|
||||||
public function generateDiff($filename, $fileLines, $coverageData) {
|
public function generateDiff($filename, $fileLines, $coverageData) {
|
||||||
$output = '';
|
$output = '';
|
||||||
$diff = array();
|
$diff = array();
|
||||||
|
|
||||||
list($covered, $total) = $this->_calculateCoveredLines($fileLines, $coverageData);
|
list($covered, $total) = $this->_calculateCoveredLines($fileLines, $coverageData);
|
||||||
|
@ -72,8 +72,7 @@ HTML;
|
||||||
$coveringTests = array();
|
$coveringTests = array();
|
||||||
foreach ($coverageData[$lineno] as $test) {
|
foreach ($coverageData[$lineno] as $test) {
|
||||||
$testReflection = new ReflectionClass(current(explode('::', $test['id'])));
|
$testReflection = new ReflectionClass(current(explode('::', $test['id'])));
|
||||||
list($fileBasename,) = explode('.', basename($testReflection->getFileName()), 2);
|
$this->_testNames[] = $this->_guessSubjectName($testReflection);
|
||||||
$this->_testNames[] = $fileBasename;
|
|
||||||
$coveringTests[] = $test['id'];
|
$coveringTests[] = $test['id'];
|
||||||
}
|
}
|
||||||
$class = 'covered';
|
$class = 'covered';
|
||||||
|
@ -86,13 +85,28 @@ HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
$percentCovered = round(100 * $covered / $total, 2);
|
$percentCovered = round(100 * $covered / $total, 2);
|
||||||
|
|
||||||
$output .= $this->coverageHeader($filename, $percentCovered);
|
$output .= $this->coverageHeader($filename, $percentCovered);
|
||||||
$output .= implode("", $diff);
|
$output .= implode("", $diff);
|
||||||
$output .= $this->coverageFooter();
|
$output .= $this->coverageFooter();
|
||||||
return $output;
|
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.
|
* Renders the html for a single line in the html diff.
|
||||||
*
|
*
|
||||||
|
@ -171,4 +185,4 @@ HTML;
|
||||||
public function coverageFooter() {
|
public function coverageFooter() {
|
||||||
return "</pre></div></div>";
|
return "</pre></div></div>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue