|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GD; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Gherkin\Gherkin; |
|
6
|
|
|
use Behat\Gherkin\Keywords\CucumberKeywords; |
|
7
|
|
|
use Behat\Gherkin\Lexer; |
|
8
|
|
|
use Behat\Gherkin\Loader\GherkinFileLoader; |
|
9
|
|
|
use Behat\Gherkin\Loader\YamlFileLoader; |
|
10
|
|
|
use Behat\Gherkin\Parser; |
|
11
|
|
|
use GD\Exceptions\MustSetFileNameAndPath; |
|
12
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
13
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
14
|
|
|
|
|
15
|
|
|
class GherkinToDusk extends BaseGherkinToDusk |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
protected $component = false; |
|
19
|
|
|
|
|
20
|
|
|
protected $string_contents = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Yml Content of a test yml |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $feature_content; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var \Behat\Gherkin\Node\FeatureNode |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $parsed_feature; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $dusk_class_and_methods; |
|
37
|
|
|
|
|
38
|
|
|
protected $dusk_test_name; |
|
39
|
|
|
|
|
40
|
|
|
public function initializeFeature() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->loadFileContent(); |
|
43
|
|
|
|
|
44
|
|
|
$this->buildDuskTestName(); |
|
45
|
|
|
|
|
46
|
|
|
$this->passThroughParser(); |
|
47
|
|
|
|
|
48
|
|
|
$this->breakIntoMethods(); |
|
49
|
|
|
|
|
50
|
|
|
if ($this->context == 'domain') { |
|
51
|
|
|
$this->featureToUnit(); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function featureToUnit() |
|
56
|
|
|
{ |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return Parser |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getParser() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->parser; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param Parser $parser |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setParser($parser) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->parser = $parser; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return boolean |
|
77
|
|
|
*/ |
|
78
|
|
|
public function isComponent() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->component; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param boolean $component |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setComponent($component) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->component = $component; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return mixed |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getFeatureContent() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->feature_content; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param mixed $feature_content |
|
101
|
|
|
*/ |
|
102
|
|
|
public function setFeatureContent($feature_content) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->feature_content = $feature_content; |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
private function loadFileContent() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->feature_content = $this->filesystem->get($this->getFullPathToFileAndFileName()); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
private function passThroughParser() |
|
113
|
|
|
{ |
|
114
|
|
|
$this->parsed_feature = $this->getParser()->parse($this->feature_content); |
|
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return \Behat\Gherkin\Node\FeatureNode |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getParsedFeature() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->parsed_feature; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param \Behat\Gherkin\Node\FeatureNode $parsed_feature |
|
127
|
|
|
*/ |
|
128
|
|
|
public function setParsedFeature($parsed_feature) |
|
129
|
|
|
{ |
|
130
|
|
|
$this->parsed_feature = $parsed_feature; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
private function breakIntoMethods() |
|
134
|
|
|
{ |
|
135
|
|
|
//take the parsed content and build out the methods needed for the file |
|
136
|
|
|
//1) the public method to test eg the Scenario |
|
137
|
|
|
// set the name right |
|
138
|
|
|
|
|
139
|
|
|
$this->iterateOverScenariosAndBuildUpClassMethods(); |
|
140
|
|
|
|
|
141
|
|
|
//2) and sub items it has eg the steps |
|
142
|
|
|
// makesure their names are correct |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
private function iterateOverScenariosAndBuildUpClassMethods() |
|
146
|
|
|
{ |
|
147
|
|
|
/** @var $feature \Behat\Gherkin\Node\ScenarioNode */ |
|
148
|
|
|
foreach ($this->parsed_feature->getScenarios() as $scenario_index => $scenario) { |
|
149
|
|
|
$parent_method_name = ucfirst(camel_case($scenario->getTitle())); |
|
150
|
|
|
|
|
151
|
|
|
$this->dusk_class_and_methods[$scenario_index] = [ |
|
152
|
|
|
'parent' => sprintf('test%s', $parent_method_name) |
|
153
|
|
|
]; |
|
154
|
|
|
|
|
155
|
|
|
foreach ($scenario->getSteps() as $step_index => $step) { |
|
156
|
|
|
$method_name = camel_case(sprintf("%s %s", $step->getKeyword(), $step->getText())); |
|
157
|
|
|
$this->dusk_class_and_methods[$scenario_index]['steps'][$step_index] = $method_name; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
private function buildDuskTestName() |
|
163
|
|
|
{ |
|
164
|
|
|
if (!$this->dusk_test_name) { |
|
165
|
|
|
$name = $this->filesystem->name($this->getFullPathToFileAndFileName()); |
|
|
|
|
|
|
166
|
|
|
$this->dusk_test_name = ucfirst(camel_case($name) . 'Test'); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
private function getFullPathToFileAndFileName() |
|
171
|
|
|
{ |
|
172
|
|
|
return getcwd() . DIRECTORY_SEPARATOR . $this->getPathToFeature(); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @return mixed |
|
177
|
|
|
*/ |
|
178
|
|
|
public function getDuskClassAndMethods() |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->dusk_class_and_methods; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param mixed $dusk_class_and_methods |
|
185
|
|
|
*/ |
|
186
|
|
|
public function setDuskClassAndMethods($dusk_class_and_methods) |
|
187
|
|
|
{ |
|
188
|
|
|
$this->dusk_class_and_methods = $dusk_class_and_methods; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @return mixed |
|
193
|
|
|
*/ |
|
194
|
|
|
public function getDuskTestName() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->dusk_test_name; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @param mixed $dusk_test_name |
|
201
|
|
|
*/ |
|
202
|
|
|
public function setDuskTestName($dusk_test_name) |
|
203
|
|
|
{ |
|
204
|
|
|
$this->dusk_test_name = $dusk_test_name; |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..