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\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;
31 * Tester executing step tests in the runtime.
33 * @author Konstantin Kudryashov <ever.zet@gmail.com>
35 final class RuntimeStepTester implements StepTester
38 * @var DefinitionFinder
40 private $definitionFinder;
49 * @param DefinitionFinder $definitionFinder
50 * @param CallCenter $callCenter
52 public function __construct(DefinitionFinder $definitionFinder, CallCenter $callCenter)
54 $this->definitionFinder = $definitionFinder;
55 $this->callCenter = $callCenter;
61 public function setUp(Environment $env, FeatureNode $feature, StepNode $step, $skip)
63 return new SuccessfulSetup();
69 public function test(Environment $env, FeatureNode $feature, StepNode $step, $skip = false)
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);
84 public function tearDown(Environment $env, FeatureNode $feature, StepNode $step, $skip, StepResult $result)
86 return new SuccessfulTeardown();
90 * Searches for a definition.
92 * @param Environment $env
93 * @param FeatureNode $feature
94 * @param StepNode $step
96 * @return SearchResult
98 private function searchDefinition(Environment $env, FeatureNode $feature, StepNode $step)
100 return $this->definitionFinder->findDefinition($env, $feature, $step);
104 * Tests found definition.
106 * @param Environment $env
107 * @param FeatureNode $feature
108 * @param StepNode $step
109 * @param SearchResult $search
110 * @param Boolean $skip
114 private function testDefinition(Environment $env, FeatureNode $feature, StepNode $step, SearchResult $search, $skip)
116 if (!$search->hasMatch()) {
117 return new UndefinedStepResult();
121 return new SkippedStepResult($search);
124 $call = $this->createDefinitionCall($env, $feature, $search, $step);
125 $result = $this->callCenter->makeCall($call);
127 return new ExecutedStepResult($search, $result);
131 * Creates definition call.
133 * @param Environment $env
134 * @param FeatureNode $feature
135 * @param SearchResult $search
136 * @param StepNode $step
138 * @return DefinitionCall
140 private function createDefinitionCall(Environment $env, FeatureNode $feature, SearchResult $search, StepNode $step)
142 $definition = $search->getMatchedDefinition();
143 $arguments = $search->getMatchedArguments();
145 return new DefinitionCall($env, $feature, $step, $definition, $arguments);