Merge commit 'mark/2.0-coverage' into 2.0-phpunit

Conflicts:
	cake/tests/lib/reporter/cake_html_reporter.php
This commit is contained in:
José Lorenzo Rodríguez 2010-05-13 00:05:30 -04:30
commit 3e3817f113
8 changed files with 735 additions and 153 deletions

View file

@ -0,0 +1,268 @@
<?php
/**
* Test case for HtmlCoverageReport
*
* PHP5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake
* @subpackage cake.cake
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
require_once CAKE . 'tests' . DS . 'lib' . DS . 'coverage' . DS . 'html_coverage_report.php';
class HtmlCoverageReportTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
public function setUp() {
$reporter = new CakeBaseReporter();
$reporter->params = array('app' => false, 'plugin' => false, 'group' => false);
$coverage = array();
$this->Coverage = new HtmlCoverageReport($coverage, $reporter);
}
/**
* test getting the path filters.
*
* @return void
*/
function testGetPathFilter() {
$this->Coverage->appTest = false;
$result = $this->Coverage->getPathFilter();
$this->assertEquals(TEST_CAKE_CORE_INCLUDE_PATH, $result);
$this->Coverage->appTest = true;
$result = $this->Coverage->getPathFilter();
$this->assertEquals(ROOT . DS . APP_DIR . DS, $result);
$this->Coverage->appTest = false;
$this->Coverage->pluginTest = 'test_plugin';
$result = $this->Coverage->getPathFilter();
$this->assertEquals(ROOT . DS . APP_DIR . DS . 'plugins' . DS .'test_plugin' . DS, $result);
}
/**
* test filtering coverage data.
*
* @return void
*/
function testFilterCoverageDataByPathRemovingElements() {
$data = array(
array(
'files' => array(
TEST_CAKE_CORE_INCLUDE_PATH . 'dispatcher.php' => array(
10 => -1,
12 => 1
),
APP . 'app_model.php' => array(
50 => 1,
52 => -1
)
)
)
);
$this->Coverage->setCoverage($data);
$result = $this->Coverage->filterCoverageDataByPath(TEST_CAKE_CORE_INCLUDE_PATH);
$this->assertTrue(isset($result[TEST_CAKE_CORE_INCLUDE_PATH . 'dispatcher.php']));
$this->assertFalse(isset($result[APP . 'app_model.php']));
}
/**
* test that filterCoverageDataByPath correctly merges data sets in each test run.
*
* @return void
*/
function testFilterCoverageDataCorrectlyMergingValues() {
$data = array(
array(
'files' => array(
'/something/dispatcher.php' => array(
10 => 1,
12 => 1
),
),
'executable' => array(
'/something/dispatcher.php' => array(
9 => -1
)
),
'dead' => array(
'/something/dispatcher.php' => array(
22 => -2,
23 => -2
)
)
),
array(
'files' => array(
'/something/dispatcher.php' => array(
10 => 1,
50 => 1,
),
),
'executable' => array(
'/something/dispatcher.php' => array(
12 => -1,
51 => -1
)
),
'dead' => array(
'/something/dispatcher.php' => array(
13 => -2,
42 => -2
)
)
),
);
$this->Coverage->setCoverage($data);
$result = $this->Coverage->filterCoverageDataByPath('/something/');
$path = '/something/dispatcher.php';
$this->assertTrue(isset($result[$path]));
$this->assertEquals(array(10, 12, 50), array_keys($result[$path]['covered']));
$this->assertEquals(array(9, 12, 51), array_keys($result[$path]['executable']));
$this->assertEquals(array(22, 23, 13, 42), array_keys($result[$path]['dead']));
}
/**
* test generating HTML reports from file arrays.
*
* @return void
*/
function testGenerateDiff() {
$file = array(
'line 1',
'line 2',
'line 3',
'line 4',
'line 5',
'line 6',
'line 7',
'line 8',
'line 9',
'line 10',
);
$coverage = array(
'covered' => array(
1 => 1,
3 => 1,
4 => 1,
6 => 1,
7 => 1,
8 => 1,
10 => 1
),
'executable' => array(
5 => -1,
9 => -1
),
'dead' => array(
2 => -2
)
);
$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('/<pre>/', $result);
foreach ($file as $i => $line) {
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
$class = 'covered';
if (in_array($i + 1, array(5, 9, 2))) {
$class = 'uncovered';
}
if ($i + 1 == 2) {
$class .= ' dead';
}
$this->assertTrue(strpos($class, $result) !== 0, 'Class name is wrong ' . $i);
}
}
/**
* test that covering methods show up as title attributes for lines.
*
* @return void
*/
function testCoveredLinesTitleAttributes() {
$file = array(
'line 1',
'line 2',
'line 3',
'line 4',
'line 5',
);
$mock = $this->getMock('PHPUnit_Framework_TestCase');
$mock->expects($this->any())->method('getName')->will($this->returnValue('testAwesomeness'));
$rawdata = array(
array(
'test' => $mock,
'files' => array(
'myfile.php' => array(
1 => 1,
3 => 1,
4 => 1,
)
),
'executable' => array(
'myfile.php' => array(
5 => -1
)
)
)
);
$coverage = array(
'covered' => array(
1 => 1,
3 => 1,
4 => 1,
),
'executable' => array(
5 => -1,
),
'dead' => array(
2 => -2
)
);
$this->Coverage->setCoverage($rawdata);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertTrue(
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">1") !== false,
'Missing method coverage for line 1'
);
$this->assertTrue(
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">3") !== false,
'Missing method coverage for line 3'
);
$this->assertTrue(
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">4") !== false,
'Missing method coverage for line 4'
);
$this->assertTrue(
strpos($result, "title=\"\"><span class=\"line-num\">5") !== false,
'Coverage report is wrong for line 5'
);
}
/**
* teardown
*
* @return void
*/
function tearDown() {
unset($this->Coverage);
}
}

