From 410493380de6d107174f883005fe2d33ad11ff14 Mon Sep 17 00:00:00 2001 From: Shift Date: Sat, 2 Mar 2024 13:39:46 +0000 Subject: [PATCH 01/13] Bump PHPUnit dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index daf66fa..852e831 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require-dev": { "mockery/mockery": "^1.3.3", "orchestra/testbench": "^5.0|^6.0|^7.0|^8.0", - "phpunit/phpunit": "^8.0|^9.0" + "phpunit/phpunit": "^10.0" }, "scripts": { "test": "phpunit" From 414056c117f93e4f42a69f9d6f2724c810ef8165 Mon Sep 17 00:00:00 2001 From: Shift Date: Sat, 2 Mar 2024 13:39:46 +0000 Subject: [PATCH 02/13] Ignore PHPUnit cache folder --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fe1052a..80742d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /vendor /phpunit.xml composer.lock -/.phpunit.result.cache +/.phpunit.cache From 1a6c520fb572961da10c7a252f1a89c20a978df8 Mon Sep 17 00:00:00 2001 From: Shift Date: Sat, 2 Mar 2024 13:39:47 +0000 Subject: [PATCH 03/13] Adopt PHP attributes in test classes --- tests/Feature/SetLocaleTest.php | 33 +++++++++++++++++---------------- tests/Unit/LocalizerTest.php | 19 ++++++++++--------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/tests/Feature/SetLocaleTest.php b/tests/Feature/SetLocaleTest.php index 8b8a099..3455f51 100644 --- a/tests/Feature/SetLocaleTest.php +++ b/tests/Feature/SetLocaleTest.php @@ -2,6 +2,7 @@ namespace CodeZero\Localizer\Tests\Feature; +use PHPUnit\Framework\Attributes\Test; use CodeZero\BrowserLocale\BrowserLocale; use CodeZero\Localizer\Middleware\SetLocale; use CodeZero\Localizer\Tests\TestCase; @@ -33,7 +34,7 @@ protected function setUp(): void $this->cookieName = Config::get('localizer.cookie_name'); } - /** @test */ + #[Test] public function it_looks_for_a_locale_in_a_custom_route_action() { $this->setSupportedLocales(['en', 'nl']); @@ -54,7 +55,7 @@ public function it_looks_for_a_locale_in_a_custom_route_action() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_looks_for_a_locale_in_the_url() { $this->setSupportedLocales(['en', 'nl']); @@ -71,7 +72,7 @@ public function it_looks_for_a_locale_in_the_url() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function you_can_configure_which_segment_to_use_as_locale() { $this->setSupportedLocales(['en', 'nl']); @@ -90,7 +91,7 @@ public function you_can_configure_which_segment_to_use_as_locale() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_looks_for_custom_slugs() { $this->setSupportedLocales([ @@ -110,7 +111,7 @@ public function it_looks_for_custom_slugs() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function you_can_use_multiple_slugs_for_a_locale() { $this->setSupportedLocales([ @@ -140,7 +141,7 @@ public function you_can_use_multiple_slugs_for_a_locale() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_looks_for_custom_domains() { $this->setSupportedLocales([ @@ -162,7 +163,7 @@ public function it_looks_for_custom_domains() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function you_can_use_multiple_domains_for_a_locale() { $this->setSupportedLocales([ @@ -196,7 +197,7 @@ public function you_can_use_multiple_domains_for_a_locale() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_checks_for_a_configured_omitted_locale() { $this->setSupportedLocales(['en', 'nl']); @@ -215,7 +216,7 @@ public function it_checks_for_a_configured_omitted_locale() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_looks_for_a_locale_on_the_authenticated_user() { $this->setSupportedLocales(['en', 'nl']); @@ -236,7 +237,7 @@ public function it_looks_for_a_locale_on_the_authenticated_user() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_will_bypass_missing_attribute_exception_if_the_locale_attribute_is_missing_on_the_user_model() { if (version_compare(App::version(), '9.35.0') === -1) { @@ -261,7 +262,7 @@ public function it_will_bypass_missing_attribute_exception_if_the_locale_attribu $this->assertEquals('en', $response->original); } - /** @test */ + #[Test] public function it_looks_for_a_locale_in_the_session() { $this->setSupportedLocales(['en', 'nl']); @@ -280,7 +281,7 @@ public function it_looks_for_a_locale_in_the_session() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_looks_for_a_locale_in_a_cookie() { $this->setSupportedLocales(['en', 'nl']); @@ -300,7 +301,7 @@ public function it_looks_for_a_locale_in_a_cookie() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_looks_for_a_locale_in_the_browser() { $this->setSupportedLocales(['en', 'nl']); @@ -319,7 +320,7 @@ public function it_looks_for_a_locale_in_the_browser() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_returns_the_best_match_when_a_browser_locale_is_used() { $this->setSupportedLocales(['en', 'nl', 'fr']); @@ -338,7 +339,7 @@ public function it_returns_the_best_match_when_a_browser_locale_is_used() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function it_looks_for_the_current_app_locale() { $this->setSupportedLocales(['en', 'nl']); @@ -355,7 +356,7 @@ public function it_looks_for_the_current_app_locale() $this->assertEquals('nl', $response->original); } - /** @test */ + #[Test] public function trusted_detectors_ignore_supported_locales_and_may_set_any_locale() { $this->setSupportedLocales(['en']); diff --git a/tests/Unit/LocalizerTest.php b/tests/Unit/LocalizerTest.php index fb85c2b..d61f7ce 100644 --- a/tests/Unit/LocalizerTest.php +++ b/tests/Unit/LocalizerTest.php @@ -2,6 +2,7 @@ namespace CodeZero\Localizer\Tests\Unit; +use PHPUnit\Framework\Attributes\Test; use CodeZero\Localizer\Detectors\Detector; use CodeZero\Localizer\Localizer; use CodeZero\Localizer\Stores\Store; @@ -11,7 +12,7 @@ class LocalizerTest extends TestCase { - /** @test */ + #[Test] public function it_loops_through_the_detectors_and_returns_the_first_supported_locale() { $supportedLocales = ['en', 'nl']; @@ -26,7 +27,7 @@ public function it_loops_through_the_detectors_and_returns_the_first_supported_l $this->assertEquals('nl', $localizer->detect()); } - /** @test */ + #[Test] public function it_returns_the_first_match_if_an_array_of_locales_is_detected() { $supportedLocales = ['en', 'nl']; @@ -39,7 +40,7 @@ public function it_returns_the_first_match_if_an_array_of_locales_is_detected() $this->assertEquals('nl', $localizer->detect()); } - /** @test */ + #[Test] public function trusted_detectors_ignore_supported_locales_and_may_set_any_locale() { $supportedLocales = ['en']; @@ -55,7 +56,7 @@ public function trusted_detectors_ignore_supported_locales_and_may_set_any_local $this->assertEquals('nl', $localizer->detect()); } - /** @test */ + #[Test] public function it_skips_null_and_false_and_empty_values() { App::instance(Detector::class, Mockery::mock(Detector::class)->allows()->detect()->andReturns('')->getMock()); @@ -75,7 +76,7 @@ public function it_skips_null_and_false_and_empty_values() $this->assertEquals('nl', $localizer->detect()); } - /** @test */ + #[Test] public function it_skips_null_and_false_and_empty_values_from_trusted_detectors() { App::instance(Detector::class, Mockery::mock(Detector::class)->allows()->detect()->andReturns('')->getMock()); @@ -98,7 +99,7 @@ public function it_skips_null_and_false_and_empty_values_from_trusted_detectors( $this->assertEquals('nl', $localizer->detect()); } - /** @test */ + #[Test] public function it_returns_false_if_no_supported_locale_could_be_detected() { $supportedLocales = ['en']; @@ -113,7 +114,7 @@ public function it_returns_false_if_no_supported_locale_could_be_detected() $this->assertFalse($localizer->detect()); } - /** @test */ + #[Test] public function it_loops_through_the_stores_and_calls_the_store_method_with_the_given_locale() { $stores = [ @@ -127,7 +128,7 @@ public function it_loops_through_the_stores_and_calls_the_store_method_with_the_ $localizer->store('nl'); } - /** @test */ + #[Test] public function it_accepts_class_names_instead_of_instances_in_the_constructor() { App::instance(Store::class, Mockery::mock(Store::class)->expects()->store('nl')->once()->getMock()); @@ -142,7 +143,7 @@ public function it_accepts_class_names_instead_of_instances_in_the_constructor() $localizer->store('nl'); } - /** @test */ + #[Test] public function you_can_set_the_supported_locales_at_runtime() { $supportedLocales = ['en']; From dcbfda0166f53b300d496789d793f2f8f2467e32 Mon Sep 17 00:00:00 2001 From: Shift Date: Sat, 2 Mar 2024 13:39:47 +0000 Subject: [PATCH 04/13] Add return types to test methods --- tests/Feature/SetLocaleTest.php | 32 ++++++++++++++++---------------- tests/Unit/LocalizerTest.php | 18 +++++++++--------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/Feature/SetLocaleTest.php b/tests/Feature/SetLocaleTest.php index 3455f51..b4ededc 100644 --- a/tests/Feature/SetLocaleTest.php +++ b/tests/Feature/SetLocaleTest.php @@ -35,7 +35,7 @@ protected function setUp(): void } #[Test] - public function it_looks_for_a_locale_in_a_custom_route_action() + public function it_looks_for_a_locale_in_a_custom_route_action(): void { $this->setSupportedLocales(['en', 'nl']); $this->setAppLocale('en'); @@ -56,7 +56,7 @@ public function it_looks_for_a_locale_in_a_custom_route_action() } #[Test] - public function it_looks_for_a_locale_in_the_url() + public function it_looks_for_a_locale_in_the_url(): void { $this->setSupportedLocales(['en', 'nl']); $this->setAppLocale('en'); @@ -73,7 +73,7 @@ public function it_looks_for_a_locale_in_the_url() } #[Test] - public function you_can_configure_which_segment_to_use_as_locale() + public function you_can_configure_which_segment_to_use_as_locale(): void { $this->setSupportedLocales(['en', 'nl']); $this->setAppLocale('en'); @@ -92,7 +92,7 @@ public function you_can_configure_which_segment_to_use_as_locale() } #[Test] - public function it_looks_for_custom_slugs() + public function it_looks_for_custom_slugs(): void { $this->setSupportedLocales([ 'en' => 'english', @@ -112,7 +112,7 @@ public function it_looks_for_custom_slugs() } #[Test] - public function you_can_use_multiple_slugs_for_a_locale() + public function you_can_use_multiple_slugs_for_a_locale(): void { $this->setSupportedLocales([ 'en' => 'english', @@ -142,7 +142,7 @@ public function you_can_use_multiple_slugs_for_a_locale() } #[Test] - public function it_looks_for_custom_domains() + public function it_looks_for_custom_domains(): void { $this->setSupportedLocales([ 'en' => 'english.test', @@ -164,7 +164,7 @@ public function it_looks_for_custom_domains() } #[Test] - public function you_can_use_multiple_domains_for_a_locale() + public function you_can_use_multiple_domains_for_a_locale(): void { $this->setSupportedLocales([ 'en' => 'english.test', @@ -198,7 +198,7 @@ public function you_can_use_multiple_domains_for_a_locale() } #[Test] - public function it_checks_for_a_configured_omitted_locale() + public function it_checks_for_a_configured_omitted_locale(): void { $this->setSupportedLocales(['en', 'nl']); $this->setAppLocale('en'); @@ -217,7 +217,7 @@ public function it_checks_for_a_configured_omitted_locale() } #[Test] - public function it_looks_for_a_locale_on_the_authenticated_user() + public function it_looks_for_a_locale_on_the_authenticated_user(): void { $this->setSupportedLocales(['en', 'nl']); $this->setAppLocale('en'); @@ -238,7 +238,7 @@ public function it_looks_for_a_locale_on_the_authenticated_user() } #[Test] - public function it_will_bypass_missing_attribute_exception_if_the_locale_attribute_is_missing_on_the_user_model() + public function it_will_bypass_missing_attribute_exception_if_the_locale_attribute_is_missing_on_the_user_model(): void { if (version_compare(App::version(), '9.35.0') === -1) { $this->markTestSkipped('This test only applies to Laravel 9.35.0 and higher.'); @@ -263,7 +263,7 @@ public function it_will_bypass_missing_attribute_exception_if_the_locale_attribu } #[Test] - public function it_looks_for_a_locale_in_the_session() + public function it_looks_for_a_locale_in_the_session(): void { $this->setSupportedLocales(['en', 'nl']); $this->setAppLocale('en'); @@ -282,7 +282,7 @@ public function it_looks_for_a_locale_in_the_session() } #[Test] - public function it_looks_for_a_locale_in_a_cookie() + public function it_looks_for_a_locale_in_a_cookie(): void { $this->setSupportedLocales(['en', 'nl']); $this->setAppLocale('en'); @@ -302,7 +302,7 @@ public function it_looks_for_a_locale_in_a_cookie() } #[Test] - public function it_looks_for_a_locale_in_the_browser() + public function it_looks_for_a_locale_in_the_browser(): void { $this->setSupportedLocales(['en', 'nl']); $this->setAppLocale('en'); @@ -321,7 +321,7 @@ public function it_looks_for_a_locale_in_the_browser() } #[Test] - public function it_returns_the_best_match_when_a_browser_locale_is_used() + public function it_returns_the_best_match_when_a_browser_locale_is_used(): void { $this->setSupportedLocales(['en', 'nl', 'fr']); $this->setAppLocale('en'); @@ -340,7 +340,7 @@ public function it_returns_the_best_match_when_a_browser_locale_is_used() } #[Test] - public function it_looks_for_the_current_app_locale() + public function it_looks_for_the_current_app_locale(): void { $this->setSupportedLocales(['en', 'nl']); $this->setAppLocale('nl'); @@ -357,7 +357,7 @@ public function it_looks_for_the_current_app_locale() } #[Test] - public function trusted_detectors_ignore_supported_locales_and_may_set_any_locale() + public function trusted_detectors_ignore_supported_locales_and_may_set_any_locale(): void { $this->setSupportedLocales(['en']); $this->setAppLocale('en'); diff --git a/tests/Unit/LocalizerTest.php b/tests/Unit/LocalizerTest.php index d61f7ce..4d2a931 100644 --- a/tests/Unit/LocalizerTest.php +++ b/tests/Unit/LocalizerTest.php @@ -13,7 +13,7 @@ class LocalizerTest extends TestCase { #[Test] - public function it_loops_through_the_detectors_and_returns_the_first_supported_locale() + public function it_loops_through_the_detectors_and_returns_the_first_supported_locale(): void { $supportedLocales = ['en', 'nl']; $detectors = [ @@ -28,7 +28,7 @@ public function it_loops_through_the_detectors_and_returns_the_first_supported_l } #[Test] - public function it_returns_the_first_match_if_an_array_of_locales_is_detected() + public function it_returns_the_first_match_if_an_array_of_locales_is_detected(): void { $supportedLocales = ['en', 'nl']; $detectors = [ @@ -41,7 +41,7 @@ public function it_returns_the_first_match_if_an_array_of_locales_is_detected() } #[Test] - public function trusted_detectors_ignore_supported_locales_and_may_set_any_locale() + public function trusted_detectors_ignore_supported_locales_and_may_set_any_locale(): void { $supportedLocales = ['en']; $detectors = [ @@ -57,7 +57,7 @@ public function trusted_detectors_ignore_supported_locales_and_may_set_any_local } #[Test] - public function it_skips_null_and_false_and_empty_values() + public function it_skips_null_and_false_and_empty_values(): void { App::instance(Detector::class, Mockery::mock(Detector::class)->allows()->detect()->andReturns('')->getMock()); @@ -77,7 +77,7 @@ public function it_skips_null_and_false_and_empty_values() } #[Test] - public function it_skips_null_and_false_and_empty_values_from_trusted_detectors() + public function it_skips_null_and_false_and_empty_values_from_trusted_detectors(): void { App::instance(Detector::class, Mockery::mock(Detector::class)->allows()->detect()->andReturns('')->getMock()); @@ -100,7 +100,7 @@ public function it_skips_null_and_false_and_empty_values_from_trusted_detectors( } #[Test] - public function it_returns_false_if_no_supported_locale_could_be_detected() + public function it_returns_false_if_no_supported_locale_could_be_detected(): void { $supportedLocales = ['en']; $detectors = [ @@ -115,7 +115,7 @@ public function it_returns_false_if_no_supported_locale_could_be_detected() } #[Test] - public function it_loops_through_the_stores_and_calls_the_store_method_with_the_given_locale() + public function it_loops_through_the_stores_and_calls_the_store_method_with_the_given_locale(): void { $stores = [ Mockery::mock(Store::class)->expects()->store('nl')->once()->getMock(), @@ -129,7 +129,7 @@ public function it_loops_through_the_stores_and_calls_the_store_method_with_the_ } #[Test] - public function it_accepts_class_names_instead_of_instances_in_the_constructor() + public function it_accepts_class_names_instead_of_instances_in_the_constructor(): void { App::instance(Store::class, Mockery::mock(Store::class)->expects()->store('nl')->once()->getMock()); App::instance(Detector::class, Mockery::mock(Detector::class)->expects()->detect()->once()->getMock()); @@ -144,7 +144,7 @@ public function it_accepts_class_names_instead_of_instances_in_the_constructor() } #[Test] - public function you_can_set_the_supported_locales_at_runtime() + public function you_can_set_the_supported_locales_at_runtime(): void { $supportedLocales = ['en']; $detectors = [ From a70bb1d3f38167346550067987776d80adaa58b0 Mon Sep 17 00:00:00 2001 From: Shift Date: Sat, 2 Mar 2024 13:39:47 +0000 Subject: [PATCH 05/13] Define test classes as `final` --- tests/Feature/SetLocaleTest.php | 2 +- tests/Unit/LocalizerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/SetLocaleTest.php b/tests/Feature/SetLocaleTest.php index b4ededc..504fa5a 100644 --- a/tests/Feature/SetLocaleTest.php +++ b/tests/Feature/SetLocaleTest.php @@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Session; -class SetLocaleTest extends TestCase +final class SetLocaleTest extends TestCase { protected $sessionKey; protected $cookieName; diff --git a/tests/Unit/LocalizerTest.php b/tests/Unit/LocalizerTest.php index 4d2a931..ef45338 100644 --- a/tests/Unit/LocalizerTest.php +++ b/tests/Unit/LocalizerTest.php @@ -10,7 +10,7 @@ use Illuminate\Support\Facades\App; use Mockery; -class LocalizerTest extends TestCase +final class LocalizerTest extends TestCase { #[Test] public function it_loops_through_the_detectors_and_returns_the_first_supported_locale(): void From 92480c8001c4f9a380476939fe3106b027cfa15f Mon Sep 17 00:00:00 2001 From: Ivan Vermeyen Date: Wed, 6 Mar 2024 14:07:39 +0100 Subject: [PATCH 06/13] Only support Laravel 10 and 11 --- .github/workflows/run-tests.yml | 23 ++++++----------------- README.md | 6 +++--- UPGRADE.md | 9 +++++++++ composer.json | 13 +++++-------- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9e9fd1f..4554c07 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,28 +8,17 @@ jobs: strategy: fail-fast: true matrix: - php: [ 8.0, 8.1 ] - laravel: [ 8.*, 9.*, 10.* ] + php: [ 8.1, 8.2, 8.3 ] + laravel: [ 10.*, 11.* ] dependency-version: [ prefer-stable ] exclude: - - laravel: 10.* - php: 8.0 + - laravel: 11.* + php: 8.1 include: - - laravel: 7.* - php: 7.2 - testbench: 5.* - - laravel: 7.* - php: 8.0 - testbench: 5.* - - laravel: 8.* - php: 7.3 - testbench: 6.* - - laravel: 8.* - testbench: 6.* - - laravel: 9.* - testbench: 7.* - laravel: 10.* testbench: 8.* + - laravel: 11.* + testbench: 9.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} diff --git a/README.md b/README.md index 4be467e..ac9f8e6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Laravel Localizer [![GitHub release](https://img.shields.io/github/release/codezero-be/laravel-localizer.svg?style=flat-square)](https://github.com/codezero-be/laravel-localizer/releases) -[![Laravel](https://img.shields.io/badge/laravel-10-red?style=flat-square&logo=laravel&logoColor=white)](https://laravel.com) +[![Laravel](https://img.shields.io/badge/laravel-11-red?style=flat-square&logo=laravel&logoColor=white)](https://laravel.com) [![License](https://img.shields.io/packagist/l/codezero/laravel-localizer.svg?style=flat-square)](LICENSE.md) [![Build Status](https://img.shields.io/github/actions/workflow/status/codezero-be/laravel-localizer/run-tests.yml?style=flat-square&logo=github&logoColor=white&label=tests)](https://github.com/codezero-be/laravel-localizer/actions) [![Code Coverage](https://img.shields.io/codacy/coverage/ad6fcea152b449d380a187a375d0f7d7/master?style=flat-square)](https://app.codacy.com/gh/codezero-be/laravel-localizer) @@ -19,8 +19,8 @@ Automatically detect and set an app locale that matches your visitor's preferenc ## ✅ Requirements -- PHP >= 7.2.5 -- Laravel >= 7.0 +- PHP >= 8.1 +- Laravel >= 19.0 ## ⬆ Upgrade diff --git a/UPGRADE.md b/UPGRADE.md index 8850e90..f6d7a02 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,14 @@ # Upgrade Guide +## Upgrading To 3.0 From 2.x + +### ➡ Minimum Requirements Updated + +Due to PHP and PHPUnit version constraints with Laravel 11, we dropped support for Laravel 7.x, 8.x and 9.x. + +- The minimum PHP version required is now 8.1 +- The minimum Laravel version required is now 10.0 + ## Upgrading To 2.0 From 1.x ### ➡ Minimum Requirements Updated diff --git a/composer.json b/composer.json index 852e831..6444ae8 100644 --- a/composer.json +++ b/composer.json @@ -21,14 +21,14 @@ } ], "require": { - "php": "^7.2.5|^8.0", + "php": "^8.1", "codezero/browser-locale": "^3.0", - "illuminate/support": "^7.0|^8.0|^9.0|^10.0" + "illuminate/support": "^10.0|^11.0" }, "require-dev": { "mockery/mockery": "^1.3.3", - "orchestra/testbench": "^5.0|^6.0|^7.0|^8.0", - "phpunit/phpunit": "^10.0" + "orchestra/testbench": "^8.0|^9.0", + "phpunit/phpunit": "^10.5" }, "scripts": { "test": "phpunit" @@ -53,10 +53,7 @@ "config": { "preferred-install": "dist", "sort-packages": true, - "optimize-autoloader": true, - "allow-plugins": { - "kylekatarnls/update-helper": true - } + "optimize-autoloader": true }, "minimum-stability": "dev", "prefer-stable": true From 7633f8c720b4a7fa4b0ec47e8e58d2651e3f5916 Mon Sep 17 00:00:00 2001 From: Ivan Vermeyen Date: Wed, 6 Mar 2024 14:12:56 +0100 Subject: [PATCH 07/13] Migrate PHPUnit XML --- phpunit.xml.dist | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e1988a6..80550d0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,6 @@ - + stopOnFailure="false" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> + + + ./src + + ./tests/Unit @@ -16,11 +23,6 @@ ./tests/Feature - - - ./src - - From c4313ab5c10afbe12245661d654d672246209db9 Mon Sep 17 00:00:00 2001 From: Ivan Vermeyen Date: Wed, 6 Mar 2024 14:21:11 +0100 Subject: [PATCH 08/13] Migrate PHPUnit XML --- phpunit.xml.dist | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 80550d0..dc4366a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,20 +1,13 @@ - - - ./src - - + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" + cacheDirectory=".phpunit.cache" + backupStaticProperties="false"> ./tests/Unit @@ -29,4 +22,9 @@ + + + ./src + + From fedda2d58d806d9157f61efdf79ec2c4df4dcb9a Mon Sep 17 00:00:00 2001 From: Ivan Vermeyen Date: Wed, 6 Mar 2024 14:21:38 +0100 Subject: [PATCH 09/13] Ignore PHPUnit cache --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 80742d3..667fe37 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /phpunit.xml composer.lock /.phpunit.cache +/.phpunit.result.cache From 5cdbf0e640f971d00e2a85a35baefcd6abace362 Mon Sep 17 00:00:00 2001 From: Ivan Vermeyen Date: Sun, 10 Mar 2024 13:42:46 +0100 Subject: [PATCH 10/13] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ac9f8e6..582e700 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Automatically detect and set an app locale that matches your visitor's preferenc ## ✅ Requirements - PHP >= 8.1 -- Laravel >= 19.0 +- Laravel >= 10.0 ## ⬆ Upgrade From 121ea0814cc450e638fdbd1ca7e490e8c4b9221f Mon Sep 17 00:00:00 2001 From: Ivan Vermeyen Date: Sun, 10 Mar 2024 15:49:12 +0100 Subject: [PATCH 11/13] Don't use Kernel to test middleware --- tests/Feature/SetLocaleTest.php | 36 ++++++++++++++++----------------- tests/Stubs/Kernel.php | 25 ----------------------- tests/TestCase.php | 18 ----------------- 3 files changed, 18 insertions(+), 61 deletions(-) delete mode 100644 tests/Stubs/Kernel.php diff --git a/tests/Feature/SetLocaleTest.php b/tests/Feature/SetLocaleTest.php index 504fa5a..fcd3656 100644 --- a/tests/Feature/SetLocaleTest.php +++ b/tests/Feature/SetLocaleTest.php @@ -45,7 +45,7 @@ public function it_looks_for_a_locale_in_a_custom_route_action(): void Route::group($routeAction, function () { Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); }); $response = $this->get('some/route'); @@ -63,7 +63,7 @@ public function it_looks_for_a_locale_in_the_url(): void Route::get('nl/some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->get('nl/some/route'); @@ -82,7 +82,7 @@ public function you_can_configure_which_segment_to_use_as_locale(): void Route::get('some/nl/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->get('some/nl/route'); @@ -102,7 +102,7 @@ public function it_looks_for_custom_slugs(): void Route::get('dutch/some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->get('dutch/some/route'); @@ -122,11 +122,11 @@ public function you_can_use_multiple_slugs_for_a_locale(): void Route::get('dutch/some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); Route::get('nederlands/some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->get('dutch/some/route'); @@ -153,7 +153,7 @@ public function it_looks_for_custom_domains(): void Route::group(['domain' => 'dutch.test'], function () { Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); }); $response = $this->get('http://dutch.test/some/route'); @@ -175,13 +175,13 @@ public function you_can_use_multiple_domains_for_a_locale(): void Route::group(['domain' => 'dutch.test'], function () { Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); }); Route::group(['domain' => 'nederlands.test'], function () { Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); }); $response = $this->get('http://dutch.test/some/route'); @@ -207,7 +207,7 @@ public function it_checks_for_a_configured_omitted_locale(): void Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->get('some/route'); @@ -228,7 +228,7 @@ public function it_looks_for_a_locale_on_the_authenticated_user(): void Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->actingAs($user)->get('some/route'); @@ -253,7 +253,7 @@ public function it_will_bypass_missing_attribute_exception_if_the_locale_attribu Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->actingAs($user)->get('some/route'); @@ -272,7 +272,7 @@ public function it_looks_for_a_locale_in_the_session(): void Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->get('some/route'); @@ -291,7 +291,7 @@ public function it_looks_for_a_locale_in_a_cookie(): void Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->withCookie($this->cookieName, $cookie) ->get('some/route'); @@ -311,7 +311,7 @@ public function it_looks_for_a_locale_in_the_browser(): void Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->get('some/route'); @@ -330,7 +330,7 @@ public function it_returns_the_best_match_when_a_browser_locale_is_used(): void Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->get('some/route'); @@ -347,7 +347,7 @@ public function it_looks_for_the_current_app_locale(): void Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); $response = $this->get('some/route'); @@ -371,7 +371,7 @@ public function trusted_detectors_ignore_supported_locales_and_may_set_any_local Route::group($routeAction, function () { Route::get('some/route', function () { return App::getLocale(); - })->middleware(['web']); + })->middleware(['web', \CodeZero\Localizer\Middleware\SetLocale::class]); }); $response = $this->get('some/route'); diff --git a/tests/Stubs/Kernel.php b/tests/Stubs/Kernel.php deleted file mode 100644 index 691f8f8..0000000 --- a/tests/Stubs/Kernel.php +++ /dev/null @@ -1,25 +0,0 @@ - [ - \Illuminate\Cookie\Middleware\EncryptCookies::class, - \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, - \Illuminate\Session\Middleware\StartSession::class, - // \Illuminate\Session\Middleware\AuthenticateSession::class, - \Illuminate\View\Middleware\ShareErrorsFromSession::class, - \CodeZero\Localizer\Middleware\SetLocale::class, // <== Added Middleware Here - \Illuminate\Routing\Middleware\SubstituteBindings::class, - ], - ]; -} diff --git a/tests/TestCase.php b/tests/TestCase.php index 25892ec..5f29dc2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -21,24 +21,6 @@ protected function setUp(): void Config::set('app.key', Str::random(32)); } - /** - * Resolve application Console Kernel implementation. - * - * @param \Illuminate\Foundation\Application $app - * - * @return void - */ - protected function resolveApplicationHttpKernel($app): void - { - // In Laravel 6+, we need to add the middleware to - // $middlewarePriority in Kernel.php for route - // model binding to work properly. - $app->singleton( - 'Illuminate\Contracts\Http\Kernel', - 'CodeZero\Localizer\Tests\Stubs\Kernel' - ); - } - /** * Get the packages service providers. * From d685748b996f846eb5867bc2784935dc50e2ea9d Mon Sep 17 00:00:00 2001 From: Ivan Vermeyen Date: Sun, 10 Mar 2024 15:49:25 +0100 Subject: [PATCH 12/13] Update UPGRADE.md --- UPGRADE.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index f6d7a02..87bf804 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -9,6 +9,17 @@ Due to PHP and PHPUnit version constraints with Laravel 11, we dropped support f - The minimum PHP version required is now 8.1 - The minimum Laravel version required is now 10.0 +--- + +### ➡ Re-register Middleware + +Laravel 11 no longer has a `app/Http/Kernel.php` to register middleware. +This is now handled in `bootstrap/app.php`. + +🔸 **Actions Required** + +If you use Laravel 11, register the middleware in `bootstrap/app.php` as described in the README. + ## Upgrading To 2.0 From 1.x ### ➡ Minimum Requirements Updated From f5e29b46e5a6d2d420fe8161e91f311901927e73 Mon Sep 17 00:00:00 2001 From: Ivan Vermeyen Date: Mon, 11 Mar 2024 11:06:11 +0100 Subject: [PATCH 13/13] Add Laravel 11 middleware instructions to README --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 582e700..8ce4846 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,36 @@ Laravel will automatically register the ServiceProvider. ## 🧩 Add Middleware -Add the middleware to the `web` middleware group in `app/Http/Kernel.php`. +By default, the app locale will always be what you configured in `config/app.php`. +To automatically update the app locale, you need to register the middleware in the `web` middleware group. Make sure to add it after `StartSession` and before `SubstituteBindings`. The order of the middleware is important if you are using localized route keys (translated slugs)! The session needs to be active when setting the locale, and the locale needs to be set when substituting the route bindings. +### Laravel 11 and newer: + +Add the middleware to the `web` middleware group in `bootstrap/app.php`. + +```php +// bootstrap/app.php +->withMiddleware(function (Middleware $middleware) { + $middleware->web(remove: [ + \Illuminate\Routing\Middleware\SubstituteBindings::class, + ]); + $middleware->web(append: [ + \CodeZero\Localizer\Middleware\SetLocale::class, + \Illuminate\Routing\Middleware\SubstituteBindings::class, + ]); +}) +``` + +### Laravel 10: + +Add the middleware to the `web` middleware group in `app/Http/Kernel.php`. + ```php +// app/Http/Kernel.php protected $middlewareGroups = [ 'web' => [ //...