Skip to content

Commit 2548cac

Browse files
Add named constructor to create CachedArrayKeywords::withDefaultKeywords
Allows end-users to create an instance with the i18n file provided by us, without an external dependency on the path to the file. Co-authored-by: Carlos Granados <barel.barelon@gmail.com>
1 parent 064befa commit 2548cac

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Behat/Gherkin/Keywords/CachedArrayKeywords.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919
*/
2020
class CachedArrayKeywords extends ArrayKeywords
2121
{
22-
private const I18N_FILE_LOCATION = __DIR__ . '/../../../../i18n.php';
22+
public static function withDefaultKeywords(): self
23+
{
24+
return new self(__DIR__ . '/../../../../i18n.php');
25+
}
2326

2427
/**
2528
* Initializes holder with file.
2629
*
2730
* @param string $file Cached array path
2831
*/
29-
public function __construct($file = null)
32+
public function __construct($file)
3033
{
31-
parent::__construct(require $file ?? self::I18N_FILE_LOCATION);
34+
parent::__construct(require $file);
3235
}
3336
}

tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CachedArrayKeywordsTest extends KeywordsTestCase
1818
protected function getKeywords()
1919
{
2020
// Test with the default i18n file provided in this repository
21-
return new CachedArrayKeywords();
21+
return CachedArrayKeywords::withDefaultKeywords();
2222
}
2323

2424
protected function getKeywordsArray()

0 commit comments

Comments
 (0)