cvs: pear(ZEND_ENGINE_2) /PHPUnit/TextUI ResultPrinter.php TestRunner.php

From: Date: Sun, 08 Jun 2003 06:43:20 +0000
Subject: cvs: pear(ZEND_ENGINE_2) /PHPUnit/TextUI ResultPrinter.php TestRunner.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-10760@lists.php.net to get a copy of this message
sebastian Sun Jun 8 02:43:20 2003 EDT Added files: (Branch: ZEND_ENGINE_2) /pear/PHPUnit/TextUI ResultPrinter.php Modified files: /pear/PHPUnit/TextUI TestRunner.php Log: More work on the TextUI TestRunner.

Index: pear/PHPUnit/TextUI/TestRunner.php diff -u pear/PHPUnit/TextUI/TestRunner.php:1.1.2.3 pear/PHPUnit/TextUI/TestRunner.php:1.1.2.4 --- pear/PHPUnit/TextUI/TestRunner.php:1.1.2.3 Sat Jun 7 13:37:07 2003 +++ pear/PHPUnit/TextUI/TestRunner.php Sun Jun 8 02:43:20 2003 @@ -12,16 +12,16 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: TestRunner.php,v 1.1.2.3 2003/06/07 17:37:07 sebastian Exp $ +// $Id: TestRunner.php,v 1.1.2.4 2003/06/08 06:43:20 sebastian Exp $ // require_once 'Benchmark/Timer.php'; require_once 'Console/Getopt.php'; require_once 'PHPUnit/Framework/Test.php'; require_once 'PHPUnit/Framework/TestResult.php'; -require_once 'PHPUnit/Runner/BaseTestRunner.php'; -require_once 'PHPUnit/Runner/TestRunListener.php'; require_once 'PHPUnit/Framework/Version.php'; +require_once 'PHPUnit/Runner/BaseTestRunner.php'; +require_once 'PHPUnit/TextUI/ResultPrinter.php'; /** * A TestRunner for the Command Line Interface (CLI) @@ -35,39 +35,16 @@ // {{{ Members /** - * @var integer + * @var PHPUnit_TextUI_ResultPrinter * @access private */ - private $fColumn = 0; + private $fPrinter; // }}} - // {{{ public function doRun(PHPUnit_Framework_Test $suite, $wait = false) + // {{{ public function __construct() - /** - * Runs a test suite. - * - * @param PHPUnit_Framework_Test $suite - * @param optional boolean $wait - * @return PHPUnit_Framework_TestResult - * @access public - */ - public function doRun(PHPUnit_Framework_Test $suite, $wait = false) { - printf( - "PHPUnit %s by Sebastian Bergmann.\n\n", - - PHPUnit_Framework_Version - ); - - $result = new PHPUnit_Framework_TestResult; - $result->addListener(new PHPUnit_TextUI_TestRunner); - - $suite->run($result); - - if ($wait) { - // ... - } - - return $result; + public function __construct() { + $this->fPrinter = new PHPUnit_TextUI_ResultPrinter; } // }}} @@ -92,16 +69,10 @@ $testRunner = new PHPUnit_TextUI_TestRunner; try { - $timer = new Benchmark_Timer; - $timer->start(); - $result = $testRunner->doRun( $testRunner->getTest($test), $wait ); - - $timer->stop(); - $testRunner->printResult($result, $timer->timeElapsed()); } catch (Exception $e) { @@ -113,151 +84,39 @@ } // }}} - // {{{ public function printResult(PHPUnit_Framework_TestResult $result, $runTime) + // {{{ public function doRun(PHPUnit_Framework_Test $suite, $wait = false) /** - * @param PHPUnit_Framework_TestResult $result - * @param float $runTime + * Runs a test suite. + * + * @param PHPUnit_Framework_Test $suite + * @param optional boolean $wait + * @return PHPUnit_Framework_TestResult * @access public */ - public function printResult(PHPUnit_Framework_TestResult $result, $runTime) { - $this->printHeader($runTime); - $this->printErrors($result); - $this->printFailures($result); - $this->printFooter($result); - } - - // }}} - // {{{ protected function printDefects($defects, $count, $type) - - /** - * @param array $defects - * @param integer $count - * @param string $type - * @access protected - */ - protected function printDefects($defects, $count, $type) { - if ($count == 0) { - return; - } - - printf( - "There %s %d %s%s:\n", - - ($count == 1) ? 'was' : 'were', - $count, - $type, - ($count == 1) ? '' : 's' - ); - - $i = 1; - - foreach ($defects as $defect) { - $this->printDefect($defect, $i++); - } - } - - // }}} - // {{{ protected function printDefect(PHPUnit_Framework_TestFailure $defect, $count) - - /** - * @param PHPUnit_Framework_TestFailure $defect - * @param integer $count - * @access protected - */ - protected function printDefect(PHPUnit_Framework_TestFailure $defect, $count) { - $this->printDefectHeader($defect, $count); - $this->printDefectTrace($defect); - } - - // }}} - // {{{ protected function printDefectHeader(PHPUnit_Framework_TestFailure $defect, $count) - - /** - * @param PHPUnit_Framework_TestFailure $defect - * @param integer $count - * @access protected - */ - protected function printDefectHeader(PHPUnit_Framework_TestFailure $defect, $count) { + public function doRun(PHPUnit_Framework_Test $suite, $wait = false) { printf( - "%d) %s\n", + "PHPUnit %s by Sebastian Bergmann.\n\n", - $count, - $defect->failedTest()->getName() + PHPUnit_Framework_Version ); - } - - // }}} - // {{{ protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect) - - /** - * @param PHPUnit_Framework_TestFailure $defect - * @access protected - */ - protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect) { - } - - // }}} - // {{{ protected function printErrors(PHPUnit_Framework_TestResult $result) - - /** - * @param PHPUnit_Framework_TestResult $result - * @access protected - */ - protected function printErrors(PHPUnit_Framework_TestResult $result) { - $this->printDefects($result->errors(), $result->errorCount(), 'error'); - } - - // }}} - // {{{ protected function printFailures(PHPUnit_Framework_TestResult $result) - - /** - * @param PHPUnit_Framework_TestResult $result - * @access protected - */ - protected function printFailures(PHPUnit_Framework_TestResult $result) { - $this->printDefects($result->failures(), $result->failureCount(), 'failure'); - } - // }}} - // {{{ protected function printHeader($runTime) + $result = new PHPUnit_Framework_TestResult; + $result->addListener($this->fPrinter); - /** - * @param float $runTime - * @access protected - */ - protected function printHeader($runTime) { - printf( - "\n\nTime: %s\n", + $timer = new Benchmark_Timer; - $runTime - ); - } + $timer->start(); + $suite->run($result); + $timer->stop(); - // }}} - // {{{ protected function printFooter(PHPUnit_Framework_TestResult $result) + if ($wait) { + // ... + } - /** - * @param PHPUnit_Framework_TestResult $result - * @access protected - */ - protected function printFooter(PHPUnit_Framework_TestResult $result) { - if ($result->wasSuccessful()) { - printf( - "\nOK (%d test%s)\n", - - $result->runCount(), - ($result->runCount() == 1) ? '' : 's' - ); - } else { - printf( - "\nFAILURES!!!\nTests run: %d, Failures: %d, Errors: %d.\n", + $this->fPrinter->printResult($result, $timer->timeElapsed()); - $result->runCount(), - $result->failureCount(), - $result->errorCount() - ); - } + return $result; } // }}} @@ -295,24 +154,12 @@ /** * A test failed. * - * @param integer $status + * @param integer $status * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @access public */ - public function testFailed($status, PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e) { - switch ($status) { - case PHPUnit_Runner_TestRunListener::STATUS_ERROR: { - print 'E'; - } - break; - - case PHPUnit_Runner_TestRunListener::STATUS_FAILURE: { - print 'F'; - } - break; - } - } + public function testFailed($status, PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e) {} // }}} // {{{ public function testStarted($testName) @@ -323,14 +170,7 @@ * @param string $testName * @access public */ - public function testStarted($testName) { - print '.'; - - if ($this->fColumn++ >= 40) { - $this->fColumn = 0; - print "\n"; - } - } + public function testStarted($testName) {} // }}} // {{{ protected function runFailed($message) Index: pear/PHPUnit/TextUI/ResultPrinter.php +++ pear/PHPUnit/TextUI/ResultPrinter.php
« previous php.pear.cvs (#10760) next »