From b4e3dffc70d5404949ecb19f6f460bab22f14611 Mon Sep 17 00:00:00 2001 From: Carlos Granados Date: Wed, 26 Feb 2025 09:16:55 +0100 Subject: [PATCH 1/3] Update ChachedArrayKeywords so that it does not require a file path --- src/Behat/Gherkin/Keywords/CachedArrayKeywords.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Behat/Gherkin/Keywords/CachedArrayKeywords.php b/src/Behat/Gherkin/Keywords/CachedArrayKeywords.php index 71220132..6692755a 100644 --- a/src/Behat/Gherkin/Keywords/CachedArrayKeywords.php +++ b/src/Behat/Gherkin/Keywords/CachedArrayKeywords.php @@ -19,13 +19,15 @@ */ class CachedArrayKeywords extends ArrayKeywords { + private const I18N_FILE_LOCATION = __DIR__ . '/../../../../i18n.php'; + /** * Initializes holder with file. * * @param string $file Cached array path */ - public function __construct($file) + public function __construct($file = null) { - parent::__construct(include $file); + parent::__construct(require $file ?? self::I18N_FILE_LOCATION); } } From 064befad3a9fe347dc9334e28cb948b7bda0ac71 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 26 Feb 2025 09:17:13 +0000 Subject: [PATCH 2/3] chore: Update CachedArrayKeywords test to prove default usage works --- tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php b/tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php index 09809418..19f2b1bc 100644 --- a/tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php +++ b/tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php @@ -17,12 +17,13 @@ class CachedArrayKeywordsTest extends KeywordsTestCase { protected function getKeywords() { - return new CachedArrayKeywords(__DIR__ . '/../../../../i18n.php'); + // Test with the default i18n file provided in this repository + return new CachedArrayKeywords(); } protected function getKeywordsArray() { - return include __DIR__ . '/../../../../i18n.php'; + return require __DIR__ . '/../../../../i18n.php'; } protected function getSteps($keywords, $text, &$line, $keywordType) From 2548cac0c946762526cc5a5fd3932c7f5b30d870 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 26 Feb 2025 10:09:49 +0000 Subject: [PATCH 3/3] 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 --- src/Behat/Gherkin/Keywords/CachedArrayKeywords.php | 9 ++++++--- tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Behat/Gherkin/Keywords/CachedArrayKeywords.php b/src/Behat/Gherkin/Keywords/CachedArrayKeywords.php index 6692755a..f1ca123b 100644 --- a/src/Behat/Gherkin/Keywords/CachedArrayKeywords.php +++ b/src/Behat/Gherkin/Keywords/CachedArrayKeywords.php @@ -19,15 +19,18 @@ */ class CachedArrayKeywords extends ArrayKeywords { - private const I18N_FILE_LOCATION = __DIR__ . '/../../../../i18n.php'; + public static function withDefaultKeywords(): self + { + return new self(__DIR__ . '/../../../../i18n.php'); + } /** * Initializes holder with file. * * @param string $file Cached array path */ - public function __construct($file = null) + public function __construct($file) { - parent::__construct(require $file ?? self::I18N_FILE_LOCATION); + parent::__construct(require $file); } } diff --git a/tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php b/tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php index 19f2b1bc..159b76f4 100644 --- a/tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php +++ b/tests/Behat/Gherkin/Keywords/CachedArrayKeywordsTest.php @@ -18,7 +18,7 @@ class CachedArrayKeywordsTest extends KeywordsTestCase protected function getKeywords() { // Test with the default i18n file provided in this repository - return new CachedArrayKeywords(); + return CachedArrayKeywords::withDefaultKeywords(); } protected function getKeywordsArray()