Skip to content

Commit

Permalink
Merge pull request #6297 from Codeception/4.1-revert-fail-fast-change
Browse files Browse the repository at this point in the history
Revert adding optional value to fail-fast option
  • Loading branch information
Naktibalda committed Dec 21, 2021
2 parents d3656d1 + 6a011b1 commit 8a3ec8c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/Codeception/Codecept.php
Expand Up @@ -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']) {
Expand Down
8 changes: 2 additions & 6 deletions src/Codeception/Command/Run.php
Expand Up @@ -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`
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down
30 changes: 4 additions & 26 deletions src/Codeception/Subscriber/FailFast.php
Expand Up @@ -2,7 +2,6 @@
namespace Codeception\Subscriber;

use Codeception\Event\SuiteEvent;
use Codeception\Event\TestEvent;
use Codeception\Events;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand All @@ -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);
}
}
14 changes: 3 additions & 11 deletions tests/cli/RunCest.php
Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion tests/data/claypit/tests/unit/FailingTest.php
Expand Up @@ -6,4 +6,5 @@ public function testMe()
{
$this->assertFalse(true);
}
}

}
22 changes: 0 additions & 22 deletions tests/data/claypit/tests/unit/MultipleFailingTest.php

This file was deleted.

0 comments on commit 8a3ec8c

Please sign in to comment.