Skip to content

Commit 618b7ce

Browse files
committed
Add a test covering the DialectKeywords implementation
Code coverage does not count code executed in data providers as being covered.
1 parent 6d0ac5e commit 618b7ce

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Behat Gherkin Parser.
5+
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
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 Tests\Behat\Gherkin\Keywords;
12+
13+
use Behat\Gherkin\Dialect\CucumberDialectProvider;
14+
use Behat\Gherkin\Keywords\DialectKeywords;
15+
use Behat\Gherkin\Keywords\KeywordsInterface;
16+
use Behat\Gherkin\Node\StepNode;
17+
use Tests\Behat\Gherkin\Filesystem;
18+
19+
class DialectKeywordsTest extends KeywordsTestCase
20+
{
21+
public function testFailsForEmptyLanguage(): void
22+
{
23+
$keywords = new DialectKeywords(new CucumberDialectProvider());
24+
25+
$this->expectException(\LogicException::class);
26+
$this->expectExceptionMessage('Language cannot be empty');
27+
28+
$keywords->setLanguage('');
29+
}
30+
31+
protected static function getKeywords(): KeywordsInterface
32+
{
33+
return new DialectKeywords(new CucumberDialectProvider());
34+
}
35+
36+
protected static function getKeywordsArray(): array
37+
{
38+
$data = json_decode(Filesystem::readFile(__DIR__ . '/../../resources/gherkin-languages.json'), true, flags: \JSON_THROW_ON_ERROR);
39+
40+
$keywordsArray = [];
41+
42+
foreach ($data as $lang => $dialect) {
43+
$keywordsArray[$lang] = [
44+
'feature' => implode('|', $dialect['feature']),
45+
'background' => implode('|', $dialect['background']),
46+
'scenario' => implode('|', $dialect['scenario']),
47+
'scenario_outline' => implode('|', $dialect['scenarioOutline']),
48+
'examples' => implode('|', $dialect['examples']),
49+
'given' => implode('|', $dialect['given']),
50+
'when' => implode('|', $dialect['when']),
51+
'then' => implode('|', $dialect['then']),
52+
'and' => implode('|', $dialect['and']),
53+
'but' => implode('|', $dialect['but']),
54+
];
55+
}
56+
57+
return $keywordsArray;
58+
}
59+
60+
protected static function getSteps(string $keywords, string $text, int &$line, ?string $keywordType): array
61+
{
62+
$steps = [];
63+
foreach (explode('|', $keywords) as $keyword) {
64+
if ($keyword === '* ') {
65+
continue;
66+
}
67+
68+
$steps[] = new StepNode(trim($keyword), $text, [], $line++, $keywordType);
69+
}
70+
71+
return $steps;
72+
}
73+
}

0 commit comments

Comments
 (0)