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 GD\Helpers\BuildOutContent; |
13
|
|
|
use Illuminate\Filesystem\Filesystem; |
14
|
|
|
use Symfony\Component\Yaml\Yaml; |
15
|
|
|
|
16
|
|
|
class GherkinToDusk extends BaseGherkinToDusk |
17
|
|
|
{ |
18
|
|
|
use BuildOutContent; |
19
|
|
|
|
20
|
|
|
protected $component = false; |
21
|
|
|
|
22
|
|
|
protected $string_contents = null; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Yml Content of a test yml |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $feature_content; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \Behat\Gherkin\Node\FeatureNode |
32
|
|
|
*/ |
33
|
|
|
protected $parsed_feature; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
*/ |
38
|
|
|
protected $dusk_class_and_methods; |
39
|
|
|
|
40
|
|
|
protected $dusk_test_name; |
41
|
|
|
|
42
|
12 |
|
public function initializeFeature() |
43
|
|
|
{ |
44
|
12 |
|
$this->loadFileContent(); |
45
|
|
|
|
46
|
12 |
|
$this->buildDuskTestName(); |
47
|
|
|
|
48
|
12 |
|
$this->passThroughParser(); |
49
|
|
|
|
50
|
12 |
|
$this->breakIntoMethods(); |
51
|
|
|
|
52
|
12 |
|
if ($this->context == 'domain') { |
53
|
12 |
|
$this->featureToUnit(); |
54
|
8 |
|
} |
55
|
12 |
|
} |
56
|
|
|
|
57
|
12 |
|
protected function featureToUnit() |
58
|
|
|
{ |
59
|
12 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return Parser |
63
|
|
|
*/ |
64
|
15 |
|
public function getParser() |
65
|
|
|
{ |
66
|
15 |
|
return $this->parser; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param Parser $parser |
71
|
|
|
*/ |
72
|
|
|
public function setParser($parser) |
73
|
|
|
{ |
74
|
|
|
$this->parser = $parser; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return boolean |
79
|
|
|
*/ |
80
|
|
|
public function isComponent() |
81
|
|
|
{ |
82
|
|
|
return $this->component; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param boolean $component |
87
|
|
|
*/ |
88
|
|
|
public function setComponent($component) |
89
|
|
|
{ |
90
|
|
|
$this->component = $component; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return mixed |
95
|
|
|
*/ |
96
|
3 |
|
public function getFeatureContent() |
97
|
|
|
{ |
98
|
3 |
|
return $this->feature_content; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param mixed $feature_content |
103
|
|
|
*/ |
104
|
|
|
public function setFeatureContent($feature_content) |
105
|
|
|
{ |
106
|
|
|
$this->feature_content = $feature_content; |
107
|
|
|
} |
108
|
|
|
|
109
|
12 |
|
private function loadFileContent() |
110
|
|
|
{ |
111
|
12 |
|
$this->feature_content = $this->getFilesystem()->get($this->getFullPathToFileAndFileName()); |
112
|
12 |
|
} |
113
|
|
|
|
114
|
12 |
|
private function passThroughParser() |
115
|
|
|
{ |
116
|
12 |
|
$this->parsed_feature = $this->getParser()->parse($this->feature_content); |
117
|
12 |
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return \Behat\Gherkin\Node\FeatureNode |
121
|
|
|
*/ |
122
|
3 |
|
public function getParsedFeature() |
123
|
|
|
{ |
124
|
3 |
|
return $this->parsed_feature; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param \Behat\Gherkin\Node\FeatureNode $parsed_feature |
129
|
|
|
*/ |
130
|
|
|
public function setParsedFeature($parsed_feature) |
131
|
|
|
{ |
132
|
|
|
$this->parsed_feature = $parsed_feature; |
133
|
|
|
} |
134
|
|
|
|
135
|
12 |
|
private function breakIntoMethods() |
136
|
|
|
{ |
137
|
12 |
|
$this->iterateOverScenariosAndBuildUpClassMethods(); |
138
|
12 |
|
} |
139
|
|
|
|
140
|
12 |
|
private function iterateOverScenariosAndBuildUpClassMethods() |
141
|
|
|
{ |
142
|
|
|
/** @var $feature \Behat\Gherkin\Node\ScenarioNode */ |
143
|
12 |
|
foreach ($this->parsed_feature->getScenarios() as $scenario_index => $scenario) { |
144
|
12 |
|
$parent_method_name = ucfirst(camel_case($scenario->getTitle())); |
145
|
|
|
|
146
|
12 |
|
$parent_method_name_camelized_and_prefix_test = sprintf('test%s', $parent_method_name); |
147
|
|
|
|
148
|
12 |
|
$this->dusk_class_and_methods[$scenario_index] = [ |
149
|
12 |
|
'parent' => $parent_method_name_camelized_and_prefix_test, |
150
|
12 |
|
'parent_content' => $this->getParentLevelContent($parent_method_name_camelized_and_prefix_test) |
151
|
8 |
|
]; |
152
|
|
|
|
153
|
12 |
|
$this->buildOutSteps($scenario, $scenario_index); |
154
|
8 |
|
} |
155
|
12 |
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param $scenario \Behat\Gherkin\Node\ScenarioNode |
159
|
|
|
*/ |
160
|
12 |
|
protected function buildOutSteps($scenario, $scenario_index) { |
161
|
12 |
|
foreach ($scenario->getSteps() as $step_index => $step) { |
162
|
12 |
|
$method_name = camel_case(sprintf("%s %s", $step->getKeyword(), $step->getText())); |
163
|
12 |
|
$step_method_name_camalized = camel_case(sprintf("%s %s", $step->getKeyword(), $step->getText())); |
164
|
12 |
|
$this->dusk_class_and_methods[$scenario_index]['steps'][$step_index]['name'] = |
165
|
|
|
$method_name; |
166
|
12 |
|
$this->dusk_class_and_methods[$scenario_index]['steps'][$step_index] = |
167
|
12 |
|
$this->getStepLevelContent($step_method_name_camalized); |
168
|
8 |
|
} |
169
|
12 |
|
} |
170
|
|
|
|
171
|
12 |
|
private function buildDuskTestName() |
172
|
|
|
{ |
173
|
12 |
|
if (!$this->dusk_test_name) { |
174
|
12 |
|
$name = $this->getFilesystem()->name($this->getFullPathToFileAndFileName()); |
175
|
12 |
|
$this->dusk_test_name = ucfirst(camel_case($name) . 'Test'); |
176
|
8 |
|
} |
177
|
12 |
|
} |
178
|
|
|
|
179
|
12 |
|
private function getFullPathToFileAndFileName() |
180
|
|
|
{ |
181
|
12 |
|
return getcwd() . DIRECTORY_SEPARATOR . $this->getPathToFeature(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return mixed |
186
|
|
|
*/ |
187
|
6 |
|
public function getDuskClassAndMethods() |
188
|
|
|
{ |
189
|
6 |
|
return $this->dusk_class_and_methods; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param mixed $dusk_class_and_methods |
194
|
|
|
*/ |
195
|
|
|
public function setDuskClassAndMethods($dusk_class_and_methods) |
196
|
|
|
{ |
197
|
|
|
$this->dusk_class_and_methods = $dusk_class_and_methods; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return mixed |
202
|
|
|
*/ |
203
|
3 |
|
public function getDuskTestName() |
204
|
|
|
{ |
205
|
3 |
|
return $this->dusk_test_name; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param mixed $dusk_test_name |
210
|
|
|
*/ |
211
|
|
|
public function setDuskTestName($dusk_test_name) |
212
|
|
|
{ |
213
|
|
|
$this->dusk_test_name = $dusk_test_name; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|