Completed
Pull Request — master (#112)
by Christophe
02:45
created

ParserExceptionsTest::testEmptyOutline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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