3 namespace Tests\Behat\Gherkin;
5 use Behat\Gherkin\Node\FeatureNode;
6 use Behat\Gherkin\Lexer;
7 use Behat\Gherkin\Parser;
8 use Behat\Gherkin\Keywords\ArrayKeywords;
9 use Behat\Gherkin\Loader\YamlFileLoader;
11 class ParserTest extends \PHPUnit_Framework_TestCase
16 public function parserTestDataProvider()
20 foreach (glob(__DIR__ . '/Fixtures/etalons/*.yml') as $file) {
21 $testname = basename($file, '.yml');
23 $data[] = array($testname);
30 * @dataProvider parserTestDataProvider
32 * @param string $fixtureName name of the fixture
34 public function testParser($fixtureName)
36 $etalon = $this->parseEtalon($fixtureName . '.yml');
37 $features = $this->parseFixture($fixtureName . '.feature');
39 $this->assertInternalType('array', $features);
40 $this->assertEquals(1, count($features));
41 $fixture = $features[0];
43 $this->assertEquals($etalon, $fixture);
46 public function testParserResetsTagsBetweenFeatures()
48 $parser = $this->getGherkinParser();
50 $parser->parse(<<<FEATURE
57 $feature2 = $parser->parse(<<<FEATURE
64 $this->assertFalse($feature2->hasTags());
67 protected function getGherkinParser()
69 if (null === $this->gherkin) {
70 $keywords = new ArrayKeywords(array(
72 'feature' => 'Feature',
73 'background' => 'Background',
74 'scenario' => 'Scenario',
75 'scenario_outline' => 'Scenario Outline',
76 'examples' => 'Examples',
84 'feature' => 'Функционал',
85 'background' => 'Предыстория',
86 'scenario' => 'Сценарий',
87 'scenario_outline' => 'Структура сценария',
88 'examples' => 'Значения',
89 'given' => 'Допустим',
99 'scenario_outline' => 'シナリオアウトライン',
100 'examples' => '例|サンプル',
108 $this->gherkin = new Parser(new Lexer($keywords));
111 return $this->gherkin;
114 protected function getYamlParser()
116 if (null === $this->yaml) {
117 $this->yaml = new YamlFileLoader();
123 protected function parseFixture($fixture)
125 $file = __DIR__ . '/Fixtures/features/' . $fixture;
127 return array($this->getGherkinParser()->parse(file_get_contents($file), $file));
130 protected function parseEtalon($etalon)
132 $features = $this->getYamlParser()->load(__DIR__ . '/Fixtures/etalons/' . $etalon);
133 $feature = $features[0];
135 return new FeatureNode(
136 $feature->getTitle(),
137 $feature->getDescription(),
139 $feature->getBackground(),
140 $feature->getScenarios(),
141 $feature->getKeyword(),
142 $feature->getLanguage(),
143 __DIR__ . '/Fixtures/features/' . basename($etalon, '.yml') . '.feature',