Continuing work on updated code coverage reports.

This commit is contained in:
Mark Story 2010-05-09 00:40:05 -04:00
parent 955c6bea9f
commit 9a20a2344b
2 changed files with 32 additions and 19 deletions

View file

@ -143,9 +143,9 @@ PHP;
$result = $this->Coverage->getExecutableLines(explode("\n", $contents));
$expected = array(
0 => false,
1 => true,
2 => true,
3 => true,
1 => false,
2 => false,
3 => false,
4 => true,
5 => true,
6 => false,
@ -186,14 +186,14 @@ PHP;
3 => 1,
4 => 1,
5 => -1,
6 => -1,
7 => -1,
6 => 1,
7 => 1,
8 => 1,
9 => -1,
10 => 1,
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertRegExp('/<h2>myfile\.php Code coverage\: \d+\.\d+\%<\/h2>/', $result);
$this->assertRegExp('/<h2>myfile\.php Code coverage\: \d+\.?\d*\%<\/h2>/', $result);
$this->assertRegExp('/<div class="code-coverage-results">/', $result);
$this->assertRegExp('/<pre>/', $result);
foreach ($file as $i => $line) {

View file

@ -150,14 +150,27 @@ class HtmlCoverageReport {
$phpTagPattern = '/^[ |\t]*[<\?php|\?>]+[ |\t]*/';
$basicallyEmptyPattern = '/^[ |\t]*[{|}|\(|\)]+[ |\t]*/';
$commentStart = '/\/\*\*/';
$commentEnd = '/\*\//';
$ignoreStart = '/@codeCoverageIgnoreStart/';
$ignoreStop = '/@codeCoverageIgnoreEnd/';
$inComment = false;
foreach ($lines as $lineno => $line) {
$runnable = true;
if (preg_match($phpTagPattern, $line) || preg_match($basicallyEmptyPattern, $line)) {
$runnable = false;
}
if ($runnable && preg_match($commentStart, $line)) {
$runnable = false;
$inComment = true;
}
if ($inComment == true) {
$runnable = false;
}
if (!$runnable && preg_match($commentEnd, $line)) {
$inComment = false;
}
$output[$lineno] = $runnable;
}
return $output;
@ -183,22 +196,22 @@ class HtmlCoverageReport {
$executableLines = $this->getExecutableLines($fileLines);
foreach ($fileLines as $lineno => $line) {
$isExecutable = (isset($executableLines[$lineno]) && $executableLines[$lineno] == true);
$manualFind = (
isset($executableLines[$lineno]) &&
$executableLines[$lineno] == true &&
trim($line) != ''
);
$class = 'uncovered';
if (!$isExecutable) {
$class = 'ignored';
} elseif (isset($coverageData[$lineno]) && $coverageData[$lineno] > 0) {
$class = 'covered';
$class = 'ignored';
if ($manualFind) {
$class = 'uncovered';
$total++;
if (isset($coverageData[$lineno]) && $coverageData[$lineno] > 0) {
$class = 'covered';
$covered++;
}
}
$diff[] = $this->_paintLine($line, $lineno, $class);
if ($class == 'covered') {
$covered++;
}
if ($class == 'uncovered' || $class == 'covered') {
$total++;
}
}
$percentCovered = round($covered / $total, 2);