Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Tester / Runtime / RuntimeScenarioTester.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Tester\Runtime;
12
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;
25
26 /**
27  * Tester executing scenario or example tests in the runtime.
28  *
29  * @author Konstantin Kudryashov <ever.zet@gmail.com>
30  */
31 final class RuntimeScenarioTester implements ScenarioTester
32 {
33     /**
34      * @var StepContainerTester
35      */
36     private $containerTester;
37     /**
38      * @var BackgroundTester
39      */
40     private $backgroundTester;
41
42     /**
43      * Initializes tester.
44      *
45      * @param StepContainerTester $containerTester
46      * @param BackgroundTester    $backgroundTester
47      */
48     public function __construct(StepContainerTester $containerTester, BackgroundTester $backgroundTester)
49     {
50         $this->containerTester = $containerTester;
51         $this->backgroundTester = $backgroundTester;
52     }
53
54     /**
55      * {@inheritdoc}
56      */
57     public function setUp(Environment $env, FeatureNode $feature, Scenario $example, $skip)
58     {
59         return new SuccessfulSetup();
60     }
61
62     /**
63      * {@inheritdoc}
64      */
65     public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip = false)
66     {
67         $results = array();
68
69         if ($feature->hasBackground()) {
70             $backgroundResult = $this->testBackground($env, $feature, $skip);
71             $skip = !$backgroundResult->isPassed() || $skip;
72
73             $results[] = $backgroundResult;
74         }
75
76         $results = array_merge($results, $this->containerTester->test($env, $feature, $scenario, $skip));
77
78         return new TestResults($results);
79     }
80
81     /**
82      * {@inheritdoc}
83      */
84     public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result)
85     {
86         return new SuccessfulTeardown();
87     }
88
89     /**
90      * Tests background of the provided feature against provided environment.
91      *
92      * @param Environment $env
93      * @param FeatureNode $feature
94      * @param Boolean     $skip
95      *
96      * @return TestResult
97      */
98     private function testBackground(Environment $env, FeatureNode $feature, $skip)
99     {
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);
104
105         $integerResult = new IntegerTestResult($testResult->getResultCode());
106
107         return new TestWithSetupResult($setup, $integerResult, $teardown);
108     }
109 }