3 namespace Tests\Behat\Gherkin;
5 use Behat\Gherkin\Lexer;
6 use Behat\Gherkin\Parser;
7 use Behat\Gherkin\Keywords\ArrayKeywords;
9 class ParserExceptionsTest extends \PHPUnit_Framework_TestCase
16 protected function setUp()
18 $keywords = new ArrayKeywords(array(
20 'feature' => 'Feature',
21 'background' => 'Background',
22 'scenario' => 'Scenario',
23 'scenario_outline' => 'Scenario Outline',
24 'examples' => 'Examples',
32 'feature' => 'Функционал',
33 'background' => 'Предыстория',
34 'scenario' => 'Сценарий',
35 'scenario_outline' => 'Структура сценария',
36 'examples' => 'Значения',
37 'given' => 'Допустим',
44 $this->gherkin = new Parser(new Lexer($keywords));
47 public function testStepRightAfterFeature()
52 Given some step-like line
55 $parsed = $this->gherkin->parse($feature);
57 $this->assertEquals("\n Given some step-like line", $parsed->getDescription());
60 public function testTextInBackground()
63 Feature: Behat bug test
64 Background: remove X to couse bug
65 Step is red form is not valid
76 Scenario: bug user edit date
79 $this->gherkin->parse($feature);
82 public function testTextInScenario()
85 Feature: Behat bug test
86 Scenario: remove X to cause bug
87 Step is red form is not valid
98 Scenario Outline: bug user edit date
99 Step is red form is not valid
113 $feature = $this->gherkin->parse($feature);
115 $this->assertCount(2, $scenarios = $feature->getScenarios());
116 $firstTitle = <<<TEXT
117 remove X to cause bug
118 Step is red form is not valid
128 $this->assertEquals($firstTitle, $scenarios[0]->getTitle());
129 $secondTitle = <<<TEXT
131 Step is red form is not valid
141 $this->assertEquals($secondTitle, $scenarios[1]->getTitle());
145 * @expectedException \Behat\Gherkin\Exception\ParserException
147 public function testAmbigiousLanguage()
149 $feature = <<<GHERKIN
154 Feature: Some feature
156 Given something wrong
159 $this->gherkin->parse($feature);
163 * @expectedException \Behat\Gherkin\Exception\ParserException
165 public function testEmptyOutline()
167 $feature = <<<GHERKIN
168 Feature: Some feature
173 $this->gherkin->parse($feature);
177 * @expectedException \Behat\Gherkin\Exception\ParserException
179 public function testWrongTagPlacement()
181 $feature = <<<GHERKIN
182 Feature: Some feature
187 Then some additional step
190 $this->gherkin->parse($feature);
194 * @expectedException \Behat\Gherkin\Exception\ParserException
196 public function testBackgroundWithTag()
198 $feature = <<<GHERKIN
199 Feature: Some feature
206 $this->gherkin->parse($feature);
210 * @expectedException \Behat\Gherkin\Exception\ParserException
212 public function testEndlessPyString()
214 $feature = <<<GHERKIN
218 Given something with:
223 $this->gherkin->parse($feature);
227 * @expectedException \Behat\Gherkin\Exception\ParserException
229 public function testWrongStepType()
231 $feature = <<<GHERKIN
240 $this->gherkin->parse($feature);
244 * @expectedException \Behat\Gherkin\Exception\ParserException
246 public function testMultipleBackgrounds()
248 $feature = <<<GHERKIN
258 $this->gherkin->parse($feature);
262 * @expectedException \Behat\Gherkin\Exception\ParserException
264 public function testMultipleFeatures()
266 $feature = <<<GHERKIN
272 $this->gherkin->parse($feature);
276 * @expectedException \Behat\Gherkin\Exception\ParserException
278 public function testTableWithoutRightBorder()
280 $feature = <<<GHERKIN
284 Given something with:
289 $this->gherkin->parse($feature);