From 4a152d3d55b9cdf63eacb638024c8cc711d2af15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Tue, 4 May 2010 16:31:03 -0430 Subject: [PATCH] Adding number of assertion runned in html reporter enabling "show passes" (that in contrast of simpletest only reports the passed test method instead of the assertion) cleaning up a bit --- .../tests/lib/reporter/cake_base_reporter.php | 4 ++ .../tests/lib/reporter/cake_html_reporter.php | 57 +++++++++---------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/cake/tests/lib/reporter/cake_base_reporter.php b/cake/tests/lib/reporter/cake_base_reporter.php index c6d36a987..c0b5653f9 100644 --- a/cake/tests/lib/reporter/cake_base_reporter.php +++ b/cake/tests/lib/reporter/cake_base_reporter.php @@ -65,6 +65,10 @@ class CakeBaseReporter { */ protected $_characterSet; +/** +* The number of assertions done for a test suite +*/ + protected $numAssertions = 0; /** * Does nothing yet. The first output will * be sent on the first test start. diff --git a/cake/tests/lib/reporter/cake_html_reporter.php b/cake/tests/lib/reporter/cake_html_reporter.php index 69b28eb6d..e59269562 100755 --- a/cake/tests/lib/reporter/cake_html_reporter.php +++ b/cake/tests/lib/reporter/cake_html_reporter.php @@ -26,16 +26,15 @@ include_once dirname(__FILE__) . DS . 'cake_base_reporter.php'; * @package cake * @subpackage cake.tests.lib */ -class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_TestListener{ +class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_TestListener { /** * Paints the top of the web page setting the * title to the name of the starting test. * - * @param string $test_name Name class of test. * @return void */ - public function paintHeader($testName) { + public function paintHeader() { $this->sendNoCacheHeaders(); $this->paintDocumentStart(); $this->paintTestMenu(); @@ -161,9 +160,10 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;"; echo "\">"; echo $result->count() . "/" . $result->count() - $result->skippedCount(); - echo " test cases complete:\n"; + echo " test methods complete:\n"; echo "" . count($result->passed()) . " passes, "; - echo "" . $result->failureCount() . " fails and "; + echo "" . $result->failureCount() . " fails, "; + echo "" . $this->numAssertions . " assertions and "; echo "" . $result->errorCount() . " exceptions."; echo "\n"; echo '
'; @@ -174,8 +174,8 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes echo $this->_paintLinks(); echo '
'; if ( - isset($this->params['codeCoverage']) && - $this->params['codeCoverage'] && + isset($this->params['codeCoverage']) && + $this->params['codeCoverage'] && class_exists('CodeCoverageManager') ) { CodeCoverageManager::report(); @@ -257,7 +257,7 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes echo "
  • \n"; echo "Failed"; - echo "
    " . $this->_htmlEntities($message->getDescription()) . "
    \n"; + echo "
    " . $this->_htmlEntities($message->getDescription()) . "
    \n"; echo "
    " . sprintf(__('File: %s'), $context['file']) . "
    \n"; echo "
    " . sprintf(__('Method: %s'), $realContext['function']) . "
    \n"; echo "
    " . sprintf(__('Line: %s'), $context['line']) . "
    \n"; @@ -272,19 +272,18 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes * trail of the nesting test suites below the * top level test. * - * @param string $message Pass message displayed in the context of the other tests. + * @param PHPUnit_Framework_Test test method that just passed + * @param float $time time spent to run the test method * @return void */ - public function paintPass($message) { - parent::paintPass($message); - + public function paintPass(PHPUnit_Framework_Test $test, $time = null) { if (isset($this->params['show_passes']) && $this->params['show_passes']) { echo "
  • \n"; echo "Passed "; - $breadcrumb = $this->getTestList(); - array_shift($breadcrumb); - echo implode(" -> ", $breadcrumb); - echo "
    " . $this->_htmlEntities($message) . "\n"; + //$breadcrumb = $this->getTestList(); + //array_shift($breadcrumb); + //echo implode(" -> ", $breadcrumb); + echo "
    " . $this->_htmlEntities($test->getName()) . " ($time seconds)\n"; echo "
  • \n"; } } @@ -312,7 +311,6 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes * @return void */ public function paintException($exception) { - parent::paintException($exception); echo "
  • \n"; echo "Exception"; $message = 'Unexpected exception of type [' . get_class($exception) . @@ -333,7 +331,6 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes * @return void */ public function paintSkip($message) { - parent::paintSkip($message); echo "
  • \n"; echo "Skipped "; echo $this->_htmlEntities($message); @@ -369,7 +366,7 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes if ($result->failureCount() > 0) { $this->printFailures($result); } - + if ($result->skippedCount() > 0) { $this->printIncompletes($result); } @@ -389,15 +386,15 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes * @param float $time */ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { - + } /** * A failure occurred. * -* @param PHPUnit_Framework_Test $test +* @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e -* @param float $time +* @param float $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->paintFail($e); @@ -407,8 +404,8 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes * Incomplete test. * * @param PHPUnit_Framework_Test $test -* @param Exception $e -* @param float $time +* @param Exception $e +* @param float $time */ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) { @@ -418,19 +415,16 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes * Skipped test. * * @param PHPUnit_Framework_Test $test -* @param Exception $e -* @param float $time -* @since Method available since Release 3.0.0 +* @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 - * @since Method available since Release 2.2.0 */ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { echo '

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

    '; @@ -440,7 +434,6 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes * A test suite ended. * * @param PHPUnit_Framework_TestSuite $suite - * @since Method available since Release 2.2.0 */ public function endTestSuite(PHPUnit_Framework_TestSuite $suite) { } @@ -457,9 +450,11 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes * A test ended. * * @param PHPUnit_Framework_Test $test - * @param float $time + * @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