1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Behat\Gherkin; |
4
|
|
|
|
5
|
|
|
use Behat\Gherkin\Lexer; |
6
|
|
|
use Behat\Gherkin\Parser; |
7
|
|
|
use Behat\Gherkin\Keywords\ArrayKeywords; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class ParserExceptionsTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Parser |
14
|
|
|
*/ |
15
|
|
|
private $gherkin; |
16
|
|
|
|
17
|
|
|
protected function setUp() |
18
|
|
|
{ |
19
|
|
|
$keywords = new ArrayKeywords(array( |
20
|
|
|
'en' => array( |
21
|
|
|
'feature' => 'Feature', |
22
|
|
|
'background' => 'Background', |
23
|
|
|
'scenario' => 'Scenario', |
24
|
|
|
'scenario_outline' => 'Scenario Outline', |
25
|
|
|
'examples' => 'Examples', |
26
|
|
|
'given' => 'Given', |
27
|
|
|
'when' => 'When', |
28
|
|
|
'then' => 'Then', |
29
|
|
|
'and' => 'And', |
30
|
|
|
'but' => 'But' |
31
|
|
|
), |
32
|
|
|
'ru' => array( |
33
|
|
|
'feature' => 'Функционал', |
34
|
|
|
'background' => 'Предыстория', |
35
|
|
|
'scenario' => 'Сценарий', |
36
|
|
|
'scenario_outline' => 'Структура сценария', |
37
|
|
|
'examples' => 'Примеры', |
38
|
|
|
'given' => 'Допустим', |
39
|
|
|
'when' => 'То', |
40
|
|
|
'then' => 'Если', |
41
|
|
|
'and' => 'И', |
42
|
|
|
'but' => 'Но' |
43
|
|
|
) |
44
|
|
|
)); |
45
|
|
|
$this->gherkin = new Parser(new Lexer($keywords)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testStepRightAfterFeature() |
49
|
|
|
{ |
50
|
|
|
$feature = <<<GHERKIN |
51
|
|
|
Feature: Some feature |
52
|
|
|
|
53
|
|
|
Given some step-like line |
54
|
|
|
GHERKIN; |
55
|
|
|
|
56
|
|
|
$parsed = $this->gherkin->parse($feature); |
57
|
|
|
|
58
|
|
|
$this->assertEquals("\n Given some step-like line", $parsed->getDescription()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testTextInBackground() |
62
|
|
|
{ |
63
|
|
|
$feature = <<<GHERKIN |
64
|
|
|
Feature: Behat bug test |
65
|
|
|
Background: remove X to couse bug |
66
|
|
|
Step is red form is not valid |
67
|
|
|
asd |
68
|
|
|
asd |
69
|
|
|
as |
70
|
|
|
da |
71
|
|
|
sd |
72
|
|
|
as |
73
|
|
|
das |
74
|
|
|
d |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
Scenario: bug user edit date |
78
|
|
|
GHERKIN; |
79
|
|
|
|
80
|
|
|
$feature = $this->gherkin->parse($feature); |
81
|
|
|
$background = $feature->getBackground(); |
82
|
|
|
$this->assertEquals( |
83
|
|
|
"remove X to couse bug\nStep is red form is not valid\nasd\nasd\nas\nda\nsd\nas\ndas\nd", |
84
|
|
|
$background->getTitle() |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testTextInScenario() |
89
|
|
|
{ |
90
|
|
|
$feature = <<<GHERKIN |
91
|
|
|
Feature: Behat bug test |
92
|
|
|
Scenario: remove X to cause bug |
93
|
|
|
Step is red form is not valid |
94
|
|
|
asd |
95
|
|
|
asd |
96
|
|
|
as |
97
|
|
|
da |
98
|
|
|
sd |
99
|
|
|
as |
100
|
|
|
das |
101
|
|
|
d |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
Scenario Outline: bug user edit date |
105
|
|
|
Step is red form is not valid |
106
|
|
|
asd |
107
|
|
|
asd |
108
|
|
|
as |
109
|
|
|
da |
110
|
|
|
sd |
111
|
|
|
as |
112
|
|
|
das |
113
|
|
|
d |
114
|
|
|
Examples: |
115
|
|
|
|| |
116
|
|
|
|
117
|
|
|
GHERKIN; |
118
|
|
|
|
119
|
|
|
$feature = $this->gherkin->parse($feature); |
120
|
|
|
|
121
|
|
|
$this->assertCount(2, $scenarios = $feature->getScenarios()); |
122
|
|
|
$firstTitle = <<<TEXT |
123
|
|
|
remove X to cause bug |
124
|
|
|
Step is red form is not valid |
125
|
|
|
asd |
126
|
|
|
asd |
127
|
|
|
as |
128
|
|
|
da |
129
|
|
|
sd |
130
|
|
|
as |
131
|
|
|
das |
132
|
|
|
d |
133
|
|
|
TEXT; |
134
|
|
|
$this->assertEquals($firstTitle, $scenarios[0]->getTitle()); |
135
|
|
|
$secondTitle = <<<TEXT |
136
|
|
|
bug user edit date |
137
|
|
|
Step is red form is not valid |
138
|
|
|
asd |
139
|
|
|
asd |
140
|
|
|
as |
141
|
|
|
da |
142
|
|
|
sd |
143
|
|
|
as |
144
|
|
|
das |
145
|
|
|
d |
146
|
|
|
TEXT; |
147
|
|
|
$this->assertEquals($secondTitle, $scenarios[1]->getTitle()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @expectedException \Behat\Gherkin\Exception\ParserException |
152
|
|
|
*/ |
153
|
|
|
public function testAmbigiousLanguage() |
154
|
|
|
{ |
155
|
|
|
$feature = <<<GHERKIN |
156
|
|
|
# language: en |
157
|
|
|
|
158
|
|
|
# language: ru |
159
|
|
|
|
160
|
|
|
Feature: Some feature |
161
|
|
|
|
162
|
|
|
Given something wrong |
163
|
|
|
GHERKIN; |
164
|
|
|
|
165
|
|
|
$this->gherkin->parse($feature); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @expectedException \Behat\Gherkin\Exception\ParserException |
170
|
|
|
*/ |
171
|
|
|
public function testEmptyOutline() |
172
|
|
|
{ |
173
|
|
|
$feature = <<<GHERKIN |
174
|
|
|
Feature: Some feature |
175
|
|
|
|
176
|
|
|
Scenario Outline: |
177
|
|
|
GHERKIN; |
178
|
|
|
|
179
|
|
|
$this->gherkin->parse($feature); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @expectedException \Behat\Gherkin\Exception\ParserException |
184
|
|
|
*/ |
185
|
|
|
public function testWrongTagPlacement() |
186
|
|
|
{ |
187
|
|
|
$feature = <<<GHERKIN |
188
|
|
|
Feature: Some feature |
189
|
|
|
|
190
|
|
|
Scenario: |
191
|
|
|
Given some step |
192
|
|
|
@some_tag |
193
|
|
|
Then some additional step |
194
|
|
|
GHERKIN; |
195
|
|
|
|
196
|
|
|
$this->gherkin->parse($feature); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @expectedException \Behat\Gherkin\Exception\ParserException |
201
|
|
|
*/ |
202
|
|
|
public function testBackgroundWithTag() |
203
|
|
|
{ |
204
|
|
|
$feature = <<<GHERKIN |
205
|
|
|
Feature: Some feature |
206
|
|
|
|
207
|
|
|
@some_tag |
208
|
|
|
Background: |
209
|
|
|
Given some step |
210
|
|
|
GHERKIN; |
211
|
|
|
|
212
|
|
|
$this->gherkin->parse($feature); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @expectedException \Behat\Gherkin\Exception\ParserException |
217
|
|
|
*/ |
218
|
|
|
public function testEndlessPyString() |
219
|
|
|
{ |
220
|
|
|
$feature = <<<GHERKIN |
221
|
|
|
Feature: |
222
|
|
|
|
223
|
|
|
Scenario: |
224
|
|
|
Given something with: |
225
|
|
|
""" |
226
|
|
|
some text |
227
|
|
|
GHERKIN; |
228
|
|
|
|
229
|
|
|
$this->gherkin->parse($feature); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @expectedException \Behat\Gherkin\Exception\ParserException |
234
|
|
|
*/ |
235
|
|
|
public function testWrongStepType() |
236
|
|
|
{ |
237
|
|
|
$feature = <<<GHERKIN |
238
|
|
|
Feature: |
239
|
|
|
|
240
|
|
|
Scenario: |
241
|
|
|
Given some step |
242
|
|
|
|
243
|
|
|
Aaand some step |
244
|
|
|
GHERKIN; |
245
|
|
|
|
246
|
|
|
$this->gherkin->parse($feature); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @expectedException \Behat\Gherkin\Exception\ParserException |
251
|
|
|
*/ |
252
|
|
|
public function testMultipleBackgrounds() |
253
|
|
|
{ |
254
|
|
|
$feature = <<<GHERKIN |
255
|
|
|
Feature: |
256
|
|
|
|
257
|
|
|
Background: |
258
|
|
|
Given some step |
259
|
|
|
|
260
|
|
|
Background: |
261
|
|
|
Aaand some step |
262
|
|
|
GHERKIN; |
263
|
|
|
|
264
|
|
|
$this->gherkin->parse($feature); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @expectedException \Behat\Gherkin\Exception\ParserException |
269
|
|
|
*/ |
270
|
|
|
public function testMultipleFeatures() |
271
|
|
|
{ |
272
|
|
|
$feature = <<<GHERKIN |
273
|
|
|
Feature: |
274
|
|
|
|
275
|
|
|
Feature: |
276
|
|
|
GHERKIN; |
277
|
|
|
|
278
|
|
|
$this->gherkin->parse($feature); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @expectedException \Behat\Gherkin\Exception\ParserException |
283
|
|
|
*/ |
284
|
|
|
public function testTableWithoutRightBorder() |
285
|
|
|
{ |
286
|
|
|
$feature = <<<GHERKIN |
287
|
|
|
Feature: |
288
|
|
|
|
289
|
|
|
Scenario: |
290
|
|
|
Given something with: |
291
|
|
|
| foo | bar |
292
|
|
|
| 42 | 42 |
293
|
|
|
GHERKIN; |
294
|
|
|
|
295
|
|
|
$this->gherkin->parse($feature); |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
|