Browse files

- Add PHPUnit_Framework_TestResult::stopOnFailure().

- Implement --stop-on-failure switch for the TextUI test runner.
- Closes #121.
  • Loading branch information...
1 parent 7654aed commit 64e8153a23482c95a09be8e57cb608658f07a6a1 @sebastianbergmann committed Jun 19, 2007
Showing with 47 additions and 4 deletions.
  1. +31 −0 PHPUnit/Framework/TestResult.php
  2. +7 −0 PHPUnit/TextUI/Command.php
  3. +9 −4 PHPUnit/TextUI/TestRunner.php
View
31 PHPUnit/Framework/TestResult.php
@@ -142,6 +142,12 @@ class PHPUnit_Framework_TestResult implements Countable
private $stop = FALSE;
/**
+ * @var boolean
+ * @access protected
+ */
+ protected $stopOnFailure = FALSE;
+
+ /**
* Registers a TestListener.
*
* @param PHPUnit_Framework_TestListener
@@ -215,6 +221,10 @@ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
foreach ($this->listeners as $listener) {
$listener->addError($test, $e, $time);
}
+
+ if ($this->stopOnFailure) {
+ $this->stop();
+ }
}
}
@@ -251,6 +261,10 @@ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_Asser
foreach ($this->listeners as $listener) {
$listener->addFailure($test, $e, $time);
}
+
+ if ($this->stopOnFailure) {
+ $this->stop();
+ }
}
}
@@ -617,6 +631,23 @@ public function stop()
}
/**
+ * Enables or disables the stopping when a failure or error occurs.
+ *
+ * @param boolean $flag
+ * @throws InvalidArgumentException
+ * @access public
+ * @since Method available since Release 3.1.0
+ */
+ public function stopOnFailure($flag)
+ {
+ if (is_bool($flag)) {
+ $this->stopOnFailure = $flag;
+ } else {
+ throw new InvalidArgumentException;
+ }
+ }
+
+ /**
* Returns the time spent running the tests.
*
* @return float
View
7 PHPUnit/TextUI/Command.php
@@ -141,6 +141,7 @@ protected static function handleArguments()
'log-xml=',
'repeat=',
'skeleton',
+ 'stop-on-failure',
'tap',
'testdox-html=',
'testdox-text=',
@@ -248,6 +249,11 @@ protected static function handleArguments()
}
break;
+ case '--stop-on-failure': {
+ $arguments['stopOnFailure'] = TRUE;
+ }
+ break;
+
case '--test-db-dsn': {
$arguments['testDatabaseDSN'] = $option[1];
}
@@ -427,6 +433,7 @@ public static function showHelp()
" --loader <loader> TestSuiteLoader implementation to use.\n" .
" --repeat <times> Runs the test(s) repeatedly.\n" .
" --tap Report test execution progress in TAP format.\n" .
+ " --stop-on-failure Stop execution upon first error or failure.\n" .
" --no-syntax-check Disable syntax check of test source files.\n" .
" --verbose Output more verbose information.\n" .
" --wait Waits for a keystroke after each test.\n\n" .
View
13 PHPUnit/TextUI/TestRunner.php
@@ -162,10 +162,11 @@ protected function createTestResult()
*/
public function doRun(PHPUnit_Framework_Test $suite, array $parameters = array())
{
- $parameters['repeat'] = isset($parameters['repeat']) ? $parameters['repeat'] : FALSE;
- $parameters['filter'] = isset($parameters['filter']) ? $parameters['filter'] : FALSE;
- $parameters['verbose'] = isset($parameters['verbose']) ? $parameters['verbose'] : FALSE;
- $parameters['wait'] = isset($parameters['wait']) ? $parameters['wait'] : FALSE;
+ $parameters['filter'] = isset($parameters['filter']) ? $parameters['filter'] : FALSE;
+ $parameters['stopOnFailure'] = isset($parameters['stopOnFailure']) ? $parameters['stopOnFailure']: FALSE;
+ $parameters['repeat'] = isset($parameters['repeat']) ? $parameters['repeat'] : FALSE;
+ $parameters['verbose'] = isset($parameters['verbose']) ? $parameters['verbose'] : FALSE;
+ $parameters['wait'] = isset($parameters['wait']) ? $parameters['wait'] : FALSE;
if (is_integer($parameters['repeat'])) {
$suite = new PHPUnit_Extensions_RepeatedTest($suite, $parameters['repeat']);
@@ -177,6 +178,10 @@ public function doRun(PHPUnit_Framework_Test $suite, array $parameters = array()
$result = $this->createTestResult();
+ if ($parameters['stopOnFailure']) {
+ $result->stopOnFailure(TRUE);
+ }
+
if ($this->printer === NULL) {
if (isset($parameters['printer']) && $parameters['printer'] instanceof PHPUnit_Util_Printer) {
$this->printer = $parameters['printer'];

0 comments on commit 64e8153

Please sign in to comment.