Skip to content

Commit

Permalink
Merge pull request #5478 from tranfuga25s/HtmlCodeCoverageFix
Browse files Browse the repository at this point in the history
Html Testing Renderer & Code Coverage Improvement
  • Loading branch information
lorenzo committed Dec 26, 2014
2 parents 11206d5 + fe3d2b9 commit 8a4b0e8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/TestSuite/HtmlCoverageReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testGenerateDiff() {
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php"/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php-' . md5('myfile.php') . '"/', $result);
$this->assertRegExp('/<pre>/', $result);
foreach ($file as $i => $line) {
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
Expand Down Expand Up @@ -167,7 +167,7 @@ public function testPhpunit36Compatibility() {

$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php"/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php-' . md5('myfile.php') . '"/', $result);
$this->assertRegExp('/<pre>/', $result);
foreach ($file as $i => $line) {
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,19 @@ function coverage_toggle_all() {
* @return string
*/
public function coverageHeader($filename, $percent) {
$hash = md5($filename);
$filename = basename($filename);
list($file) = 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');">
<a href="#coverage-$filename-$hash" onclick="coverage_show_hide('coverage-$filename-$hash');">
$filename Code coverage: $percent%
</a>
</h4>
<div class="code-coverage-results" id="coverage-$filename" style="display:none;">
<div class="code-coverage-results" id="coverage-$filename-$hash" style="display:none;">
<pre>
HTML;
}
Expand Down
41 changes: 37 additions & 4 deletions lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ protected function _paintLinks() {
if (!empty($this->params['case'])) {
$query['case'] = $this->params['case'];
}
$show = $this->_queryString($show);
$query = $this->_queryString($query);
list($show, $query) = $this->_getQueryLink();

echo "<p><a href='" . $this->baseUrl() . $show . "'>Run more tests</a> | <a href='" . $this->baseUrl() . $query . "&amp;show_passes=1'>Show Passes</a> | \n";
echo "<a href='" . $this->baseUrl() . $query . "&amp;debug=1'>Enable Debug Output</a> | \n";
echo "<a href='" . $this->baseUrl() . $query . "&amp;code_coverage=true'>Analyze Code Coverage</a></p>\n";
echo "<a href='" . $this->baseUrl() . $query . "&amp;code_coverage=true'>Analyze Code Coverage</a> | \n";
echo "<a href='" . $this->baseUrl() . $query . "&amp;code_coverage=true&amp;show_passes=1&amp;debug=1'>All options enabled</a></p>\n";
}

/**
Expand Down Expand Up @@ -248,7 +248,8 @@ public function paintDocumentEnd() {
*/
public function paintFail($message, $test) {
$trace = $this->_getStackTrace($message);
$testName = get_class($test) . '(' . $test->getName() . ')';
$className = get_class($test);
$testName = $className . '::' . $test->getName() . '()';

$actualMsg = $expectedMsg = null;
if (method_exists($message, 'getComparisonFailure')) {
Expand All @@ -269,6 +270,10 @@ public function paintFail($message, $test) {

echo "</pre></div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Test case: %s', $testName) . "</div>\n";
if (strpos($className, "PHPUnit_") === false) {
list($show, $query) = $this->_getQueryLink();
echo "<div class='msg'><a href='" . $this->baseUrl() . $query . "&amp;filter=" . $test->getName() . "'>" . __d('cake_dev', 'Rerun only this test: %s', $testName) . "</a></div>\n";
}
echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
echo "</li>\n";
}
Expand Down Expand Up @@ -380,4 +385,32 @@ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
echo '<h2>' . __d('cake_dev', 'Running %s', $suite->getName()) . '</h2>';
}

/**
* Returns the query string formatted for ouput in links
*
* @return string
*/
protected function _getQueryLink() {
$show = $query = array();
if (!empty($this->params['case'])) {
$show['show'] = 'cases';
}

if (!empty($this->params['core'])) {
$show['core'] = $query['core'] = 'true';
}
if (!empty($this->params['plugin'])) {
$show['plugin'] = $query['plugin'] = $this->params['plugin'];
}
if (!empty($this->params['case'])) {
$query['case'] = $this->params['case'];
}
if (!empty($this->params['filter'])) {
$query['filter'] = $this->params['filter'];
}
$show = $this->_queryString($show);
$query = $this->_queryString($query);
return array($show, $query);
}

}

0 comments on commit 8a4b0e8

Please sign in to comment.