From 17f338a9b22ccbc9b7d58fafd2b3dea2e794d900 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Thu, 13 May 2010 00:18:22 -0400 Subject: [PATCH] Moving methods up into CakeBaseReporter. Starting to make CakeTextReporter work well with PHPUnit so the Text code coverage reporting can be implemented. --- .../tests/lib/reporter/cake_base_reporter.php | 85 ++++++++++++++- .../tests/lib/reporter/cake_html_reporter.php | 102 +----------------- .../tests/lib/reporter/cake_text_reporter.php | 83 ++++++++------ 3 files changed, 141 insertions(+), 129 deletions(-) diff --git a/cake/tests/lib/reporter/cake_base_reporter.php b/cake/tests/lib/reporter/cake_base_reporter.php index d1455462c0e..643c1ed73a5 100644 --- a/cake/tests/lib/reporter/cake_base_reporter.php +++ b/cake/tests/lib/reporter/cake_base_reporter.php @@ -26,7 +26,7 @@ * @package cake * @subpackage cake.tests.lib */ -class CakeBaseReporter { +class CakeBaseReporter implements PHPUnit_Framework_TestListener { /** * Time the test runs started. @@ -214,5 +214,88 @@ public function baseUrl() { 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); + } + } ?> \ No newline at end of file diff --git a/cake/tests/lib/reporter/cake_html_reporter.php b/cake/tests/lib/reporter/cake_html_reporter.php index 3c4d335482b..3206f31530b 100755 --- a/cake/tests/lib/reporter/cake_html_reporter.php +++ b/cake/tests/lib/reporter/cake_html_reporter.php @@ -28,7 +28,7 @@ * @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 @@ -152,7 +152,7 @@ public function sendNoCacheHeaders() { * 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) { @@ -161,7 +161,7 @@ public function paintFooter($result) { echo "
"; - echo $result->count() . "/" . $result->count() - $result->skippedCount(); + echo $result->count() . "/" . ($result->count() - $result->skippedCount()); echo " test methods complete:\n"; echo "" . count($result->passed()) . " passes, "; echo "" . $result->failureCount() . " fails, "; @@ -272,9 +272,6 @@ public function paintFail($message) { echo "
" . sprintf(__('File: %s'), $context['file']) . "
\n"; echo "
" . sprintf(__('Method: %s'), $realContext['function']) . "
\n"; echo "
" . sprintf(__('Line: %s'), $context['line']) . "
\n"; - //$breadcrumb = $this->getTestList(); - //array_shift($breadcrumb); - //echo "
" . implode(" -> ", $breadcrumb) . "
\n"; echo "\n"; } @@ -368,104 +365,13 @@ protected function _htmlEntities($message) { 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 '

' . sprintf(__('Running %s'), $suite->getName()) . '

'; - } - -/** - * 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 '

' . sprintf(__('Running %s'), $suite->getName()) . '

'; } } ?> \ No newline at end of file diff --git a/cake/tests/lib/reporter/cake_text_reporter.php b/cake/tests/lib/reporter/cake_text_reporter.php index 31cec5c3e3f..8f32b3c435e 100644 --- a/cake/tests/lib/reporter/cake_text_reporter.php +++ b/cake/tests/lib/reporter/cake_text_reporter.php @@ -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,31 +36,57 @@ 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"; } @@ -73,28 +102,11 @@ public function paintFooter($test_name) { * @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. * @@ -185,5 +197,16 @@ public function testCaseList() { $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 ''; + } + } ?> \ No newline at end of file