Skip to content

Commit

Permalink
Revert "Added optional value to fail-fast option"
Browse files Browse the repository at this point in the history
This reverts commit 29cd2d1.
  • Loading branch information
Naktibalda committed Dec 20, 2021
1 parent 484a354 commit 6a011b1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/Codeception/Codecept.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}
}
10 changes: 1 addition & 9 deletions tests/cli/RunCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ 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 --no-exit');
$I->seeInShellOutput('FailingTest: Me');
Expand All @@ -306,14 +306,6 @@ public function runTestWithFailFastDefault(\CliGuy $I)
$I->dontSeeInShellOutput("PassingTest: Me");
}

public function runTestWithFailFastCustom(\CliGuy $I)
{
$I->executeCommand('run unit tests/unit/FailingTest.php --fail-fast=2 --no-exit');
$I->seeInShellOutput('There were 2 failures');
$I->executeCommand('run unit tests/unit/FailingTest.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
9 changes: 0 additions & 9 deletions tests/data/claypit/tests/unit/FailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,4 @@ public function testMe()
$this->assertFalse(true);
}

public function testMeTwo()
{
$this->assertFalse(true);
}

public function testMeThree()
{
$this->assertFalse(true);
}
}

0 comments on commit 6a011b1

Please sign in to comment.