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\AfterScenarioScope; |
15
|
|
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope; |
16
|
|
|
use Behat\Behat\Hook\Tester\HookableScenarioTester; |
17
|
|
|
use Behat\Behat\Tester\ScenarioTester; |
18
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
19
|
|
|
use Behat\Gherkin\Node\ScenarioInterface as Scenario; |
20
|
|
|
use Behat\Testwork\Environment\Environment; |
21
|
|
|
use Behat\Testwork\Hook\Tester\Setup\HookedSetup; |
22
|
|
|
use Behat\Testwork\Hook\Tester\Setup\HookedTeardown; |
23
|
|
|
use Behat\Testwork\Tester\Result\TestResult; |
24
|
|
|
use Gorghoa\ScenarioStateBehatExtension\Hook\Dispatcher\ScenarioStateHookDispatcher; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @author Vincent Chalamon <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
final class ScenarioStateHookableScenarioTester implements ScenarioTester |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var HookableScenarioTester |
33
|
|
|
*/ |
34
|
|
|
private $baseTester; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ScenarioStateHookDispatcher |
38
|
|
|
*/ |
39
|
|
|
private $dispatcher; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param HookableScenarioTester $baseTester |
43
|
|
|
* @param ScenarioStateHookDispatcher $dispatcher |
44
|
|
|
*/ |
45
|
|
|
public function __construct(HookableScenarioTester $baseTester, ScenarioStateHookDispatcher $dispatcher) |
46
|
|
|
{ |
47
|
|
|
$this->baseTester = $baseTester; |
48
|
|
|
$this->dispatcher = $dispatcher; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function setUp(Environment $env, FeatureNode $feature, Scenario $scenario, $skip) |
55
|
|
|
{ |
56
|
|
|
$setup = $this->baseTester->setUp($env, $feature, $scenario, true); |
57
|
|
|
|
58
|
|
|
if ($skip) { |
59
|
|
|
return $setup; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$hookCallResults = $this->dispatcher->dispatchScopeHooks(new BeforeScenarioScope($env, $feature, $scenario)); |
63
|
|
|
|
64
|
|
|
return new HookedSetup($setup, $hookCallResults); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip) |
71
|
|
|
{ |
72
|
|
|
return $this->baseTester->test($env, $feature, $scenario, $skip); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result) |
79
|
|
|
{ |
80
|
|
|
$teardown = $this->baseTester->tearDown($env, $feature, $scenario, $skip, $result); |
81
|
|
|
|
82
|
|
|
if ($skip) { |
83
|
|
|
return $teardown; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$hookCallResults = $this->dispatcher->dispatchScopeHooks(new AfterScenarioScope($env, $feature, $scenario, $result)); |
87
|
|
|
|
88
|
|
|
return new HookedTeardown($teardown, $hookCallResults); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|