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\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\Hook\Tester\Setup\HookedTeardown; |
22
|
|
|
use Behat\Testwork\Tester\Result\TestResult; |
23
|
|
|
use Gorghoa\ScenarioStateBehatExtension\Hook\Dispatcher\ScenarioStateHookDispatcher; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Vincent Chalamon <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
final class ScenarioStateHookableScenarioTester implements ScenarioTester |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var ScenarioTester |
32
|
|
|
*/ |
33
|
|
|
private $baseTester; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var ScenarioStateHookDispatcher |
37
|
|
|
*/ |
38
|
|
|
private $dispatcher; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ScenarioTester $baseTester |
42
|
|
|
* @param ScenarioStateHookDispatcher $dispatcher |
43
|
|
|
*/ |
44
|
3 |
|
public function __construct(ScenarioTester $baseTester, ScenarioStateHookDispatcher $dispatcher) |
45
|
|
|
{ |
46
|
3 |
|
$this->baseTester = $baseTester; |
47
|
3 |
|
$this->dispatcher = $dispatcher; |
48
|
3 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
1 |
View Code Duplication |
public function setUp(Environment $env, FeatureNode $feature, Scenario $scenario, $skip) |
|
|
|
|
54
|
|
|
{ |
55
|
1 |
|
$setup = $this->baseTester->setUp($env, $feature, $scenario, true); |
56
|
|
|
|
57
|
1 |
|
if ($skip) { |
58
|
1 |
|
return $setup; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$hookCallResults = $this->dispatcher->dispatchScopeHooks(new BeforeScenarioScope($env, $feature, $scenario)); |
62
|
|
|
|
63
|
|
|
return new HookedSetup($setup, $hookCallResults); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
1 |
|
public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip) |
70
|
|
|
{ |
71
|
1 |
|
return $this->baseTester->test($env, $feature, $scenario, $skip); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
1 |
View Code Duplication |
public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result) |
|
|
|
|
78
|
|
|
{ |
79
|
1 |
|
$teardown = $this->baseTester->tearDown($env, $feature, $scenario, true, $result); |
80
|
|
|
|
81
|
1 |
|
if ($skip) { |
82
|
1 |
|
return $teardown; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$hookCallResults = $this->dispatcher->dispatchScopeHooks(new AfterScenarioScope($env, $feature, $scenario, $result)); |
86
|
|
|
|
87
|
|
|
return new HookedTeardown($teardown, $hookCallResults); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.