1
|
|
|
<?php |
2
|
|
|
namespace Ciandt\Behat\PlaceholdersExtension\Tester; |
3
|
|
|
|
4
|
|
|
use Behat\Behat\Tester\OutlineTester; |
5
|
|
|
use Behat\Behat\Tester\ScenarioTester; |
6
|
|
|
use Behat\Gherkin\Node\OutlineNode; |
7
|
|
|
use Behat\Testwork\Environment\Environment; |
8
|
|
|
use Behat\Testwork\Environment\EnvironmentManager; |
9
|
|
|
use Behat\Testwork\Tester\Result\IntegerTestResult; |
10
|
|
|
use Behat\Testwork\Tester\Result\TestResult; |
11
|
|
|
use Behat\Testwork\Tester\Result\TestResults; |
12
|
|
|
use Behat\Testwork\Tester\Result\TestWithSetupResult; |
13
|
|
|
use Behat\Testwork\Tester\Setup\SuccessfulSetup; |
14
|
|
|
use Behat\Testwork\Tester\Setup\SuccessfulTeardown; |
15
|
|
|
use Behat\Testwork\Tester\SpecificationTester; |
16
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
17
|
|
|
use Behat\Gherkin\Node\ScenarioNode; |
18
|
|
|
use Behat\Gherkin\Node\StepNode; |
19
|
|
|
use Ciandt\Behat\PlaceholdersExtension\Config\PlaceholdersRepository; |
20
|
|
|
use Ciandt\Behat\PlaceholdersExtension\Utils\PlaceholderUtils; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Tester executing feature tests in the runtime. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
final class ScenarioBranchingFeatureTester implements SpecificationTester |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var SpecificationTester |
31
|
|
|
*/ |
32
|
|
|
private $baseTester; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private $variantTags; |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private $configsRepo; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Initializes tester. |
46
|
|
|
* |
47
|
|
|
* @param SpecificationTester $baseTester |
48
|
|
|
*/ |
49
|
|
|
public function __construct(SpecificationTester $baseTester, PlaceholdersRepository $configsRepo) |
50
|
|
|
{ |
51
|
|
|
$this->baseTester = $baseTester; |
52
|
|
|
$this->configsRepo = $configsRepo; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function setUp(Environment $env, $spec, $skip) |
59
|
|
|
{ |
60
|
|
|
return new SuccessfulSetup(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function test(Environment $env, $feature, $skip = false) |
67
|
|
|
{ |
68
|
|
|
$tester = $this->baseTester; |
69
|
|
|
$reconstructedFeature = $this->preprocessFeature($feature); |
70
|
|
|
return $tester->test($env, $reconstructedFeature, $skip); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function preprocessFeature(FeatureNode $feature) |
74
|
|
|
{ |
75
|
|
|
$scenarios = array(); |
76
|
|
|
|
77
|
|
|
foreach ($feature->getScenarios() as $scenario) { |
78
|
|
|
$scenarios = array_merge($scenarios,$this->splitScenarioPerVariants($scenario,$feature)); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return new FeatureNode( |
82
|
|
|
$feature->getTitle(), |
83
|
|
|
$feature->getDescription(), |
84
|
|
|
$feature->getTags(), |
85
|
|
|
$feature->getBackground(), |
86
|
|
|
$scenarios, |
87
|
|
|
$feature->getKeyword(), |
88
|
|
|
$feature->getLanguage(), |
89
|
|
|
$feature->getFile(), |
90
|
|
|
$feature->getLine() |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
private function splitScenarioPerVariants(ScenarioNode $scenario, FeatureNode $feature){ |
95
|
|
|
$scenarioTags = $scenario->getTags(); |
96
|
|
|
$featureTags = $feature->getTags(); |
97
|
|
|
$tags = array_merge($scenarioTags,$featureTags); |
98
|
|
|
|
99
|
|
|
$variants = PlaceholderUtils::filterVariantTags($tags,false); |
100
|
|
|
|
101
|
|
|
if (count($variants) <= 1) { |
102
|
|
|
return array($scenario); |
103
|
|
|
} else { |
104
|
|
|
return $this->forkScenario($scenario, $variants); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
private function forkScenario(ScenarioNode $scenario, $variants) |
110
|
|
|
{ |
111
|
|
|
$scenarios = array(); |
112
|
|
|
$nonVariantTags = PlaceholderUtils::filterVariantTags($scenario->getTags(),true); |
113
|
|
|
foreach ($variants as $variant) { |
114
|
|
|
$tags = array_merge($nonVariantTags, array($variant)); |
115
|
|
|
$scenarios[] = new ScenarioNode( |
116
|
|
|
$scenario->getTitle(), |
117
|
|
|
$tags, |
118
|
|
|
$scenario->getSteps(), |
119
|
|
|
$scenario->getKeyword(), |
120
|
|
|
$scenario->getLine() |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
return $scenarios; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
*/ |
129
|
|
|
public function tearDown(Environment $env, $spec, $skip, TestResult $result) |
130
|
|
|
{ |
131
|
|
|
return new SuccessfulTeardown(); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.