From a1e7eef1e7119b44642f230fb471d5fe750aaad2 Mon Sep 17 00:00:00 2001 From: Martin Soenen Date: Thu, 5 Feb 2026 11:05:28 +0100 Subject: [PATCH 1/6] :alien: Remove warnings in PHP8.5 --- .github/workflows/tests.yml | 2 +- src/Container/Traits/HasExtensions.php | 6 +++--- src/Container/Traits/HasLocale.php | 2 +- src/Extensions/Traits/HasLocale.php | 2 +- tests/Unit/LocaleTest.php | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f7a5a0b..9852101 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ '8.3', '8.4' ] + php-version: [ '8.3', '8.4', '8.5' ] name: Tests on PHP ${{ matrix.php-version }} diff --git a/src/Container/Traits/HasExtensions.php b/src/Container/Traits/HasExtensions.php index 254f4f2..60e0398 100644 --- a/src/Container/Traits/HasExtensions.php +++ b/src/Container/Traits/HasExtensions.php @@ -189,10 +189,10 @@ public function callExtensionMethod(string $method, array $parameters = []) // We assume we here have multiple extensions declined by locale, we will try // to get the extension with the current locale, defaulting to first element if (is_array($extension) && isset($extension['locales'])) { - if (!isset($extension['locales'][$this->getLocale()]) && !isset($extension['locales'][null])) { - throw new NoExtensionLocaleFound(sprintf('Locale \'%s\' and \'null\' for method \'%s\' was not found', $this->getLocale(), $method)); + if (!isset($extension['locales'][$this->getLocale()]) && !isset($extension['locales']['default'])) { + throw new NoExtensionLocaleFound(sprintf('Locale \'%s\' and \'default\' for method \'%s\' was not found', $this->getLocale(), $method)); } - $extension = $extension['locales'][$this->getLocale()] ?? $extension['locales'][null]; + $extension = $extension['locales'][$this->getLocale()] ?? $extension['locales']['default']; } return $extension->$method(...$parameters); diff --git a/src/Container/Traits/HasLocale.php b/src/Container/Traits/HasLocale.php index 3fddf6f..8b65707 100644 --- a/src/Container/Traits/HasLocale.php +++ b/src/Container/Traits/HasLocale.php @@ -18,7 +18,7 @@ trait HasLocale */ public function getLocale(): ?string { - return $this->locale ?? null; + return $this->locale ?? 'default'; } /** diff --git a/src/Extensions/Traits/HasLocale.php b/src/Extensions/Traits/HasLocale.php index a5c2349..ebf2c16 100644 --- a/src/Extensions/Traits/HasLocale.php +++ b/src/Extensions/Traits/HasLocale.php @@ -11,6 +11,6 @@ trait HasLocale */ public function getLocale(): ?string { - return null; + return 'default'; } } diff --git a/tests/Unit/LocaleTest.php b/tests/Unit/LocaleTest.php index 36196a4..58922bf 100644 --- a/tests/Unit/LocaleTest.php +++ b/tests/Unit/LocaleTest.php @@ -19,10 +19,10 @@ public function testExtensionsCorrectlyRegistered() $this->assertEquals( [ 'locales' => [ - null => new \Xefi\Faker\Tests\Support\Extensions\NullLocaleExtensionTest(new \Random\Randomizer()), - 'en_EN' => new \Xefi\Faker\Tests\Support\Extensions\EnEnExtensionTest(new \Random\Randomizer()), - 'en_US' => new \Xefi\Faker\Tests\Support\Extensions\EnUsExtensionTest(new \Random\Randomizer()), - 'fr_FR' => new \Xefi\Faker\Tests\Support\Extensions\FrFrExtensionTest(new \Random\Randomizer()), + 'default' => new \Xefi\Faker\Tests\Support\Extensions\NullLocaleExtensionTest(new \Random\Randomizer()), + 'en_EN' => new \Xefi\Faker\Tests\Support\Extensions\EnEnExtensionTest(new \Random\Randomizer()), + 'en_US' => new \Xefi\Faker\Tests\Support\Extensions\EnUsExtensionTest(new \Random\Randomizer()), + 'fr_FR' => new \Xefi\Faker\Tests\Support\Extensions\FrFrExtensionTest(new \Random\Randomizer()), ], ], (new \Xefi\Faker\Container\Container())->getExtensions()['locale-extension-test'] From 300f2e92d22c89b27fe6a2971c30efbb6b41a3b3 Mon Sep 17 00:00:00 2001 From: Martin Soenen Date: Thu, 5 Feb 2026 11:10:15 +0100 Subject: [PATCH 2/6] Fix tests --- tests/Unit/LocaleTest.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/Unit/LocaleTest.php b/tests/Unit/LocaleTest.php index 58922bf..b256a67 100644 --- a/tests/Unit/LocaleTest.php +++ b/tests/Unit/LocaleTest.php @@ -32,7 +32,7 @@ public function testExtensionsCorrectlyRegistered() public function testCallingDefaultExtension() { $this->assertEquals( - null, + 'default', (new \Xefi\Faker\Faker())->returnLocale() ); } @@ -75,16 +75,21 @@ public function testResettingLocale() ); $this->assertEquals( - null, + 'default', $faker->locale(null)->returnLocale() ); + + $this->assertEquals( + 'default', + $faker->locale('default')->returnLocale() + ); } public function testUsingNotExistingLocaleFallingBackToNullLocale() { $faker = new Xefi\Faker\Faker('not-existing-locale'); $this->assertEquals( - null, + 'default', $faker->returnLocale() ); } @@ -101,7 +106,7 @@ public function testUsingNotExistingLocaleWithoutNullLocale() ]); $this->expectException(\Xefi\Faker\Exceptions\NoExtensionLocaleFound::class); - $this->expectExceptionMessage('Locale \'not-existing-locale\' and \'null\' for method \'returnLocale\' was not found'); + $this->expectExceptionMessage('Locale \'not-existing-locale\' and \'default\' for method \'returnLocale\' was not found'); $faker = new Xefi\Faker\Faker('not-existing-locale'); $faker->returnLocale(); From 4bb94dd18358985e39ed1e2f4e229cd9f7beaf23 Mon Sep 17 00:00:00 2001 From: Martin Soenen Date: Thu, 5 Feb 2026 11:16:09 +0100 Subject: [PATCH 3/6] Fix test --- tests/Unit/Extensions/NumbersExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Extensions/NumbersExtensionTest.php b/tests/Unit/Extensions/NumbersExtensionTest.php index 0a245a4..8de48e8 100644 --- a/tests/Unit/Extensions/NumbersExtensionTest.php +++ b/tests/Unit/Extensions/NumbersExtensionTest.php @@ -71,7 +71,7 @@ public static function floatProvider() [-0.0001, 0.0001, 6], [1.111, 1.119, 4], [2500.0, 5000.0, 0], - [-0.999, 0.999, 2], + [-0.995, 0.995, 2], [1234.567, 2345.678, 3], [-300.3, -100.1, 1], [0.000001, 0.000009, 7], From c93ff8eb87cf835b57a94c50ba6882651e10de81 Mon Sep 17 00:00:00 2001 From: Martin Soenen Date: Sun, 8 Mar 2026 15:53:16 +0100 Subject: [PATCH 4/6] Switch default language to a const --- src/Container/Enum/Locales.php | 8 ++++++++ src/Container/Traits/HasExtensions.php | 7 ++++--- src/Container/Traits/HasLocale.php | 4 +++- src/Extensions/Traits/HasLocale.php | 4 +++- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 src/Container/Enum/Locales.php diff --git a/src/Container/Enum/Locales.php b/src/Container/Enum/Locales.php new file mode 100644 index 0000000..94950d9 --- /dev/null +++ b/src/Container/Enum/Locales.php @@ -0,0 +1,8 @@ +getLocale()]) && !isset($extension['locales']['default'])) { - throw new NoExtensionLocaleFound(sprintf('Locale \'%s\' and \'default\' for method \'%s\' was not found', $this->getLocale(), $method)); + if (!isset($extension['locales'][$this->getLocale()]) && !isset($extension['locales'][Locales::DEFAULT])) { + throw new NoExtensionLocaleFound(sprintf('Locale \'%s\' and \'%s\' for method \'%s\' was not found', $this->getLocale(), Locales::DEFAULT, $method)); } - $extension = $extension['locales'][$this->getLocale()] ?? $extension['locales']['default']; + $extension = $extension['locales'][$this->getLocale()] ?? $extension['locales'][Locales::DEFAULT]; } return $extension->$method(...$parameters); diff --git a/src/Container/Traits/HasLocale.php b/src/Container/Traits/HasLocale.php index 8b65707..6d0d323 100644 --- a/src/Container/Traits/HasLocale.php +++ b/src/Container/Traits/HasLocale.php @@ -2,6 +2,8 @@ namespace Xefi\Faker\Container\Traits; +use Xefi\Faker\Container\Enum\Locales; + trait HasLocale { /** @@ -18,7 +20,7 @@ trait HasLocale */ public function getLocale(): ?string { - return $this->locale ?? 'default'; + return $this->locale ?? Locales::DEFAULT; } /** diff --git a/src/Extensions/Traits/HasLocale.php b/src/Extensions/Traits/HasLocale.php index ebf2c16..bcd1146 100644 --- a/src/Extensions/Traits/HasLocale.php +++ b/src/Extensions/Traits/HasLocale.php @@ -2,6 +2,8 @@ namespace Xefi\Faker\Extensions\Traits; +use Xefi\Faker\Container\Enum\Locales; + trait HasLocale { /** @@ -11,6 +13,6 @@ trait HasLocale */ public function getLocale(): ?string { - return 'default'; + return Locales::DEFAULT; } } From bb75360f9954eb631763cc742d434d03c91d93ff Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Sun, 8 Mar 2026 14:53:33 +0000 Subject: [PATCH 5/6] Apply fixes from StyleCI --- src/Container/Enum/Locales.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Container/Enum/Locales.php b/src/Container/Enum/Locales.php index 94950d9..7c1926c 100644 --- a/src/Container/Enum/Locales.php +++ b/src/Container/Enum/Locales.php @@ -4,5 +4,5 @@ class Locales { - public const string DEFAULT = "default"; -} \ No newline at end of file + public const string DEFAULT = 'default'; +} From 2a2b333593bfae73fcd0b6d7842bb3108e1b7263 Mon Sep 17 00:00:00 2001 From: Martin Soenen Date: Mon, 9 Mar 2026 09:59:25 +0100 Subject: [PATCH 6/6] Fix PHP versions to avoid version problems --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e09cc3b..8075b2c 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "php": "^8.3", + "php": ">=8.3 <8.6", "phpdocumentor/reflection-docblock": "^5.6", "psr/container": "^2.0" },