View file

@ -236,7 +236,6 @@ class CakeTestSuiteDispatcher {
if (isset($_GET['code_coverage'])) {
$this->params['codeCoverage'] = true;
$this->_checkXdebug();
require_once CAKE_TESTS_LIB . 'code_coverage_manager.php';
}
$this->params['baseUrl'] = $this->_baseUrl;
$this->params['baseDir'] = $this->_baseDir;
@ -250,9 +249,6 @@ class CakeTestSuiteDispatcher {
*/
function _runGroupTest() {
$Reporter = CakeTestSuiteDispatcher::getReporter();
if ($this->params['codeCoverage']) {
CodeCoverageManager::init($this->params['group'], $Reporter);
}
if ('all' == $this->params['group']) {
$this->Manager->runAllTests($Reporter);
} else {
@ -267,9 +263,6 @@ class CakeTestSuiteDispatcher {
*/
function _runTestCase() {
$Reporter = CakeTestSuiteDispatcher::getReporter();
if ($this->params['codeCoverage']) {
CodeCoverageManager::init($this->params['case'], $Reporter);
}
$this->Manager->runTestCase($this->params['case'], $Reporter, $this->params['codeCoverage']);
}
}

View file

@ -0,0 +1,296 @@
<?php
/**
* Generates code coverage reports in HTML from data obtained from PHPUnit
*
* PHP5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake
* @subpackage cake.cake
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class HtmlCoverageReport {
/**
* coverage data
*
* @var string
*/
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;
/**
* 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 array
*/
protected $_testNames = array();
/**
* Constructor
*
* @param array $coverage Array of coverage data from PHPUnit_Test_Result
* @return void
*/
public function __construct($coverage, CakeBaseReporter $reporter) {
$this->_rawCoverage = $coverage;
$this->setParams($reporter);
}
/**
* Pulls params out of the reporter.
*
* @return void
*/
protected function setParams(CakeBaseReporter $reporter) {
if ($reporter->params['app']) {
$this->appTest = true;
}
if ($reporter->params['group']) {
$this->groupTest = true;
}
if ($reporter->params['plugin']) {
$this->pluginTest = Inflector::underscore($reporter->params['plugin']);
}
}
/**
* Set the coverage data array
*
* @return void
*/
public function setCoverage($coverage) {
$this->_rawCoverage = $coverage;
}
/**
* Generates report html to display.
*
* @return string compiled html report.
*/
public function report() {
$pathFilter = $this->getPathFilter();
$coverageData = $this->filterCoverageDataByPath($pathFilter);
if (empty($coverageData)) {
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);
}
return $output;
}
/**
* Gets the base path that the files we are interested in live in.
* If appTest ist
*
* @return void
*/
public function getPathFilter() {
$path = ROOT . DS;
if ($this->appTest) {
$path .= APP_DIR . DS;
} elseif ($this->pluginTest) {
$path = App::pluginPath($this->pluginTest);
} else {
$path = TEST_CAKE_CORE_INCLUDE_PATH;
}
return $path;
}
/**
* Filters the coverage data by path. Files not in the provided path will be removed.
* This method will merge all the various test run reports as well into a single report per file.
*
* @param string $path Path to filter files by.
* @return array Array of coverage data for files that match the given path.
*/
public function filterCoverageDataByPath($path) {
$files = array();
foreach ($this->_rawCoverage as $testRun) {
foreach ($testRun['files'] as $filename => $fileCoverage) {
if (strpos($filename, $path) !== 0) {
continue;
}
$dead = isset($testRun['dead'][$filename]) ? $testRun['dead'][$filename] : array();
$executable = isset($testRun['executable'][$filename]) ? $testRun['executable'][$filename] : array();
if (!isset($files[$filename])) {
$files[$filename] = array(
'covered' => array(),
'dead' => array(),
'executable' => array()
);
}
$files[$filename]['covered'] += $fileCoverage;
$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;
}
/**
* Generates an HTML diff for $file based on $coverageData.
*
* @param array $fileData File data as an array. See file() for how to get one of these.
* @param array $coverageData Array of coverage data to use to generate HTML diffs with
* @return string HTML diff.
*/
public function generateDiff($filename, $fileLines, $coverageData) {
$output = '';
$diff = array();
$covered = 0;
$total = 0;
//shift line numbers forward one;
array_unshift($fileLines, ' ');
unset($fileLines[0]);
foreach ($fileLines as $lineno => $line) {
$class = 'ignored';
$coveringTests = array();
if (isset($coverageData['covered'][$lineno])) {
$coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests(
$this->_rawCoverage, $filename, $lineno
);
$class = 'covered';
$covered++;
$total++;
} elseif (isset($coverageData['executable'][$lineno])) {
$class = 'uncovered';
$total++;
} elseif (isset($coverageData['dead'][$lineno])) {
$class .= ' dead';
}
$diff[] = $this->_paintLine($line, $lineno, $class, $coveringTests);
}
$percentCovered = round(100 * $covered / $total, 2);
$output .= $this->coverageHeader($filename, $percentCovered);
$output .= implode("", $diff);
$output .= $this->coverageFooter();
return $output;
}
/**
* Renders the html for a single line in the html diff.
*
* @return void
*/
protected function _paintLine($line, $linenumber, $class, $coveringTests) {
$coveredBy = '';
if (!empty($coveringTests)) {
$coveredBy = "Covered by:\n";
foreach ($coveringTests as &$test) {
$coveredBy .= $test->getName() . "\n";
}
}
return sprintf(
'<div class="code-line %s" title="%s"><span class="line-num">%s</span><span class="content">%s</span></div>',
$class,
$coveredBy,
$linenumber,
htmlspecialchars($line)
);
}
/**
* generate some javascript for the coverage report.
*
* @return void
*/
public function coverageScript() {
return <<<HTML
<script type="text/javascript">
function coverage_show_hide(selector) {
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;
}
/**
* Generate an HTML snippet for coverage headers
*
* @return void
*/
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%
</a>
</h4>
<div class="code-coverage-results" id="coverage-$filename" style="display:none;">
<pre>
HTML;
}
/**
* Generate an HTML snippet for coverage footers
*
* @return void
*/
public function coverageFooter() {
return "</pre></div></div>";
}
}

View file

@ -26,7 +26,7 @@ PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
* @package cake
* @subpackage cake.tests.lib
*/
class CakeBaseReporter {
class CakeBaseReporter implements PHPUnit_Framework_TestListener {
/**
* Time the test runs started.
@ -214,4 +214,87 @@ class CakeBaseReporter {
return '';
}
public function paintResult(PHPUnit_Framework_TestResult $result) {
$this->paintFooter($result);
}
/**
* An error occurred.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
*/
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
$this->paintException($e);
}
/**
* A failure occurred.
*
* @param PHPUnit_Framework_Test $test
* @param PHPUnit_Framework_AssertionFailedError $e
* @param float $time
*/
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
$this->paintFail($e);
}
/**
* Incomplete test.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
*/
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
}
/**
* Skipped test.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
*/
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
}
/**
* A test suite started.
*
* @param PHPUnit_Framework_TestSuite $suite
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
echo sprintf(__('Running %s'), $suite->getName()) . "\n";
}
/**
* A test suite ended.
*
* @param PHPUnit_Framework_TestSuite $suite
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
}
/**
* A test started.
*
* @param PHPUnit_Framework_Test $test
*/
public function startTest(PHPUnit_Framework_Test $test) {
}
/**
* A test ended.
*
* @param PHPUnit_Framework_Test $test
* @param float $time
*/
public function endTest(PHPUnit_Framework_Test $test, $time) {
$this->numAssertions += $test->getNumAssertions();
$this->paintPass($test, $time);
}
}

View file

@ -28,8 +28,7 @@ PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
* @package cake
* @subpackage cake.tests.lib
*/
class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_TestListener {
class CakeHtmlReporter extends CakeBaseReporter {
/**
* Paints the top of the web page setting the
@ -153,7 +152,7 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
* Paints the end of the test with a summary of
* the passes and failures.
*
* @param string $test_name Name class of test.
* @param PHPUnit_Framework_TestResult $result Result object
* @return void
*/
public function paintFooter($result) {
@ -162,7 +161,7 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
echo "<div style=\"";
echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
echo "\">";
echo $result->count() . "/" . $result->count() - $result->skippedCount();
echo $result->count() . "/" . ($result->count() - $result->skippedCount());
echo " test methods complete:\n";
echo "<strong>" . count($result->passed()) . "</strong> passes, ";
echo "<strong>" . $result->failureCount() . "</strong> fails, ";
@ -176,16 +175,25 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
}
echo $this->_paintLinks();
echo '</div>';
if (
isset($this->params['codeCoverage']) &&
$this->params['codeCoverage'] &&
class_exists('CodeCoverageManager')
) {
//CodeCoverageManager::report();
if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
$coverage = $result->getCodeCoverageInformation();
echo $this->paintCoverage($coverage);
}
$this->paintDocumentEnd();
}
/**
* Paints a code coverage report.
*
* @return void
*/
public function paintCoverage($coverage) {
$file = dirname(dirname(__FILE__)) . '/coverage/html_coverage_report.php';
include $file;
$reporter = new HtmlCoverageReport($coverage, $this);
echo $reporter->report();
}
/**
* Renders the links that for accessing things in the test suite.
*
@ -264,9 +272,6 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
echo "<div class='msg'>" . sprintf(__('File: %s'), $context['file']) . "</div>\n";
echo "<div class='msg'>" . sprintf(__('Method: %s'), $realContext['function']) . "</div>\n";
echo "<div class='msg'>" . sprintf(__('Line: %s'), $context['line']) . "</div>\n";
//$breadcrumb = $this->getTestList();
//array_shift($breadcrumb);
//echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
echo "</li>\n";
}
@ -360,103 +365,12 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
return htmlentities($message, ENT_COMPAT, $this->_characterSet);
}
public function paintResult(PHPUnit_Framework_TestResult $result) {
/*if ($result->errorCount() > 0) {
$this->printErrors($result);
}
if ($result->failureCount() > 0) {
$this->printFailures($result);
}
if ($result->skippedCount() > 0) {
$this->printIncompletes($result);
}
if ($result->skippedCount() > 0) {
$this->printSkipped($result);
}*/
$this->paintFooter($result);
}
/**
* An error occurred.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
*/
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
$this->paintException($e);
}
/**
* A failure occurred.
*
* @param PHPUnit_Framework_Test $test
* @param PHPUnit_Framework_AssertionFailedError $e
* @param float $time
*/
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
$this->paintFail($e);
}
/**
* Incomplete test.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
*/
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
}
/**
* Skipped test.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
*/
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
}
/**
* A test suite started.
*
* @param PHPUnit_Framework_TestSuite $suite
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
echo '<h2>' . sprintf(__('Running %s'), $suite->getName()) . '</h2>';
}
/**
* A test suite ended.
*
* @param PHPUnit_Framework_TestSuite $suite
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
}
/**
* A test started.
*
* @param PHPUnit_Framework_Test $test
*/
public function startTest(PHPUnit_Framework_Test $test) {
}
/**
* A test ended.
*
* @param PHPUnit_Framework_Test $test
* @param float $time
*/
public function endTest(PHPUnit_Framework_Test $test, $time) {
$this->numAssertions += $test->getNumAssertions();
$this->paintPass($test, $time);
echo '<h2>' . sprintf(__('Running %s'), $suite->getName()) . '</h2>';
}
}

