File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 2121 */
2222final class KeywordsDialectProvider implements DialectProviderInterface
2323{
24+ private readonly string $ defaultLanguage ;
25+
2426 public function __construct (
2527 private readonly KeywordsInterface $ keywords ,
2628 ) {
29+ // Assume a default dialect of `en` as the KeywordsInterface does not allow reading its language but returns the current data
30+ $ this ->defaultLanguage = $ this ->keywords instanceof ArrayKeywords ? $ this ->keywords ->getLanguage () : 'en ' ;
2731 }
2832
2933 public function getDialect (string $ language ): GherkinDialect
@@ -40,10 +44,9 @@ public function getDialect(string $language): GherkinDialect
4044
4145 public function getDefaultDialect (): GherkinDialect
4246 {
43- // Assume a default dialect of `en` as the KeywordsInterface does not allow reading its language but returns the current data
44- $ language = $ this ->keywords instanceof ArrayKeywords ? $ this ->keywords ->getLanguage () : 'en ' ;
47+ $ this ->keywords ->setLanguage ($ this ->defaultLanguage );
4548
46- return $ this ->buildDialect ($ language );
49+ return $ this ->buildDialect ($ this -> defaultLanguage );
4750 }
4851
4952 private function buildDialect (string $ language ): GherkinDialect
Original file line number Diff line number Diff line change 1212
1313use Behat \Gherkin \Dialect \KeywordsDialectProvider ;
1414use Behat \Gherkin \Keywords \ArrayKeywords ;
15+ use Behat \Gherkin \Keywords \CachedArrayKeywords ;
1516use PHPUnit \Framework \TestCase ;
1617
1718class KeywordsDialectProviderTest extends TestCase
@@ -40,4 +41,15 @@ public function testFailsForEmptyKeywordString(): void
4041 $ this ->expectExceptionMessage ('A keyword string must contain at least one keyword. ' );
4142 $ dialectProvider ->getDialect ('en ' );
4243 }
44+
45+ public function testDefaultDialectAfterExplicitDialect (): void
46+ {
47+ $ dialectProvider = new KeywordsDialectProvider (CachedArrayKeywords::withDefaultKeywords ());
48+
49+ $ ruDialect = $ dialectProvider ->getDialect ('ru ' );
50+ $ defaultDialect = $ dialectProvider ->getDefaultDialect ();
51+
52+ $ this ->assertSame ('ru ' , $ ruDialect ->getLanguage ());
53+ $ this ->assertSame ('en ' , $ defaultDialect ->getLanguage ());
54+ }
4355}
You can’t perform that action at this time.
0 commit comments