mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding a toggle all button to the coverage report. Makes it easier to see the test subject at a glance.
Adding ability to only show files that match the extension-less basename of the test case file. This hides much of the noise the new reports have.
This commit is contained in:
parent
e8e2235cfa
commit
687eab9528
2 changed files with 53 additions and 4 deletions
|
@ -25,16 +25,34 @@ class HtmlCoverageReport {
|
|||
*/
|
||||
protected $_rawCoverage;
|
||||
|
||||
/**
|
||||
* is the test an app test
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $appTest = false;
|
||||
|
||||
/**
|
||||
* is the test a plugin test
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $pluginTest = false;
|
||||
|
||||
/**
|
||||
* is the test a group test?
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $groupTest = false;
|
||||
|
||||
/**
|
||||
* Number of lines to provide around an uncovered code block
|
||||
* Array of test case file names. Used to do basename() matching with
|
||||
* files that have coverage to decide which results to show on page load.
|
||||
*
|
||||
* @var integer
|
||||
* @var array
|
||||
*/
|
||||
public $numDiffContextLines = 7;
|
||||
protected $_testNames = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -85,6 +103,11 @@ class HtmlCoverageReport {
|
|||
return '<h3>No files to generate coverage for</h3>';
|
||||
}
|
||||
$output = $this->coverageScript();
|
||||
$output .= <<<HTML
|
||||
<h3>Code coverage results
|
||||
<a href="#" onclick="coverage_toggle_all()" class="coverage-toggle">Toggle all files</a>
|
||||
</h3>
|
||||
HTML;
|
||||
foreach ($coverageData as $file => $coverageData) {
|
||||
$fileData = file($file);
|
||||
$output .= $this->generateDiff($file, $fileData, $coverageData);
|
||||
|
@ -138,6 +161,11 @@ class HtmlCoverageReport {
|
|||
$files[$filename]['executable'] += $executable;
|
||||
$files[$filename]['dead'] += $dead;
|
||||
}
|
||||
if (isset($testRun['test'])) {
|
||||
$testReflection = new ReflectionClass(get_class($testRun['test']));
|
||||
list($fileBasename, $x) = explode('.', basename($testReflection->getFileName()), 2);
|
||||
$this->_testNames[] = $fileBasename;
|
||||
}
|
||||
}
|
||||
ksort($files);
|
||||
return $files;
|
||||
|
@ -209,6 +237,15 @@ class HtmlCoverageReport {
|
|||
var element = document.getElementById(selector);
|
||||
element.style.display = (element.style.display == 'none') ? '' : 'none';
|
||||
}
|
||||
function coverage_toggle_all () {
|
||||
var divs = document.querySelectorAll('div.coverage-container');
|
||||
var i = divs.length;
|
||||
while (i--) {
|
||||
if (divs[i] && divs[i].className.indexOf('primary') == -1) {
|
||||
divs[i].style.display = (divs[i].style.display == 'none') ? '' : 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
HTML;
|
||||
}
|
||||
|
@ -220,7 +257,11 @@ HTML;
|
|||
*/
|
||||
public function coverageHeader($filename, $percent) {
|
||||
$filename = basename($filename);
|
||||
list($file, $ext) = explode('.', $filename);
|
||||
$display = in_array($file, $this->_testNames) ? 'block' : 'none';
|
||||
$primary = $display == 'block' ? 'primary' : '';
|
||||
return <<<HTML
|
||||
<div class="coverage-container $primary" style="display:$display;">
|
||||
<h4>
|
||||
<a href="#coverage-$filename" onclick="coverage_show_hide('coverage-$filename');">
|
||||
$filename Code coverage: $percent%
|
||||
|
@ -237,6 +278,6 @@ HTML;
|
|||
* @return void
|
||||
*/
|
||||
public function coverageFooter() {
|
||||
return "</pre></div>";
|
||||
return "</pre></div></div>";
|
||||
}
|
||||
}
|
|
@ -79,6 +79,14 @@
|
|||
display:block;
|
||||
margin-left:10px;
|
||||
}
|
||||
.coverage-toggle {
|
||||
float:right;
|
||||
margin-top:10px;
|
||||
font-size:12px;
|
||||
}
|
||||
.coverage-container {
|
||||
margin-top:1em;
|
||||
}
|
||||
div.code-coverage-results div.uncovered span.content { background:#ecc; }
|
||||
div.code-coverage-results div.covered span.content { background:#cec; }
|
||||
div.code-coverage-results div.ignored span.content { color:#aaa; }
|
||||
|
|
Loading…
Add table
Reference in a new issue