forked from michalochman/SilverStripeExtension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bd1452
commit e73d208
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace SilverStripe\BehatExtension\Utility; | ||
|
||
use Behat\Behat\Tester\ScenarioTester; | ||
use Behat\Gherkin\Node\FeatureNode; | ||
use Behat\Gherkin\Node\ScenarioInterface; | ||
use Behat\Testwork\Environment\Environment; | ||
use Behat\Testwork\Tester\Result\TestResult; | ||
|
||
/** | ||
* This tester will retry a scenario if it fails within the same test run. | ||
* Note that this is different from the following retry solutions: | ||
* - RetryableCallHandler using the @retry tag, which gives assertion an additional 3 seconds | ||
* - RerunController, which uses the --rerun option to run only previously failed scenarios in a subsequent test run | ||
*/ | ||
class RetryScenarioTester implements ScenarioTester | ||
{ | ||
private ScenarioTester $decoratedTester; | ||
|
||
public function __construct(ScenarioTester $decoratedTester) | ||
{ | ||
$this->decoratedTester = $decoratedTester; | ||
} | ||
|
||
public function setUp(Environment $env, FeatureNode $feature, ScenarioInterface $scenario, $skip) | ||
{ | ||
return $this->decoratedTester->setUp($env, $feature, $scenario, $skip); | ||
} | ||
|
||
public function test(Environment $env, FeatureNode $feature, ScenarioInterface $scenario, $skip) | ||
{ | ||
$result = $this->decoratedTester->test($env, $feature, $scenario, $skip); | ||
if (!$skip && !$result->isPassed()) { | ||
// Run the scenario again | ||
file_put_contents('php://stdout', 'Retrying scenario: ' . $scenario->getTitle() . PHP_EOL); | ||
$result = $this->decoratedTester->test($env, $feature, $scenario, $skip); | ||
} | ||
return $result; | ||
} | ||
|
||
public function tearDown(Environment $env, FeatureNode $feature, ScenarioInterface $scenario, $skip, TestResult $result) | ||
{ | ||
return $this->decoratedTester->tearDown($env, $feature, $scenario, $skip, $result); | ||
} | ||
} |