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\ScenarioTester;
14 use Behat\Gherkin\Node\FeatureNode;
15 use Behat\Gherkin\Node\ScenarioInterface as Scenario;
16 use Behat\Testwork\Environment\Environment;
17 use Behat\Testwork\Environment\EnvironmentManager;
18 use Behat\Testwork\Tester\Result\IntegerTestResult;
19 use Behat\Testwork\Tester\Result\TestResult;
20 use Behat\Testwork\Tester\Result\TestWithSetupResult;
21 use Behat\Testwork\Tester\Setup\SuccessfulSetup;
22 use Behat\Testwork\Tester\Setup\SuccessfulTeardown;
25 * Scenario tester that isolates the environment for each scenario.
27 * @author Konstantin Kudryashov <ever.zet@gmail.com>
29 final class IsolatingScenarioTester implements ScenarioTester
34 private $decoratedTester;
36 * @var EnvironmentManager
43 * @param ScenarioTester $decoratedTester
44 * @param EnvironmentManager $envManager
46 public function __construct(ScenarioTester $decoratedTester, EnvironmentManager $envManager)
48 $this->decoratedTester = $decoratedTester;
49 $this->envManager = $envManager;
55 public function setUp(Environment $env, FeatureNode $feature, Scenario $scenario, $skip)
57 return new SuccessfulSetup();
63 public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip)
65 $isolatedEnvironment = $this->envManager->isolateEnvironment($env, $scenario);
67 $setup = $this->decoratedTester->setUp($isolatedEnvironment, $feature, $scenario, $skip);
68 $localSkip = !$setup->isSuccessful() || $skip;
69 $testResult = $this->decoratedTester->test($isolatedEnvironment, $feature, $scenario, $localSkip);
70 $teardown = $this->decoratedTester->tearDown($isolatedEnvironment, $feature, $scenario, $localSkip, $testResult);
72 $integerResult = new IntegerTestResult($testResult->getResultCode());
74 return new TestWithSetupResult($setup, $integerResult, $teardown);
80 public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result)
82 return new SuccessfulTeardown();