|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Behat Gherkin. |
|
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\Gherkin\Node; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Represents Gherkin Feature. |
|
15
|
|
|
* |
|
16
|
|
|
* @author Konstantin Kudryashov <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class FeatureNode implements KeywordNodeInterface, TaggedNodeInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var null|string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $title; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var null|string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $description; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var string[] |
|
30
|
|
|
*/ |
|
31
|
|
|
private $tags = array(); |
|
32
|
|
|
/** |
|
33
|
|
|
* @var null|BackgroundNode |
|
34
|
|
|
*/ |
|
35
|
|
|
private $background; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var ScenarioInterface[] |
|
38
|
|
|
*/ |
|
39
|
|
|
private $scenarios = array(); |
|
40
|
|
|
/** |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
private $keyword; |
|
44
|
|
|
/** |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
private $language; |
|
48
|
|
|
/** |
|
49
|
|
|
* @var null|string |
|
50
|
|
|
*/ |
|
51
|
|
|
private $file; |
|
52
|
|
|
/** |
|
53
|
|
|
* @var integer |
|
54
|
|
|
*/ |
|
55
|
|
|
private $line; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Initializes feature. |
|
59
|
|
|
* |
|
60
|
|
|
* @param null|string $title |
|
61
|
|
|
* @param null|string $description |
|
62
|
|
|
* @param string[] $tags |
|
63
|
|
|
* @param null|BackgroundNode $background |
|
64
|
|
|
* @param ScenarioInterface[] $scenarios |
|
65
|
|
|
* @param string $keyword |
|
66
|
|
|
* @param string $language |
|
67
|
|
|
* @param null|string $file The absolute path to the feature file. |
|
68
|
|
|
* @param integer $line |
|
69
|
|
|
*/ |
|
70
|
271 |
|
public function __construct( |
|
71
|
|
|
$title, |
|
72
|
|
|
$description, |
|
73
|
|
|
array $tags, |
|
74
|
|
|
BackgroundNode $background = null, |
|
75
|
|
|
array $scenarios, |
|
76
|
|
|
$keyword, |
|
77
|
|
|
$language, |
|
78
|
|
|
$file, |
|
79
|
|
|
$line |
|
80
|
|
|
) { |
|
81
|
|
|
// Verify that the feature file is an absolute path. |
|
82
|
271 |
|
if (!empty($file) && !$this->isAbsolutePath($file)) { |
|
83
|
|
|
throw new \InvalidArgumentException('The file should be an absolute path.'); |
|
84
|
|
|
} |
|
85
|
271 |
|
$this->title = $title; |
|
86
|
271 |
|
$this->description = $description; |
|
87
|
271 |
|
$this->tags = $tags; |
|
88
|
271 |
|
$this->background = $background; |
|
89
|
271 |
|
$this->scenarios = $scenarios; |
|
90
|
271 |
|
$this->keyword = $keyword; |
|
91
|
271 |
|
$this->language = $language; |
|
92
|
271 |
|
$this->file = $file; |
|
93
|
271 |
|
$this->line = $line; |
|
94
|
271 |
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Returns node type string |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
1 |
|
public function getNodeType() |
|
102
|
|
|
{ |
|
103
|
1 |
|
return 'Feature'; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Returns feature title. |
|
108
|
|
|
* |
|
109
|
|
|
* @return null|string |
|
110
|
|
|
*/ |
|
111
|
47 |
|
public function getTitle() |
|
112
|
|
|
{ |
|
113
|
47 |
|
return $this->title; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Checks if feature has a description. |
|
118
|
|
|
* |
|
119
|
|
|
* @return Boolean |
|
120
|
|
|
*/ |
|
121
|
|
|
public function hasDescription() |
|
122
|
|
|
{ |
|
123
|
|
|
return !empty($this->description); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Returns feature description. |
|
128
|
|
|
* |
|
129
|
|
|
* @return null|string |
|
130
|
|
|
*/ |
|
131
|
47 |
|
public function getDescription() |
|
132
|
|
|
{ |
|
133
|
47 |
|
return $this->description; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Checks if feature is tagged with tag. |
|
138
|
|
|
* |
|
139
|
|
|
* @param string $tag |
|
140
|
|
|
* |
|
141
|
|
|
* @return Boolean |
|
142
|
|
|
*/ |
|
143
|
|
|
public function hasTag($tag) |
|
144
|
|
|
{ |
|
145
|
|
|
return in_array($tag, $this->tags); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Checks if feature has tags. |
|
150
|
|
|
* |
|
151
|
|
|
* @return Boolean |
|
152
|
|
|
*/ |
|
153
|
2 |
|
public function hasTags() |
|
154
|
|
|
{ |
|
155
|
2 |
|
return 0 < count($this->tags); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Returns feature tags. |
|
160
|
|
|
* |
|
161
|
|
|
* @return string[] |
|
162
|
|
|
*/ |
|
163
|
45 |
|
public function getTags() |
|
164
|
|
|
{ |
|
165
|
45 |
|
return $this->tags; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Checks if feature has background. |
|
170
|
|
|
* |
|
171
|
|
|
* @return Boolean |
|
172
|
|
|
*/ |
|
173
|
1 |
|
public function hasBackground() |
|
174
|
|
|
{ |
|
175
|
1 |
|
return null !== $this->background; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Returns feature background. |
|
180
|
|
|
* |
|
181
|
|
|
* @return null|BackgroundNode |
|
182
|
|
|
*/ |
|
183
|
46 |
|
public function getBackground() |
|
184
|
|
|
{ |
|
185
|
46 |
|
return $this->background; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Checks if feature has scenarios. |
|
190
|
|
|
* |
|
191
|
|
|
* @return Boolean |
|
192
|
|
|
*/ |
|
193
|
2 |
|
public function hasScenarios() |
|
194
|
|
|
{ |
|
195
|
2 |
|
return 0 < count($this->scenarios); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Returns feature scenarios. |
|
200
|
|
|
* |
|
201
|
|
|
* @return ScenarioInterface[] |
|
202
|
|
|
*/ |
|
203
|
49 |
|
public function getScenarios() |
|
204
|
|
|
{ |
|
205
|
49 |
|
return $this->scenarios; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* Returns feature keyword. |
|
210
|
|
|
* |
|
211
|
|
|
* @return string |
|
212
|
|
|
*/ |
|
213
|
42 |
|
public function getKeyword() |
|
214
|
|
|
{ |
|
215
|
42 |
|
return $this->keyword; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Returns feature language. |
|
220
|
|
|
* |
|
221
|
|
|
* @return string |
|
222
|
|
|
*/ |
|
223
|
43 |
|
public function getLanguage() |
|
224
|
|
|
{ |
|
225
|
43 |
|
return $this->language; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Returns feature file as an absolute path. |
|
230
|
|
|
* |
|
231
|
|
|
* @return null|string |
|
232
|
|
|
*/ |
|
233
|
14 |
|
public function getFile() |
|
234
|
|
|
{ |
|
235
|
14 |
|
return $this->file; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Returns feature declaration line number. |
|
240
|
|
|
* |
|
241
|
|
|
* @return integer |
|
242
|
|
|
*/ |
|
243
|
50 |
|
public function getLine() |
|
244
|
|
|
{ |
|
245
|
50 |
|
return $this->line; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Returns whether the file path is an absolute path. |
|
250
|
|
|
* |
|
251
|
|
|
* @param string $file A file path |
|
252
|
|
|
* |
|
253
|
|
|
* @return bool |
|
254
|
|
|
* |
|
255
|
|
|
* @see https://github.com/symfony/filesystem/blob/master/Filesystem.php |
|
256
|
|
|
*/ |
|
257
|
229 |
|
protected function isAbsolutePath($file) |
|
258
|
|
|
{ |
|
259
|
229 |
|
if (null === $file) { |
|
260
|
|
|
@trigger_error(sprintf('Calling "%s()" with a null in the $file argument is deprecated since Symfony 4.4.', __METHOD__), E_USER_DEPRECATED); |
|
|
|
|
|
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
229 |
|
return strspn($file, '/\\', 0, 1) |
|
264
|
|
|
|| (\strlen($file) > 3 && ctype_alpha($file[0]) |
|
265
|
|
|
&& ':' === $file[1] |
|
266
|
|
|
&& strspn($file, '/\\', 2, 1) |
|
267
|
|
|
) |
|
268
|
229 |
|
|| null !== parse_url($file, PHP_URL_SCHEME) |
|
269
|
|
|
; |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: