1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ScenarioStateBehatExtension project. |
5
|
|
|
* |
6
|
|
|
* (c) Rodrigue Villetard <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gorghoa\ScenarioStateBehatExtension\Hook\Tester; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope; |
15
|
|
|
use Behat\Behat\Hook\Tester\HookableScenarioTester; |
16
|
|
|
use Behat\Behat\Tester\ScenarioTester; |
17
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
18
|
|
|
use Behat\Gherkin\Node\ScenarioInterface as Scenario; |
19
|
|
|
use Behat\Testwork\Environment\Environment; |
20
|
|
|
use Behat\Testwork\Hook\Tester\Setup\HookedSetup; |
21
|
|
|
use Behat\Testwork\Tester\Result\TestResult; |
22
|
|
|
use Gorghoa\ScenarioStateBehatExtension\Hook\Dispatcher\ScenarioStateHookDispatcher; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Vincent Chalamon <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
final class ScenarioStateHookableScenarioTester implements ScenarioTester |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var HookableScenarioTester |
31
|
|
|
*/ |
32
|
|
|
private $decoratedService; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ScenarioTester |
36
|
|
|
*/ |
37
|
|
|
private $baseTester; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var ScenarioStateHookDispatcher |
41
|
|
|
*/ |
42
|
|
|
private $dispatcher; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param HookableScenarioTester $decoratedService |
46
|
|
|
* @param ScenarioTester $baseTester |
47
|
|
|
* @param ScenarioStateHookDispatcher $dispatcher |
48
|
|
|
*/ |
49
|
|
|
public function __construct(HookableScenarioTester $decoratedService, ScenarioTester $baseTester, ScenarioStateHookDispatcher $dispatcher) |
50
|
|
|
{ |
51
|
|
|
$this->decoratedService = $decoratedService; |
52
|
|
|
$this->baseTester = $baseTester; |
53
|
|
|
$this->dispatcher = $dispatcher; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function setUp(Environment $env, FeatureNode $feature, Scenario $scenario, $skip) |
60
|
|
|
{ |
61
|
|
|
$setup = $this->decoratedService->setUp($env, $feature, $scenario, true); |
62
|
|
|
|
63
|
|
|
if ($skip) { |
64
|
|
|
return $setup; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$scope = new BeforeScenarioScope($env, $feature, $scenario); |
68
|
|
|
$hookCallResults = $this->dispatcher->dispatchScopeHooks($scope); |
69
|
|
|
|
70
|
|
|
return new HookedSetup($setup, $hookCallResults); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip) |
77
|
|
|
{ |
78
|
|
|
return $this->decoratedService->test($env, $feature, $scenario, $skip); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result) |
85
|
|
|
{ |
86
|
|
|
return $this->decoratedService->tearDown($env, $feature, $scenario, $skip, $result); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: