mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Continuing work on updated code coverage reports.
This commit is contained in:
parent
955c6bea9f
commit
9a20a2344b
2 changed files with 32 additions and 19 deletions
|
@ -143,9 +143,9 @@ PHP;
|
||||||
$result = $this->Coverage->getExecutableLines(explode("\n", $contents));
|
$result = $this->Coverage->getExecutableLines(explode("\n", $contents));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
0 => false,
|
0 => false,
|
||||||
1 => true,
|
1 => false,
|
||||||
2 => true,
|
2 => false,
|
||||||
3 => true,
|
3 => false,
|
||||||
4 => true,
|
4 => true,
|
||||||
5 => true,
|
5 => true,
|
||||||
6 => false,
|
6 => false,
|
||||||
|
@ -186,14 +186,14 @@ PHP;
|
||||||
3 => 1,
|
3 => 1,
|
||||||
4 => 1,
|
4 => 1,
|
||||||
5 => -1,
|
5 => -1,
|
||||||
6 => -1,
|
6 => 1,
|
||||||
7 => -1,
|
7 => 1,
|
||||||
8 => 1,
|
8 => 1,
|
||||||
9 => -1,
|
9 => -1,
|
||||||
10 => 1,
|
10 => 1,
|
||||||
);
|
);
|
||||||
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
|
$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('/<div class="code-coverage-results">/', $result);
|
||||||
$this->assertRegExp('/<pre>/', $result);
|
$this->assertRegExp('/<pre>/', $result);
|
||||||
foreach ($file as $i => $line) {
|
foreach ($file as $i => $line) {
|
||||||
|
|
|
@ -150,14 +150,27 @@ class HtmlCoverageReport {
|
||||||
|
|
||||||
$phpTagPattern = '/^[ |\t]*[<\?php|\?>]+[ |\t]*/';
|
$phpTagPattern = '/^[ |\t]*[<\?php|\?>]+[ |\t]*/';
|
||||||
$basicallyEmptyPattern = '/^[ |\t]*[{|}|\(|\)]+[ |\t]*/';
|
$basicallyEmptyPattern = '/^[ |\t]*[{|}|\(|\)]+[ |\t]*/';
|
||||||
|
$commentStart = '/\/\*\*/';
|
||||||
|
$commentEnd = '/\*\//';
|
||||||
$ignoreStart = '/@codeCoverageIgnoreStart/';
|
$ignoreStart = '/@codeCoverageIgnoreStart/';
|
||||||
$ignoreStop = '/@codeCoverageIgnoreEnd/';
|
$ignoreStop = '/@codeCoverageIgnoreEnd/';
|
||||||
|
$inComment = false;
|
||||||
|
|
||||||
foreach ($lines as $lineno => $line) {
|
foreach ($lines as $lineno => $line) {
|
||||||
$runnable = true;
|
$runnable = true;
|
||||||
if (preg_match($phpTagPattern, $line) || preg_match($basicallyEmptyPattern, $line)) {
|
if (preg_match($phpTagPattern, $line) || preg_match($basicallyEmptyPattern, $line)) {
|
||||||
$runnable = false;
|
$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;
|
$output[$lineno] = $runnable;
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
|
@ -183,22 +196,22 @@ class HtmlCoverageReport {
|
||||||
$executableLines = $this->getExecutableLines($fileLines);
|
$executableLines = $this->getExecutableLines($fileLines);
|
||||||
|
|
||||||
foreach ($fileLines as $lineno => $line) {
|
foreach ($fileLines as $lineno => $line) {
|
||||||
$isExecutable = (isset($executableLines[$lineno]) && $executableLines[$lineno] == true);
|
$manualFind = (
|
||||||
|
isset($executableLines[$lineno]) &&
|
||||||
|
$executableLines[$lineno] == true &&
|
||||||
|
trim($line) != ''
|
||||||
|
);
|
||||||
|
|
||||||
$class = 'uncovered';
|
$class = 'ignored';
|
||||||
if (!$isExecutable) {
|
if ($manualFind) {
|
||||||
$class = 'ignored';
|
$class = 'uncovered';
|
||||||
} elseif (isset($coverageData[$lineno]) && $coverageData[$lineno] > 0) {
|
$total++;
|
||||||
$class = 'covered';
|
if (isset($coverageData[$lineno]) && $coverageData[$lineno] > 0) {
|
||||||
|
$class = 'covered';
|
||||||
|
$covered++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$diff[] = $this->_paintLine($line, $lineno, $class);
|
$diff[] = $this->_paintLine($line, $lineno, $class);
|
||||||
|
|
||||||
if ($class == 'covered') {
|
|
||||||
$covered++;
|
|
||||||
}
|
|
||||||
if ($class == 'uncovered' || $class == 'covered') {
|
|
||||||
$total++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$percentCovered = round($covered / $total, 2);
|
$percentCovered = round($covered / $total, 2);
|
||||||
|
|
Loading…
Add table
Reference in a new issue