1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace GD; |
5
|
|
|
|
6
|
|
|
use Behat\Gherkin\Parser; |
7
|
|
|
use Illuminate\Filesystem\Filesystem; |
8
|
|
|
use Silly\Edition\Pimple\Application; |
9
|
|
|
|
10
|
|
|
class BaseGherkinToDusk |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
protected $features_folder = '/tests/features/'; |
14
|
|
|
|
15
|
|
|
protected $source_path = null; |
16
|
|
|
|
17
|
|
|
protected $context = "domain"; |
18
|
|
|
|
19
|
|
|
protected $path_to_feature = null; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
protected $dusk_test_name; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Conventions |
26
|
|
|
* file should be in tests/features for now |
27
|
|
|
* @var null |
28
|
|
|
*/ |
29
|
|
|
protected $file_name = null; |
30
|
|
|
|
31
|
|
|
protected $file_name_and_path = null; |
32
|
|
|
|
33
|
|
|
protected $destination_folder_root = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Filesystem |
37
|
|
|
*/ |
38
|
|
|
protected $filesystem; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var Parser |
42
|
|
|
*/ |
43
|
|
|
protected $parser; |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
protected $output; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var Application |
50
|
|
|
*/ |
51
|
|
|
protected $app; |
52
|
|
|
|
53
|
75 |
|
public function __construct(Application $app) |
54
|
|
|
{ |
55
|
75 |
|
$this->app = $app; |
56
|
|
|
|
57
|
75 |
|
$this->filesystem = $this->app->getContainer()['filesystem']; |
58
|
|
|
|
59
|
75 |
|
$this->parser = $this->app->getContainer()['parser']; |
60
|
75 |
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function getFileName() |
64
|
|
|
{ |
65
|
|
|
return $this->file_name; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setFileName($file_name) |
69
|
|
|
{ |
70
|
|
|
$this->file_name = $file_name; |
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return Filesystem |
76
|
|
|
*/ |
77
|
57 |
|
public function getFilesystem() |
78
|
|
|
{ |
79
|
57 |
|
return $this->filesystem; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param null $filesystem |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function setFilesystem($filesystem = null) |
87
|
|
|
{ |
88
|
|
|
|
89
|
|
|
if (!$filesystem) { |
90
|
|
|
$filesystem = new Filesystem(); |
91
|
|
|
} |
92
|
|
|
$this->filesystem = $filesystem; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return null |
98
|
|
|
*/ |
99
|
|
|
public function getFileNameAndPath() |
100
|
|
|
{ |
101
|
|
|
if ($this->file_name_and_path == null) { |
102
|
|
|
$this->setFileNameAndPath(); |
103
|
|
|
} |
104
|
|
|
return $this->file_name_and_path; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param null $file_name_and_path |
109
|
|
|
* @return $this |
110
|
|
|
*/ |
111
|
|
|
public function setFileNameAndPath($file_name_and_path = null) |
112
|
|
|
{ |
113
|
|
|
if (!$file_name_and_path) { |
114
|
|
|
$file_name_and_path = |
115
|
|
|
$this->getSourcePath() . $this->features_folder . $this->getFileName(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$this->file_name_and_path = $file_name_and_path; |
119
|
|
|
|
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return null |
127
|
|
|
*/ |
128
|
63 |
|
public function getSourcePath() |
129
|
|
|
{ |
130
|
63 |
|
if ($this->source_path == null) { |
131
|
63 |
|
$this->setSourcePath(); |
132
|
42 |
|
} |
133
|
63 |
|
return $this->source_path; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param null $source_path |
138
|
|
|
*/ |
139
|
63 |
|
public function setSourcePath($source_path = null) |
140
|
|
|
{ |
141
|
63 |
|
if (!$source_path) { |
142
|
63 |
|
$source_path = getcwd() . '/tests/features/'; |
143
|
42 |
|
} |
144
|
|
|
|
145
|
63 |
|
$this->source_path = $source_path; |
146
|
63 |
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return null |
150
|
|
|
*/ |
151
|
69 |
|
public function getDestinationFolderRoot() |
152
|
|
|
{ |
153
|
69 |
|
if (!$this->destination_folder_root) { |
154
|
69 |
|
$this->setDestinationFolderRoot(); |
155
|
46 |
|
} |
156
|
69 |
|
return $this->destination_folder_root; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param null $destination_folder_root |
161
|
|
|
*/ |
162
|
69 |
|
public function setDestinationFolderRoot($destination_folder_root = null) |
163
|
|
|
{ |
164
|
69 |
|
if (!$destination_folder_root) { |
165
|
69 |
|
$destination_folder_root = getcwd() . sprintf('/tests/%s', $this->getContextFolder()); |
166
|
46 |
|
} |
167
|
|
|
|
168
|
69 |
|
$this->destination_folder_root = $destination_folder_root; |
169
|
69 |
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function getContext() |
175
|
|
|
{ |
176
|
|
|
return $this->context; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $context |
181
|
|
|
* @return $this |
182
|
|
|
*/ |
183
|
63 |
|
public function setContext($context) |
184
|
|
|
{ |
185
|
63 |
|
$this->context = $context; |
186
|
63 |
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return Parser |
191
|
|
|
*/ |
192
|
54 |
|
public function getParser() |
193
|
|
|
{ |
194
|
54 |
|
return $this->parser; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param Parser $parser |
199
|
|
|
*/ |
200
|
|
|
public function setParser($parser) |
201
|
|
|
{ |
202
|
|
|
$this->parser = $parser; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return null |
208
|
|
|
*/ |
209
|
57 |
|
public function getPathToFeature() |
210
|
|
|
{ |
211
|
57 |
|
return $this->path_to_feature; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param null $path_to_feature |
216
|
|
|
* @return $this |
217
|
|
|
*/ |
218
|
57 |
|
public function setPathToFeature($path_to_feature) |
219
|
|
|
{ |
220
|
57 |
|
$this->path_to_feature = $path_to_feature; |
221
|
57 |
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
33 |
|
public function fullPathToDestinationFile() |
225
|
|
|
{ |
226
|
33 |
|
return $this->getDestinationFolderRoot() . '/' . $this->getDuskTestName() . '.php'; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
57 |
|
protected function buildDuskTestName() |
231
|
|
|
{ |
232
|
57 |
|
if (!$this->dusk_test_name) { |
233
|
57 |
|
$name = $this->getFilesystem()->name($this->getFullPathToFileAndFileName()); |
234
|
57 |
|
$this->dusk_test_name = ucfirst(camel_case($name) . 'Test'); |
235
|
38 |
|
} |
236
|
57 |
|
} |
237
|
|
|
|
238
|
57 |
|
protected function getFullPathToFileAndFileName() |
239
|
|
|
{ |
240
|
57 |
|
return getcwd() . DIRECTORY_SEPARATOR . $this->getPathToFeature(); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return mixed |
245
|
|
|
*/ |
246
|
57 |
|
public function getDuskTestName() |
247
|
|
|
{ |
248
|
57 |
|
return $this->dusk_test_name; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param mixed $dusk_test_name |
253
|
|
|
*/ |
254
|
|
|
public function setDuskTestName($dusk_test_name) |
255
|
|
|
{ |
256
|
|
|
$this->dusk_test_name = $dusk_test_name; |
257
|
|
|
} |
258
|
|
|
|
259
|
69 |
|
private function getContextFolder() |
260
|
|
|
{ |
261
|
69 |
|
switch ($this->context) { |
262
|
69 |
|
case "domain": |
263
|
48 |
|
return "Feature"; |
264
|
21 |
|
case "ui": |
265
|
21 |
|
case "browser": |
266
|
21 |
|
return "Browser"; |
267
|
|
|
default: |
268
|
|
|
return "Feature"; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
|