diff --git a/src/Codeception/Codecept.php b/src/Codeception/Codecept.php index f2b31286e9..c671d33207 100644 --- a/src/Codeception/Codecept.php +++ b/src/Codeception/Codecept.php @@ -133,7 +133,7 @@ public function registerSubscribers() $this->dispatcher->addSubscriber(new Subscriber\Console($this->options)); } if ($this->options['fail-fast']) { - $this->dispatcher->addSubscriber(new Subscriber\FailFast($this->options['fail-fast'])); + $this->dispatcher->addSubscriber(new Subscriber\FailFast()); } if ($this->options['coverage']) { diff --git a/src/Codeception/Command/Run.php b/src/Codeception/Command/Run.php index 9e83f3bf0e..8a11897015 100644 --- a/src/Codeception/Command/Run.php +++ b/src/Codeception/Command/Run.php @@ -82,7 +82,7 @@ * --skip (-s) Skip selected suites (multiple values allowed) * --skip-group (-x) Skip selected groups (multiple values allowed) * --env Run tests in selected environments. (multiple values allowed, environments can be merged with ',') - * --fail-fast (-f) Stop after nth failure (defaults to 1) + * --fail-fast (-f) Stop after first failure * --no-rebuild Do not rebuild actor classes on start * --help (-h) Display this help message. * --quiet (-q) Do not output any message. Almost the same as `--silent` @@ -214,7 +214,7 @@ protected function configure() InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Run tests in selected environments.' ), - new InputOption('fail-fast', 'f', InputOption::VALUE_OPTIONAL, 'Stop after nth failure'), + new InputOption('fail-fast', 'f', InputOption::VALUE_NONE, 'Stop after first failure'), new InputOption('no-rebuild', '', InputOption::VALUE_NONE, 'Do not rebuild actor classes on start'), new InputOption( 'seed', @@ -326,10 +326,6 @@ public function execute(InputInterface $input, OutputInterface $output) if (!$userOptions['ansi'] && $input->getOption('colors')) { $userOptions['colors'] = true; // turn on colors even in non-ansi mode if strictly passed } - // array key will exist if fail-fast option is used - if (array_key_exists('fail-fast', $userOptions)) { - $userOptions['fail-fast'] = (int) $this->options['fail-fast'] ?: 1; - } $suite = $input->getArgument('suite'); $test = $input->getArgument('test'); diff --git a/src/Codeception/Subscriber/FailFast.php b/src/Codeception/Subscriber/FailFast.php index 37e8d21eea..2f40529d3d 100644 --- a/src/Codeception/Subscriber/FailFast.php +++ b/src/Codeception/Subscriber/FailFast.php @@ -2,7 +2,6 @@ namespace Codeception\Subscriber; use Codeception\Event\SuiteEvent; -use Codeception\Event\TestEvent; use Codeception\Events; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -11,33 +10,12 @@ class FailFast implements EventSubscriberInterface use Shared\StaticEvents; public static $events = [ - Events::TEST_FAIL => 'stopOnFail', - Events::TEST_ERROR => 'stopOnFail', - Events::SUITE_BEFORE => 'cacheSuite' + Events::SUITE_BEFORE => 'stopOnFail', ]; - private $failureCount = 0; - - private $stopFailureCount; - - private $suiteCache; - - public function __construct($stopFailureCount) - { - $this->stopFailureCount = (int) $stopFailureCount; - } - - public function cacheSuite(SuiteEvent $e) + public function stopOnFail(SuiteEvent $e) { - $this->suiteCache = $e->getResult(); - } - - public function stopOnFail(TestEvent $e) - { - $this->failureCount++; - - if ($this->failureCount >= $this->stopFailureCount) { - $this->suiteCache->stop(); - } + $e->getResult()->stopOnError(true); + $e->getResult()->stopOnFailure(true); } } diff --git a/tests/cli/RunCest.php b/tests/cli/RunCest.php index 5c71b4c31c..162e038faa 100755 --- a/tests/cli/RunCest.php +++ b/tests/cli/RunCest.php @@ -296,24 +296,16 @@ public function runOneGroupWithDataProviders(\CliGuy $I) $I->seeInShellOutput("OK"); } - public function runTestWithFailFastDefault(\CliGuy $I) + public function runTestWithFailFast(\CliGuy $I) { - $I->executeCommand('run unit --skip-group error --skip-group multiple-fail --no-exit'); + $I->executeCommand('run unit --skip-group error --no-exit'); $I->seeInShellOutput('FailingTest: Me'); $I->seeInShellOutput("PassingTest: Me"); - $I->executeCommand('run unit --fail-fast --skip-group error --skip-group multiple-fail --no-exit'); + $I->executeCommand('run unit --fail-fast --skip-group error --no-exit'); $I->seeInShellOutput('There was 1 failure'); $I->dontSeeInShellOutput("PassingTest: Me"); } - public function runTestWithFailFastCustom(\CliGuy $I) - { - $I->executeCommand('run unit MultipleFailingTest.php --fail-fast=2 --no-exit'); - $I->seeInShellOutput('There were 2 failures'); - $I->executeCommand('run unit MultipleFailingTest.php --no-exit'); - $I->seeInShellOutput('There were 3 failures'); - } - public function runWithCustomOutputPath(\CliGuy $I) { $I->executeCommand('run dummy --xml myverycustom.xml --html myownhtmlreport.html'); diff --git a/tests/data/claypit/tests/unit/FailingTest.php b/tests/data/claypit/tests/unit/FailingTest.php index d94bd154b5..3229f9231b 100644 --- a/tests/data/claypit/tests/unit/FailingTest.php +++ b/tests/data/claypit/tests/unit/FailingTest.php @@ -6,4 +6,5 @@ public function testMe() { $this->assertFalse(true); } -} + +} \ No newline at end of file diff --git a/tests/data/claypit/tests/unit/MultipleFailingTest.php b/tests/data/claypit/tests/unit/MultipleFailingTest.php deleted file mode 100644 index 5e73ccc71f..0000000000 --- a/tests/data/claypit/tests/unit/MultipleFailingTest.php +++ /dev/null @@ -1,22 +0,0 @@ -assertFalse(true); - } - - public function testMeTwo() - { - $this->assertFalse(true); - } - - public function testMeThree() - { - $this->assertFalse(true); - } -} \ No newline at end of file