1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Behat. |
5
|
|
|
* (c) Konstantin Kudryashov <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Behat\TokensExtension; |
12
|
|
|
|
13
|
|
|
use Behat\Behat\Tester\Result\StepResult; |
14
|
|
|
use Behat\Behat\Tester\StepTester; |
15
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
16
|
|
|
use Behat\Gherkin\Node\StepNode; |
17
|
|
|
use Behat\Testwork\Environment\Environment; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Step tester replacing tokens in step text. |
21
|
|
|
*/ |
22
|
|
|
final class TokensReplacementStepTester implements StepTester |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var StepTester |
26
|
|
|
*/ |
27
|
|
|
private $baseTester; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var StepTokensReplacer |
31
|
|
|
*/ |
32
|
|
|
private $tokensReplacer; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var StepNode |
36
|
|
|
*/ |
37
|
|
|
private $step; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Initializes tester. |
41
|
|
|
* |
42
|
|
|
* @param StepTester $baseTester |
43
|
|
|
* @param StepTokensReplacer $tokensReplacer |
44
|
|
|
*/ |
45
|
|
|
public function __construct(StepTester $baseTester, StepTokensReplacer $tokensReplacer) |
46
|
|
|
{ |
47
|
|
|
$this->baseTester = $baseTester; |
48
|
|
|
$this->tokensReplacer = $tokensReplacer; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function setUp(Environment $env, FeatureNode $feature, StepNode $step, $skip) |
55
|
|
|
{ |
56
|
|
|
$step = $this->tokensReplacer->replaceTokens($env, $feature, $step); |
57
|
|
|
|
58
|
|
|
if (!$step instanceof StepNode) { |
59
|
|
|
throw new \RuntimeException('Token replacement failed to return a valid StepNode object'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->step = $step; |
63
|
|
|
return $this->baseTester->setUp($env, $feature, $this->step, $skip); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function test(Environment $env, FeatureNode $feature, StepNode $step, $skip) |
70
|
|
|
{ |
71
|
|
|
return $this->baseTester->test($env, $feature, $this->step, $skip); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function tearDown(Environment $env, FeatureNode $feature, StepNode $step, $skip, StepResult $result) |
78
|
|
|
{ |
79
|
|
|
return $this->baseTester->tearDown($env, $feature, $this->step, $skip, $result); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|