Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Tester / Runtime / RuntimeStepTester.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\Definition\Call\DefinitionCall;
14 use Behat\Behat\Definition\DefinitionFinder;
15 use Behat\Behat\Definition\Exception\SearchException;
16 use Behat\Behat\Definition\SearchResult;
17 use Behat\Behat\Tester\Result\ExecutedStepResult;
18 use Behat\Behat\Tester\Result\FailedStepSearchResult;
19 use Behat\Behat\Tester\Result\SkippedStepResult;
20 use Behat\Behat\Tester\Result\StepResult;
21 use Behat\Behat\Tester\Result\UndefinedStepResult;
22 use Behat\Behat\Tester\StepTester;
23 use Behat\Gherkin\Node\FeatureNode;
24 use Behat\Gherkin\Node\StepNode;
25 use Behat\Testwork\Call\CallCenter;
26 use Behat\Testwork\Environment\Environment;
27 use Behat\Testwork\Tester\Setup\SuccessfulSetup;
28 use Behat\Testwork\Tester\Setup\SuccessfulTeardown;
29
30 /**
31  * Tester executing step tests in the runtime.
32  *
33  * @author Konstantin Kudryashov <ever.zet@gmail.com>
34  */
35 final class RuntimeStepTester implements StepTester
36 {
37     /**
38      * @var DefinitionFinder
39      */
40     private $definitionFinder;
41     /**
42      * @var CallCenter
43      */
44     private $callCenter;
45
46     /**
47      * Initialize tester.
48      *
49      * @param DefinitionFinder $definitionFinder
50      * @param CallCenter       $callCenter
51      */
52     public function __construct(DefinitionFinder $definitionFinder, CallCenter $callCenter)
53     {
54         $this->definitionFinder = $definitionFinder;
55         $this->callCenter = $callCenter;
56     }
57
58     /**
59      * {@inheritdoc}
60      */
61     public function setUp(Environment $env, FeatureNode $feature, StepNode $step, $skip)
62     {
63         return new SuccessfulSetup();
64     }
65
66     /**
67      * {@inheritdoc}
68      */
69     public function test(Environment $env, FeatureNode $feature, StepNode $step, $skip = false)
70     {
71         try {
72             $search = $this->searchDefinition($env, $feature, $step);
73             $result = $this->testDefinition($env, $feature, $step, $search, $skip);
74         } catch (SearchException $exception) {
75             $result = new FailedStepSearchResult($exception);
76         }
77
78         return $result;
79     }
80
81     /**
82      * {@inheritdoc}
83      */
84     public function tearDown(Environment $env, FeatureNode $feature, StepNode $step, $skip, StepResult $result)
85     {
86         return new SuccessfulTeardown();
87     }
88
89     /**
90      * Searches for a definition.
91      *
92      * @param Environment $env
93      * @param FeatureNode $feature
94      * @param StepNode    $step
95      *
96      * @return SearchResult
97      */
98     private function searchDefinition(Environment $env, FeatureNode $feature, StepNode $step)
99     {
100         return $this->definitionFinder->findDefinition($env, $feature, $step);
101     }
102
103     /**
104      * Tests found definition.
105      *
106      * @param Environment  $env
107      * @param FeatureNode  $feature
108      * @param StepNode     $step
109      * @param SearchResult $search
110      * @param Boolean      $skip
111      *
112      * @return StepResult
113      */
114     private function testDefinition(Environment $env, FeatureNode $feature, StepNode $step, SearchResult $search, $skip)
115     {
116         if (!$search->hasMatch()) {
117             return new UndefinedStepResult();
118         }
119
120         if ($skip) {
121             return new SkippedStepResult($search);
122         }
123
124         $call = $this->createDefinitionCall($env, $feature, $search, $step);
125         $result = $this->callCenter->makeCall($call);
126
127         return new ExecutedStepResult($search, $result);
128     }
129
130     /**
131      * Creates definition call.
132      *
133      * @param Environment  $env
134      * @param FeatureNode  $feature
135      * @param SearchResult $search
136      * @param StepNode     $step
137      *
138      * @return DefinitionCall
139      */
140     private function createDefinitionCall(Environment $env, FeatureNode $feature, SearchResult $search, StepNode $step)
141     {
142         $definition = $search->getMatchedDefinition();
143         $arguments = $search->getMatchedArguments();
144
145         return new DefinitionCall($env, $feature, $step, $definition, $arguments);
146     }
147 }