4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Tester\Runtime;
13 use Behat\Behat\Tester\BackgroundTester;
14 use Behat\Behat\Tester\StepContainerTester;
15 use Behat\Behat\Tester\ScenarioTester;
16 use Behat\Gherkin\Node\FeatureNode;
17 use Behat\Gherkin\Node\ScenarioInterface as Scenario;
18 use Behat\Testwork\Environment\Environment;
19 use Behat\Testwork\Tester\Result\IntegerTestResult;
20 use Behat\Testwork\Tester\Result\TestResult;
21 use Behat\Testwork\Tester\Result\TestResults;
22 use Behat\Testwork\Tester\Result\TestWithSetupResult;
23 use Behat\Testwork\Tester\Setup\SuccessfulSetup;
24 use Behat\Testwork\Tester\Setup\SuccessfulTeardown;
27 * Tester executing scenario or example tests in the runtime.
29 * @author Konstantin Kudryashov <ever.zet@gmail.com>
31 final class RuntimeScenarioTester implements ScenarioTester
34 * @var StepContainerTester
36 private $containerTester;
38 * @var BackgroundTester
40 private $backgroundTester;
45 * @param StepContainerTester $containerTester
46 * @param BackgroundTester $backgroundTester
48 public function __construct(StepContainerTester $containerTester, BackgroundTester $backgroundTester)
50 $this->containerTester = $containerTester;
51 $this->backgroundTester = $backgroundTester;
57 public function setUp(Environment $env, FeatureNode $feature, Scenario $example, $skip)
59 return new SuccessfulSetup();
65 public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip = false)
69 if ($feature->hasBackground()) {
70 $backgroundResult = $this->testBackground($env, $feature, $skip);
71 $skip = !$backgroundResult->isPassed() || $skip;
73 $results[] = $backgroundResult;
76 $results = array_merge($results, $this->containerTester->test($env, $feature, $scenario, $skip));
78 return new TestResults($results);
84 public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result)
86 return new SuccessfulTeardown();
90 * Tests background of the provided feature against provided environment.
92 * @param Environment $env
93 * @param FeatureNode $feature
94 * @param Boolean $skip
98 private function testBackground(Environment $env, FeatureNode $feature, $skip)
100 $setup = $this->backgroundTester->setUp($env, $feature, $skip);
101 $skipSetup = !$setup->isSuccessful() || $skip;
102 $testResult = $this->backgroundTester->test($env, $feature, $skipSetup);
103 $teardown = $this->backgroundTester->tearDown($env, $feature, $skipSetup, $testResult);
105 $integerResult = new IntegerTestResult($testResult->getResultCode());
107 return new TestWithSetupResult($setup, $integerResult, $teardown);