View file

@ -17,8 +17,11 @@
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
include_once dirname(__FILE__) . DS . 'cake_base_reporter.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
/**
* CakeTextReporter contains reporting features used for plain text based output
*
@ -33,40 +36,63 @@ class CakeTextReporter extends CakeBaseReporter {
* @return void
*/
public function paintDocumentStart() {
if (!SimpleReporter::inCli()) {
header('Content-type: text/plain');
}
header('Content-type: text/plain');
}
/**
* undocumented function
*
* @return void
*/
public function paintPass() {
}
/**
* Paints a failing test.
*
* @param $message PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
* the context of the other tests.
* @return void
*/
public function paintFail($message) {
$context = $message->getTrace();
$realContext = $context[3];
$context = $context[2];
printf(
"FAIL on line %s\n%s in\n%s %s()\n\n",
$context['line'], $message->toString(), $context['file'], $realContext['function']
);
}
/**
* Paints the end of the test with a summary of
* the passes and failures.
*
* @param string $test_name Name class of test.
* @param PHPUnit_Framework_TestResult $result Result object
* @return void
*/
public function paintFooter($test_name) {
if ($this->getFailCount() + $this->getExceptionCount() == 0) {
public function paintFooter($result) {
if ($result->failureCount() + $result->errorCount() == 0) {
echo "OK\n";
} else {
echo "FAILURES!!!\n";
}
echo "Test cases run: " . $this->getTestCaseProgress() .
"/" . $this->getTestCaseCount() .
", Passes: " . $this->getPassCount() .
", Failures: " . $this->getFailCount() .
", Exceptions: " . $this->getExceptionCount() . "\n";
echo 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
echo "Test cases run: " . $result->count() .
"/" . ($result->count() - $result->skippedCount()) .
', Passes: ' . $this->numAssertions .
', Failures: ' . $result->failureCount() .
', Exceptions: ' . $result->errorCount() . "\n";
echo 'Time taken by tests (in seconds): ' . $result->time() . "\n";
if (function_exists('memory_get_peak_usage')) {
echo 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
}
if (
isset($this->params['codeCoverage']) &&
$this->params['codeCoverage'] &&
class_exists('CodeCoverageManager')
) {
CodeCoverageManager::report();
if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
$coverage = $result->getCodeCoverageInformation();
echo $this->paintCoverage($coverage);
}
}
@ -76,28 +102,11 @@ class CakeTextReporter extends CakeBaseReporter {
* @param string $test_name Name class of test.
* @return void
*/
public function paintHeader($test_name) {
public function paintHeader() {
$this->paintDocumentStart();
echo "$test_name\n";
flush();
}
/**
* Paints the test failure as a stack trace.
*
* @param string $message Failure message displayed in
* the context of the other tests.
* @return void
*/
public function paintFail($message) {
parent::paintFail($message);
echo $this->getFailCount() . ") $message\n";
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
echo "\n";
}
/**
* Paints a PHP error.
*
@ -188,4 +197,15 @@ class CakeTextReporter extends CakeBaseReporter {
$buffer .= "\n";
echo $buffer;
}
/**
* Generates a Text summary of the coverage data.
*
* @param array $coverage Array of coverage data.
* @return string
*/
public function paintCoverage($coverage) {
return '';
}
}

View file

@ -79,9 +79,20 @@
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; }
div.code-coverage-results div:hover { background:#e8e8e8;}
div.code-coverage-results div.covered:hover span.content { background:#b4edb4;}
div.code-coverage-results div.uncovered:hover span.content { background:#edb4b4;}
div.code-coverage-results span.line-num {
color:#666;
display:block;

View file

@ -127,7 +127,7 @@ class TestManager {
$testCaseFileWithPath = $this->_getTestsPath() . DS . $testCaseFile;
if (!file_exists($testCaseFileWithPath) || strpos($testCaseFileWithPath, '..')) {
throw new InvalidArgumentException(sprintf(__('Unable to load test file %s'), htmlentities($testCaseFile));
throw new InvalidArgumentException(sprintf(__('Unable to load test file %s'), htmlentities($testCaseFile)));
}
$testSuite = $this->getTestSuite(sprintf(__('Individual test case: %s', true), $testCaseFile));
@ -182,9 +182,6 @@ class TestManager {
$testSuite->setFixtureManager($this->getFixtureManager());
$testSuite->run($result);
$reporter->paintResult($result);
// echo '<pre>';
// var_dump($result->getCodeCoverageInformation());
// echo '</pre>';
return $result;
}