|
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 $baseTester; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var ScenarioStateHookDispatcher |
|
36
|
|
|
*/ |
|
37
|
|
|
private $dispatcher; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param HookableScenarioTester $baseTester |
|
41
|
|
|
* @param ScenarioStateHookDispatcher $dispatcher |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(HookableScenarioTester $baseTester, ScenarioStateHookDispatcher $dispatcher) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->baseTester = $baseTester; |
|
46
|
|
|
$this->dispatcher = $dispatcher; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function setUp(Environment $env, FeatureNode $feature, Scenario $scenario, $skip) |
|
53
|
|
|
{ |
|
54
|
|
|
$setup = $this->baseTester->setUp($env, $feature, $scenario, true); |
|
55
|
|
|
|
|
56
|
|
|
if ($skip) { |
|
57
|
|
|
return $setup; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$scope = new BeforeScenarioScope($env, $feature, $scenario); |
|
61
|
|
|
$hookCallResults = $this->dispatcher->dispatchScopeHooks($scope); |
|
62
|
|
|
|
|
63
|
|
|
return new HookedSetup($setup, $hookCallResults); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->baseTester->test($env, $feature, $scenario, $skip); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
|
|
public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result) |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->baseTester->tearDown($env, $feature, $scenario, $skip, $result); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
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: