From fea226dfe4c4352839bb08ee1d6d80302b1ddcf3 Mon Sep 17 00:00:00 2001 From: jordyvanderhaegen Date: Wed, 27 Nov 2024 20:22:55 +0100 Subject: [PATCH] chore: solve PHPUnit 10 deprecations (#918) * Bump PHPUnit dependencies * Adopt PHP attributes in test classes * Declare data providers as `static` * Add return types to test methods * Define test classes as `final` * chore: make static dataproviders work * chore: attempt to make tests pass on prefer-lowest * chore: camel case variables --------- Co-authored-by: Shift --- composer.json | 2 +- tests/LaravelLocalizationTest.php | 397 +++++++++++++++--------------- 2 files changed, 198 insertions(+), 201 deletions(-) diff --git a/composer.json b/composer.json index 5af85fb..aa54c99 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "orchestra/testbench-browser-kit": "^8.5|^9.0", - "phpunit/phpunit": "^9.5.10|^10.0" + "phpunit/phpunit": "^10.1" }, "suggest": { "ext-intl": "*" diff --git a/tests/LaravelLocalizationTest.php b/tests/LaravelLocalizationTest.php index a3f8e3d..30304e3 100644 --- a/tests/LaravelLocalizationTest.php +++ b/tests/LaravelLocalizationTest.php @@ -2,13 +2,14 @@ namespace Mcamara\LaravelLocalization\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use Illuminate\Support\Facades\Request; use Mcamara\LaravelLocalization\LaravelLocalization; -class LaravelLocalizationTest extends TestCase +final class LaravelLocalizationTest extends TestCase { - protected $test_url = 'http://localhost/'; - protected $test_url2 = 'http://localhost'; + protected static string $testUrl = 'http://localhost/'; + protected static string $testUrl2 = 'http://localhost'; protected $supportedLocales = []; @@ -117,7 +118,7 @@ protected function createRequest( */ protected function getEnvironmentSetUp($app) { - app('config')->set('app.url', $this->test_url); + app('config')->set('app.url', self::$testUrl); app('config')->set('app.locale', $this->defaultLocale); @@ -133,12 +134,12 @@ protected function getEnvironmentSetUp($app) app('translator')->load('LaravelLocalization', 'routes', 'es'); app('translator')->load('LaravelLocalization', 'routes', 'en'); - app('laravellocalization')->setBaseUrl($this->test_url); + app('laravellocalization')->setBaseUrl(self::$testUrl); $this->setRoutes(); } - public function testSetLocale() + public function testSetLocale(): void { $this->assertEquals(route('about'), 'http://localhost/about'); @@ -157,16 +158,16 @@ public function testSetLocale() $this->assertEquals('en', app('laravellocalization')->getCurrentLocale()); } - public function testLocalizeURL() + public function testLocalizeURL(): void { $this->assertEquals( - $this->test_url.app('laravellocalization')->getCurrentLocale(), + self::$testUrl.app('laravellocalization')->getCurrentLocale(), app('laravellocalization')->localizeURL() ); // Missing trailing slash in a URL $this->assertEquals( - $this->test_url2.'/'.app('laravellocalization')->getCurrentLocale(), + self::$testUrl2.'/'.app('laravellocalization')->getCurrentLocale(), app('laravellocalization')->localizeURL() ); @@ -174,49 +175,49 @@ public function testLocalizeURL() // testing hide default locale option $this->assertNotEquals( - $this->test_url.app('laravellocalization')->getDefaultLocale(), + self::$testUrl.app('laravellocalization')->getDefaultLocale(), app('laravellocalization')->localizeURL() ); $this->assertEquals( - $this->test_url, + self::$testUrl, app('laravellocalization')->localizeURL() ); app('laravellocalization')->setLocale('es'); $this->assertEquals( - $this->test_url.'es', + self::$testUrl.'es', app('laravellocalization')->localizeURL() ); $this->assertEquals( - $this->test_url.'about', - app('laravellocalization')->localizeURL($this->test_url.'about', 'en') + self::$testUrl.'about', + app('laravellocalization')->localizeURL(self::$testUrl.'about', 'en') ); $this->assertNotEquals( - $this->test_url.'en/about', - app('laravellocalization')->localizeURL($this->test_url.'about', 'en') + self::$testUrl.'en/about', + app('laravellocalization')->localizeURL(self::$testUrl.'about', 'en') ); app('config')->set('laravellocalization.hideDefaultLocaleInURL', false); $this->assertEquals( - $this->test_url.'en/about', - app('laravellocalization')->localizeURL($this->test_url.'about', 'en') + self::$testUrl.'en/about', + app('laravellocalization')->localizeURL(self::$testUrl.'about', 'en') ); $this->assertNotEquals( - $this->test_url.'about', - app('laravellocalization')->localizeURL($this->test_url.'about', 'en') + self::$testUrl.'about', + app('laravellocalization')->localizeURL(self::$testUrl.'about', 'en') ); } - public function testGetLocalizedURL() + public function testGetLocalizedURL(): void { $this->assertEquals( - $this->test_url.app('laravellocalization')->getCurrentLocale(), + self::$testUrl.app('laravellocalization')->getCurrentLocale(), app('laravellocalization')->getLocalizedURL() ); @@ -224,37 +225,37 @@ public function testGetLocalizedURL() // testing default language hidden $this->assertNotEquals( - $this->test_url.app('laravellocalization')->getDefaultLocale(), + self::$testUrl.app('laravellocalization')->getDefaultLocale(), app('laravellocalization')->getLocalizedURL() ); app('laravellocalization')->setLocale('es'); $this->assertNotEquals( - $this->test_url, + self::$testUrl, app('laravellocalization')->getLocalizedURL() ); $this->assertNotEquals( - $this->test_url.app('laravellocalization')->getDefaultLocale(), + self::$testUrl.app('laravellocalization')->getDefaultLocale(), app('laravellocalization')->getLocalizedURL() ); $this->assertEquals( - $this->test_url.app('laravellocalization')->getCurrentLocale(), + self::$testUrl.app('laravellocalization')->getCurrentLocale(), app('laravellocalization')->getLocalizedURL() ); $this->assertEquals( - $this->test_url.'es/acerca', - app('laravellocalization')->getLocalizedURL('es', $this->test_url.'about') + self::$testUrl.'es/acerca', + app('laravellocalization')->getLocalizedURL('es', self::$testUrl.'about') ); app('laravellocalization')->setLocale('en'); $crawler = $this->call( 'GET', - $this->test_url.'about', + self::$testUrl.'about', [], [], [], @@ -263,7 +264,7 @@ public function testGetLocalizedURL() $this->assertResponseOk(); $this->assertEquals( - $this->test_url.'es/acerca', + self::$testUrl.'es/acerca', $crawler->getContent() ); @@ -272,18 +273,18 @@ public function testGetLocalizedURL() app('config')->set('laravellocalization.hideDefaultLocaleInURL', true); $this->assertEquals( - $this->test_url.'test', - app('laravellocalization')->getLocalizedURL('en', $this->test_url.'test') + self::$testUrl.'test', + app('laravellocalization')->getLocalizedURL('en', self::$testUrl.'test') ); $this->assertEquals( - $this->test_url.'test?a=1', - app('laravellocalization')->getLocalizedURL('en', $this->test_url.'test?a=1') + self::$testUrl.'test?a=1', + app('laravellocalization')->getLocalizedURL('en', self::$testUrl.'test?a=1') ); $crawler = $this->call( 'GET', - app('laravellocalization')->getLocalizedURL('en', $this->test_url.'test'), + app('laravellocalization')->getLocalizedURL('en', self::$testUrl.'test'), [], [], [], @@ -299,17 +300,17 @@ public function testGetLocalizedURL() $this->refreshApplication('es'); $this->assertEquals( - $this->test_url.'es/test', - app('laravellocalization')->getLocalizedURL('es', $this->test_url.'test') + self::$testUrl.'es/test', + app('laravellocalization')->getLocalizedURL('es', self::$testUrl.'test') ); $this->assertEquals( - $this->test_url.'es/test?a=1', - app('laravellocalization')->getLocalizedURL('es', $this->test_url.'test?a=1') + self::$testUrl.'es/test?a=1', + app('laravellocalization')->getLocalizedURL('es', self::$testUrl.'test?a=1') ); } - public function testGetLocalizedURLWithQueryStringAndhideDefaultLocaleInURL() + public function testGetLocalizedURLWithQueryStringAndhideDefaultLocaleInURL(): void { app('config')->set('laravellocalization.hideDefaultLocaleInURL', true); $request = $this->createRequest( @@ -319,12 +320,12 @@ public function testGetLocalizedURLWithQueryStringAndhideDefaultLocaleInURL() $laravelLocalization->transRoute('LaravelLocalization::routes.about'); $this->assertEquals( - $this->test_url . 'about?q=2', + self::$testUrl . 'about?q=2', $laravelLocalization->getLocalizedURL() ); } - public function testGetLocalizedURLWithQueryStringAndNotTranslatedRoute() + public function testGetLocalizedURLWithQueryStringAndNotTranslatedRoute(): void { $request = $this->createRequest( $uri = 'en/about?q=2' @@ -332,7 +333,7 @@ public function testGetLocalizedURLWithQueryStringAndNotTranslatedRoute() $laravelLocalization = app(LaravelLocalization::class, ['request' => $request]); $this->assertEquals( - $this->test_url . 'en/about?q=2', + self::$testUrl . 'en/about?q=2', $laravelLocalization->getLocalizedURL() ); } @@ -340,10 +341,9 @@ public function testGetLocalizedURLWithQueryStringAndNotTranslatedRoute() /** * @param string $path * @param string|bool $expectedRouteName - * - * @dataProvider getRouteNameFromAPathDataProvider */ - public function testGetRouteNameFromAPath($path, $expectedRouteName) + #[DataProvider('getRouteNameFromAPathDataProvider')] + public function testGetRouteNameFromAPath($path, $expectedRouteName): void { $this->assertEquals( $expectedRouteName, @@ -351,29 +351,29 @@ public function testGetRouteNameFromAPath($path, $expectedRouteName) ); } - public function getRouteNameFromAPathDataProvider() + public static function getRouteNameFromAPathDataProvider(): array { return [ - [$this->test_url, false], - [$this->test_url.'es', false], - [$this->test_url.'en/about', 'LaravelLocalization::routes.about'], - [$this->test_url.'ver/1', false], - [$this->test_url.'view/1', 'LaravelLocalization::routes.view'], - [$this->test_url.'view/1/project', 'LaravelLocalization::routes.view_project'], - [$this->test_url.'view/1/project/1', 'LaravelLocalization::routes.view_project'], - [$this->test_url.'en/view/1/project/1', 'LaravelLocalization::routes.view_project'], - [$this->test_url.'manage/1', 'LaravelLocalization::routes.manage'], - [$this->test_url.'manage', 'LaravelLocalization::routes.manage'], - [$this->test_url.'manage/', 'LaravelLocalization::routes.manage'], - [$this->test_url.'manage/0', 'LaravelLocalization::routes.manage'], - [$this->test_url.'manage/0?ex=2&ex2=a', 'LaravelLocalization::routes.manage'], + [self::$testUrl, false], + [self::$testUrl.'es', false], + [self::$testUrl.'en/about', 'LaravelLocalization::routes.about'], + [self::$testUrl.'ver/1', false], + [self::$testUrl.'view/1', 'LaravelLocalization::routes.view'], + [self::$testUrl.'view/1/project', 'LaravelLocalization::routes.view_project'], + [self::$testUrl.'view/1/project/1', 'LaravelLocalization::routes.view_project'], + [self::$testUrl.'en/view/1/project/1', 'LaravelLocalization::routes.view_project'], + [self::$testUrl.'manage/1', 'LaravelLocalization::routes.manage'], + [self::$testUrl.'manage', 'LaravelLocalization::routes.manage'], + [self::$testUrl.'manage/', 'LaravelLocalization::routes.manage'], + [self::$testUrl.'manage/0', 'LaravelLocalization::routes.manage'], + [self::$testUrl.'manage/0?ex=2&ex2=a', 'LaravelLocalization::routes.manage'], ]; } - public function testGetLocalizedUrlForIgnoredUrls() { + public function testGetLocalizedUrlForIgnoredUrls(): void { $crawler = $this->call( 'GET', - $this->test_url2.'/skipped', + self::$testUrl2.'/skipped', [], [], [], @@ -382,7 +382,7 @@ public function testGetLocalizedUrlForIgnoredUrls() { $this->assertResponseOk(); $this->assertEquals( - $this->test_url2.'/skipped', + self::$testUrl2.'/skipped', $crawler->getContent() ); } @@ -393,10 +393,9 @@ public function testGetLocalizedUrlForIgnoredUrls() { * @param string $locale * @param string $path * @param string $expectedURL - * - * @dataProvider getLocalizedURLDataProvider */ - public function testGetLocalizedURLFormat($hideDefaultLocaleInURL, $forceDefault, $locale, $path, $expectedURL) + #[DataProvider('getLocalizedURLDataProvider')] + public function testGetLocalizedURLFormat($hideDefaultLocaleInURL, $forceDefault, $locale, $path, $expectedURL): void { app('config')->set('laravellocalization.hideDefaultLocaleInURL', $hideDefaultLocaleInURL); $this->assertEquals( @@ -406,212 +405,212 @@ public function testGetLocalizedURLFormat($hideDefaultLocaleInURL, $forceDefault } - public function getLocalizedURLDataProvider() + public static function getLocalizedURLDataProvider(): array { return [ // Do not hide default - [false, false, 'es', $this->test_url, $this->test_url.'es'], - [false, false, 'es', $this->test_url.'es', $this->test_url.'es'], - [false, false, 'es', $this->test_url.'en/about', $this->test_url.'es/acerca'], - [false, false, 'es', $this->test_url.'ver/1', $this->test_url.'es/ver/1'], - [false, false, 'es', $this->test_url.'view/1/project', $this->test_url.'es/ver/1/proyecto'], - [false, false, 'es', $this->test_url.'view/1/project/1', $this->test_url.'es/ver/1/proyecto/1'], - [false, false, 'es', $this->test_url.'en/view/1/project/1', $this->test_url.'es/ver/1/proyecto/1'], - [false, false, 'es', $this->test_url.'manage/1', $this->test_url.'es/administrar/1'], - [false, false, 'es', $this->test_url.'manage', $this->test_url.'es/administrar'], - [false, false, 'es', $this->test_url.'manage/', $this->test_url.'es/administrar'], - [false, false, 'es', $this->test_url.'manage/0', $this->test_url.'es/administrar/0'], - [false, false, 'es', $this->test_url.'manage/0?ex=2&ex2=a', $this->test_url.'es/administrar/0?ex=2&ex2=a'], + [false, false, 'es', self::$testUrl, self::$testUrl.'es'], + [false, false, 'es', self::$testUrl.'es', self::$testUrl.'es'], + [false, false, 'es', self::$testUrl.'en/about', self::$testUrl.'es/acerca'], + [false, false, 'es', self::$testUrl.'ver/1', self::$testUrl.'es/ver/1'], + [false, false, 'es', self::$testUrl.'view/1/project', self::$testUrl.'es/ver/1/proyecto'], + [false, false, 'es', self::$testUrl.'view/1/project/1', self::$testUrl.'es/ver/1/proyecto/1'], + [false, false, 'es', self::$testUrl.'en/view/1/project/1', self::$testUrl.'es/ver/1/proyecto/1'], + [false, false, 'es', self::$testUrl.'manage/1', self::$testUrl.'es/administrar/1'], + [false, false, 'es', self::$testUrl.'manage', self::$testUrl.'es/administrar'], + [false, false, 'es', self::$testUrl.'manage/', self::$testUrl.'es/administrar'], + [false, false, 'es', self::$testUrl.'manage/0', self::$testUrl.'es/administrar/0'], + [false, false, 'es', self::$testUrl.'manage/0?ex=2&ex2=a', self::$testUrl.'es/administrar/0?ex=2&ex2=a'], // Do not hide default - [false, false, 'en', $this->test_url.'en', $this->test_url.'en'], - [false, false, 'en', $this->test_url.'about', $this->test_url.'en/about'], - [false, false, 'en', $this->test_url.'ver/1', $this->test_url.'en/ver/1'], - [false, false, 'en', $this->test_url.'view/1/project', $this->test_url.'en/view/1/project'], - [false, false, 'en', $this->test_url.'view/1/project/1', $this->test_url.'en/view/1/project/1'], - [false, false, 'en', $this->test_url.'en/view/1/project/1', $this->test_url.'en/view/1/project/1'], - [false, false, 'en', $this->test_url.'manage/1', $this->test_url.'en/manage/1'], - [false, false, 'en', $this->test_url.'manage', $this->test_url.'en/manage'], - [false, false, 'en', $this->test_url.'manage/', $this->test_url.'en/manage'], - [false, false, 'en', $this->test_url.'manage/0', $this->test_url.'en/manage/0'], - [false, false, 'en', $this->test_url.'manage/0?ex=2&ex2=a', $this->test_url.'en/manage/0?ex=2&ex2=a'], + [false, false, 'en', self::$testUrl.'en', self::$testUrl.'en'], + [false, false, 'en', self::$testUrl.'about', self::$testUrl.'en/about'], + [false, false, 'en', self::$testUrl.'ver/1', self::$testUrl.'en/ver/1'], + [false, false, 'en', self::$testUrl.'view/1/project', self::$testUrl.'en/view/1/project'], + [false, false, 'en', self::$testUrl.'view/1/project/1', self::$testUrl.'en/view/1/project/1'], + [false, false, 'en', self::$testUrl.'en/view/1/project/1', self::$testUrl.'en/view/1/project/1'], + [false, false, 'en', self::$testUrl.'manage/1', self::$testUrl.'en/manage/1'], + [false, false, 'en', self::$testUrl.'manage', self::$testUrl.'en/manage'], + [false, false, 'en', self::$testUrl.'manage/', self::$testUrl.'en/manage'], + [false, false, 'en', self::$testUrl.'manage/0', self::$testUrl.'en/manage/0'], + [false, false, 'en', self::$testUrl.'manage/0?ex=2&ex2=a', self::$testUrl.'en/manage/0?ex=2&ex2=a'], // Hide default - [true, false, 'es', $this->test_url, $this->test_url.'es'], - [true, false, 'es', $this->test_url.'es', $this->test_url.'es'], - [true, false, 'es', $this->test_url.'en/about', $this->test_url.'es/acerca'], - [true, false, 'es', $this->test_url.'ver/1', $this->test_url.'es/ver/1'], - [true, false, 'es', $this->test_url.'view/1/project', $this->test_url.'es/ver/1/proyecto'], - [true, false, 'es', $this->test_url.'view/1/project/1', $this->test_url.'es/ver/1/proyecto/1'], - [true, false, 'es', $this->test_url.'en/view/1/project/1', $this->test_url.'es/ver/1/proyecto/1'], - [true, false, 'es', $this->test_url.'manage/1', $this->test_url.'es/administrar/1'], - [true, false, 'es', $this->test_url.'manage', $this->test_url.'es/administrar'], - [true, false, 'es', $this->test_url.'manage/', $this->test_url.'es/administrar'], - [true, false, 'es', $this->test_url.'manage/0', $this->test_url.'es/administrar/0'], - [true, false, 'es', $this->test_url.'manage/0?ex=2&ex2=a', $this->test_url.'es/administrar/0?ex=2&ex2=a'], + [true, false, 'es', self::$testUrl, self::$testUrl.'es'], + [true, false, 'es', self::$testUrl.'es', self::$testUrl.'es'], + [true, false, 'es', self::$testUrl.'en/about', self::$testUrl.'es/acerca'], + [true, false, 'es', self::$testUrl.'ver/1', self::$testUrl.'es/ver/1'], + [true, false, 'es', self::$testUrl.'view/1/project', self::$testUrl.'es/ver/1/proyecto'], + [true, false, 'es', self::$testUrl.'view/1/project/1', self::$testUrl.'es/ver/1/proyecto/1'], + [true, false, 'es', self::$testUrl.'en/view/1/project/1', self::$testUrl.'es/ver/1/proyecto/1'], + [true, false, 'es', self::$testUrl.'manage/1', self::$testUrl.'es/administrar/1'], + [true, false, 'es', self::$testUrl.'manage', self::$testUrl.'es/administrar'], + [true, false, 'es', self::$testUrl.'manage/', self::$testUrl.'es/administrar'], + [true, false, 'es', self::$testUrl.'manage/0', self::$testUrl.'es/administrar/0'], + [true, false, 'es', self::$testUrl.'manage/0?ex=2&ex2=a', self::$testUrl.'es/administrar/0?ex=2&ex2=a'], // Hide default - [true, false, 'en', $this->test_url.'en', $this->test_url.''], - [true, false, 'en', $this->test_url.'about', $this->test_url.'about'], - [true, false, 'en', $this->test_url.'ver/1', $this->test_url.'ver/1'], - [true, false, 'en', $this->test_url.'view/1/project', $this->test_url.'view/1/project'], - [true, false, 'en', $this->test_url.'view/1/project/1', $this->test_url.'view/1/project/1'], - [true, false, 'en', $this->test_url.'en/view/1/project/1', $this->test_url.'view/1/project/1'], - [true, false, 'en', $this->test_url.'manage/1', $this->test_url.'manage/1'], - [true, false, 'en', $this->test_url.'manage', $this->test_url.'manage'], - [true, false, 'en', $this->test_url.'manage/', $this->test_url.'manage'], - [true, false, 'en', $this->test_url.'manage/0', $this->test_url.'manage/0'], - [true, false, 'en', $this->test_url.'manage/0?ex=2&ex2=a', $this->test_url.'manage/0?ex=2&ex2=a'], + [true, false, 'en', self::$testUrl.'en', self::$testUrl.''], + [true, false, 'en', self::$testUrl.'about', self::$testUrl.'about'], + [true, false, 'en', self::$testUrl.'ver/1', self::$testUrl.'ver/1'], + [true, false, 'en', self::$testUrl.'view/1/project', self::$testUrl.'view/1/project'], + [true, false, 'en', self::$testUrl.'view/1/project/1', self::$testUrl.'view/1/project/1'], + [true, false, 'en', self::$testUrl.'en/view/1/project/1', self::$testUrl.'view/1/project/1'], + [true, false, 'en', self::$testUrl.'manage/1', self::$testUrl.'manage/1'], + [true, false, 'en', self::$testUrl.'manage', self::$testUrl.'manage'], + [true, false, 'en', self::$testUrl.'manage/', self::$testUrl.'manage'], + [true, false, 'en', self::$testUrl.'manage/0', self::$testUrl.'manage/0'], + [true, false, 'en', self::$testUrl.'manage/0?ex=2&ex2=a', self::$testUrl.'manage/0?ex=2&ex2=a'], // Do not hide default FORCE SHOWING - [false, true, 'es', $this->test_url, $this->test_url.'es'], - [false, true, 'es', $this->test_url.'es', $this->test_url.'es'], - [false, true, 'es', $this->test_url.'en/about', $this->test_url.'es/acerca'], - [false, true, 'es', $this->test_url.'ver/1', $this->test_url.'es/ver/1'], - [false, true, 'es', $this->test_url.'view/1/project', $this->test_url.'es/ver/1/proyecto'], - [false, true, 'es', $this->test_url.'view/1/project/1', $this->test_url.'es/ver/1/proyecto/1'], - [false, true, 'es', $this->test_url.'en/view/1/project/1', $this->test_url.'es/ver/1/proyecto/1'], - [false, true, 'es', $this->test_url.'manage/1', $this->test_url.'es/administrar/1'], - [false, true, 'es', $this->test_url.'manage', $this->test_url.'es/administrar'], - [false, true, 'es', $this->test_url.'manage/', $this->test_url.'es/administrar'], - [false, true, 'es', $this->test_url.'manage/0', $this->test_url.'es/administrar/0'], - [false, true, 'es', $this->test_url.'manage/0?ex=2&ex2=a', $this->test_url.'es/administrar/0?ex=2&ex2=a'], + [false, true, 'es', self::$testUrl, self::$testUrl.'es'], + [false, true, 'es', self::$testUrl.'es', self::$testUrl.'es'], + [false, true, 'es', self::$testUrl.'en/about', self::$testUrl.'es/acerca'], + [false, true, 'es', self::$testUrl.'ver/1', self::$testUrl.'es/ver/1'], + [false, true, 'es', self::$testUrl.'view/1/project', self::$testUrl.'es/ver/1/proyecto'], + [false, true, 'es', self::$testUrl.'view/1/project/1', self::$testUrl.'es/ver/1/proyecto/1'], + [false, true, 'es', self::$testUrl.'en/view/1/project/1', self::$testUrl.'es/ver/1/proyecto/1'], + [false, true, 'es', self::$testUrl.'manage/1', self::$testUrl.'es/administrar/1'], + [false, true, 'es', self::$testUrl.'manage', self::$testUrl.'es/administrar'], + [false, true, 'es', self::$testUrl.'manage/', self::$testUrl.'es/administrar'], + [false, true, 'es', self::$testUrl.'manage/0', self::$testUrl.'es/administrar/0'], + [false, true, 'es', self::$testUrl.'manage/0?ex=2&ex2=a', self::$testUrl.'es/administrar/0?ex=2&ex2=a'], // Do not hide default FORCE SHOWING - [false, true, 'en', $this->test_url.'en', $this->test_url.'en'], - [false, true, 'en', $this->test_url.'about', $this->test_url.'en/about'], - [false, true, 'en', $this->test_url.'ver/1', $this->test_url.'en/ver/1'], - [false, true, 'en', $this->test_url.'view/1/project', $this->test_url.'en/view/1/project'], - [false, true, 'en', $this->test_url.'view/1/project/1', $this->test_url.'en/view/1/project/1'], - [false, true, 'en', $this->test_url.'en/view/1/project/1', $this->test_url.'en/view/1/project/1'], - [false, true, 'en', $this->test_url.'manage/1', $this->test_url.'en/manage/1'], - [false, true, 'en', $this->test_url.'manage', $this->test_url.'en/manage'], - [false, true, 'en', $this->test_url.'manage/', $this->test_url.'en/manage'], - [false, true, 'en', $this->test_url.'manage/0', $this->test_url.'en/manage/0'], - [false, true, 'en', $this->test_url.'manage/0?ex=2&ex2=a', $this->test_url.'en/manage/0?ex=2&ex2=a'], + [false, true, 'en', self::$testUrl.'en', self::$testUrl.'en'], + [false, true, 'en', self::$testUrl.'about', self::$testUrl.'en/about'], + [false, true, 'en', self::$testUrl.'ver/1', self::$testUrl.'en/ver/1'], + [false, true, 'en', self::$testUrl.'view/1/project', self::$testUrl.'en/view/1/project'], + [false, true, 'en', self::$testUrl.'view/1/project/1', self::$testUrl.'en/view/1/project/1'], + [false, true, 'en', self::$testUrl.'en/view/1/project/1', self::$testUrl.'en/view/1/project/1'], + [false, true, 'en', self::$testUrl.'manage/1', self::$testUrl.'en/manage/1'], + [false, true, 'en', self::$testUrl.'manage', self::$testUrl.'en/manage'], + [false, true, 'en', self::$testUrl.'manage/', self::$testUrl.'en/manage'], + [false, true, 'en', self::$testUrl.'manage/0', self::$testUrl.'en/manage/0'], + [false, true, 'en', self::$testUrl.'manage/0?ex=2&ex2=a', self::$testUrl.'en/manage/0?ex=2&ex2=a'], // Hide default FORCE SHOWING - [true, true, 'es', $this->test_url, $this->test_url.'es'], - [true, true, 'es', $this->test_url.'es', $this->test_url.'es'], - [true, true, 'es', $this->test_url.'en/about', $this->test_url.'es/acerca'], - [true, true, 'es', $this->test_url.'ver/1', $this->test_url.'es/ver/1'], - [true, true, 'es', $this->test_url.'view/1/project', $this->test_url.'es/ver/1/proyecto'], - [true, true, 'es', $this->test_url.'view/1/project/1', $this->test_url.'es/ver/1/proyecto/1'], - [true, true, 'es', $this->test_url.'en/view/1/project/1', $this->test_url.'es/ver/1/proyecto/1'], - [true, true, 'es', $this->test_url.'manage/1', $this->test_url.'es/administrar/1'], - [true, true, 'es', $this->test_url.'manage', $this->test_url.'es/administrar'], - [true, true, 'es', $this->test_url.'manage/', $this->test_url.'es/administrar'], - [true, true, 'es', $this->test_url.'manage/0', $this->test_url.'es/administrar/0'], - [true, true, 'es', $this->test_url.'manage/0?ex=2&ex2=a', $this->test_url.'es/administrar/0?ex=2&ex2=a'], + [true, true, 'es', self::$testUrl, self::$testUrl.'es'], + [true, true, 'es', self::$testUrl.'es', self::$testUrl.'es'], + [true, true, 'es', self::$testUrl.'en/about', self::$testUrl.'es/acerca'], + [true, true, 'es', self::$testUrl.'ver/1', self::$testUrl.'es/ver/1'], + [true, true, 'es', self::$testUrl.'view/1/project', self::$testUrl.'es/ver/1/proyecto'], + [true, true, 'es', self::$testUrl.'view/1/project/1', self::$testUrl.'es/ver/1/proyecto/1'], + [true, true, 'es', self::$testUrl.'en/view/1/project/1', self::$testUrl.'es/ver/1/proyecto/1'], + [true, true, 'es', self::$testUrl.'manage/1', self::$testUrl.'es/administrar/1'], + [true, true, 'es', self::$testUrl.'manage', self::$testUrl.'es/administrar'], + [true, true, 'es', self::$testUrl.'manage/', self::$testUrl.'es/administrar'], + [true, true, 'es', self::$testUrl.'manage/0', self::$testUrl.'es/administrar/0'], + [true, true, 'es', self::$testUrl.'manage/0?ex=2&ex2=a', self::$testUrl.'es/administrar/0?ex=2&ex2=a'], // Hide default FORCE SHOWING - [true, true, 'en', $this->test_url.'en', $this->test_url.'en'], - [true, true, 'en', $this->test_url.'about', $this->test_url.'en/about'], - [true, true, 'en', $this->test_url.'ver/1', $this->test_url.'en/ver/1'], - [true, true, 'en', $this->test_url.'view/1/project', $this->test_url.'en/view/1/project'], - [true, true, 'en', $this->test_url.'view/1/project/1', $this->test_url.'en/view/1/project/1'], - [true, true, 'en', $this->test_url.'en/view/1/project/1', $this->test_url.'en/view/1/project/1'], - [true, true, 'en', $this->test_url.'manage/1', $this->test_url.'en/manage/1'], - [true, true, 'en', $this->test_url.'manage', $this->test_url.'en/manage'], - [true, true, 'en', $this->test_url.'manage/', $this->test_url.'en/manage'], - [true, true, 'en', $this->test_url.'manage/0', $this->test_url.'en/manage/0'], - [true, true, 'en', $this->test_url.'manage/0?ex=2&ex2=a', $this->test_url.'en/manage/0?ex=2&ex2=a'], + [true, true, 'en', self::$testUrl.'en', self::$testUrl.'en'], + [true, true, 'en', self::$testUrl.'about', self::$testUrl.'en/about'], + [true, true, 'en', self::$testUrl.'ver/1', self::$testUrl.'en/ver/1'], + [true, true, 'en', self::$testUrl.'view/1/project', self::$testUrl.'en/view/1/project'], + [true, true, 'en', self::$testUrl.'view/1/project/1', self::$testUrl.'en/view/1/project/1'], + [true, true, 'en', self::$testUrl.'en/view/1/project/1', self::$testUrl.'en/view/1/project/1'], + [true, true, 'en', self::$testUrl.'manage/1', self::$testUrl.'en/manage/1'], + [true, true, 'en', self::$testUrl.'manage', self::$testUrl.'en/manage'], + [true, true, 'en', self::$testUrl.'manage/', self::$testUrl.'en/manage'], + [true, true, 'en', self::$testUrl.'manage/0', self::$testUrl.'en/manage/0'], + [true, true, 'en', self::$testUrl.'manage/0?ex=2&ex2=a', self::$testUrl.'en/manage/0?ex=2&ex2=a'], ]; } - public function testGetURLFromRouteNameTranslated() + public function testGetURLFromRouteNameTranslated(): void { $this->assertEquals( - $this->test_url.'es/acerca', + self::$testUrl.'es/acerca', app('laravellocalization')->getURLFromRouteNameTranslated('es', 'LaravelLocalization::routes.about') ); $this->assertEquals( - $this->test_url.'en/about', + self::$testUrl.'en/about', app('laravellocalization')->getURLFromRouteNameTranslated('en', 'LaravelLocalization::routes.about') ); $this->assertEquals( - $this->test_url.'en/view/1', + self::$testUrl.'en/view/1', app('laravellocalization')->getURLFromRouteNameTranslated('en', 'LaravelLocalization::routes.view', ['id' => 1]) ); app('config')->set('laravellocalization.hideDefaultLocaleInURL', true); $this->assertEquals( - $this->test_url.'about', + self::$testUrl.'about', app('laravellocalization')->getURLFromRouteNameTranslated('en', 'LaravelLocalization::routes.about') ); $this->assertEquals( - $this->test_url.'es/acerca', + self::$testUrl.'es/acerca', app('laravellocalization')->getURLFromRouteNameTranslated('es', 'LaravelLocalization::routes.about') ); $this->assertEquals( - $this->test_url.'es/ver/1', + self::$testUrl.'es/ver/1', app('laravellocalization')->getURLFromRouteNameTranslated('es', 'LaravelLocalization::routes.view', ['id' => 1]) ); $this->assertEquals( - $this->test_url.'view/1', + self::$testUrl.'view/1', app('laravellocalization')->getURLFromRouteNameTranslated('en', 'LaravelLocalization::routes.view', ['id' => 1]) ); $this->assertNotEquals( - $this->test_url.'en/view/1', + self::$testUrl.'en/view/1', app('laravellocalization')->getURLFromRouteNameTranslated('en', 'LaravelLocalization::routes.view', ['id' => 1]) ); app('config')->set('laravellocalization.hideDefaultLocaleInURL', false); $this->assertNotEquals( - $this->test_url.'view/1', + self::$testUrl.'view/1', app('laravellocalization')->getURLFromRouteNameTranslated('en', 'LaravelLocalization::routes.view', ['id' => 1]) ); $this->assertEquals( - $this->test_url.'en/view/1', + self::$testUrl.'en/view/1', app('laravellocalization')->getURLFromRouteNameTranslated('en', 'LaravelLocalization::routes.view', ['id' => 1]) ); } - public function testLocalizedParameterFromTranslateUrl() + public function testLocalizedParameterFromTranslateUrl(): void { $model = new ModelWithTranslatableRoutes(); $this->assertEquals( - $this->test_url.'en/view/company', + self::$testUrl.'en/view/company', app('laravellocalization')->getURLFromRouteNameTranslated('en', 'LaravelLocalization::routes.view', ['id' => $model]) ); $this->assertEquals( - $this->test_url.'es/ver/empresa', + self::$testUrl.'es/ver/empresa', app('laravellocalization')->getURLFromRouteNameTranslated('es', 'LaravelLocalization::routes.view', ['id' => $model]) ); } - public function testGetNonLocalizedURL() + public function testGetNonLocalizedURL(): void { $this->assertEquals( - $this->test_url, - app('laravellocalization')->getNonLocalizedURL($this->test_url.'en') + self::$testUrl, + app('laravellocalization')->getNonLocalizedURL(self::$testUrl.'en') ); $this->assertEquals( - $this->test_url, - app('laravellocalization')->getNonLocalizedURL($this->test_url.'es') + self::$testUrl, + app('laravellocalization')->getNonLocalizedURL(self::$testUrl.'es') ); $this->assertEquals( - $this->test_url.'view/1', - app('laravellocalization')->getNonLocalizedURL($this->test_url.'en/view/1') + self::$testUrl.'view/1', + app('laravellocalization')->getNonLocalizedURL(self::$testUrl.'en/view/1') ); $this->assertEquals( - $this->test_url.'ver/1', - app('laravellocalization')->getNonLocalizedURL($this->test_url.'es/ver/1') + self::$testUrl.'ver/1', + app('laravellocalization')->getNonLocalizedURL(self::$testUrl.'es/ver/1') ); } - public function testGetDefaultLocale() + public function testGetDefaultLocale(): void { $this->assertEquals( 'en', @@ -627,7 +626,7 @@ public function testGetDefaultLocale() ); } - public function testGetSupportedLocales() + public function testGetSupportedLocales(): void { $this->assertEquals( $this->supportedLocales, @@ -635,7 +634,7 @@ public function testGetSupportedLocales() ); } - public function testGetCurrentLocaleName() + public function testGetCurrentLocaleName(): void { $this->assertEquals( 'English', @@ -650,7 +649,7 @@ public function testGetCurrentLocaleName() ); } - public function testGetCurrentLocaleRegional() + public function testGetCurrentLocaleRegional(): void { $this->assertEquals( 'en_GB', @@ -665,7 +664,7 @@ public function testGetCurrentLocaleRegional() ); } - public function testGetCurrentLocaleDirection() + public function testGetCurrentLocaleDirection(): void { $this->assertEquals( 'ltr', @@ -681,7 +680,7 @@ public function testGetCurrentLocaleDirection() ); } - public function testGetCurrentLocaleScript() + public function testGetCurrentLocaleScript(): void { app('laravellocalization')->setLocale('es'); $this->refreshApplication('es'); @@ -700,7 +699,7 @@ public function testGetCurrentLocaleScript() ); } - public function testGetCurrentLocaleNativeReading() + public function testGetCurrentLocaleNativeReading(): void { $this->assertEquals( 'English', @@ -716,7 +715,7 @@ public function testGetCurrentLocaleNativeReading() ); } - public function testGetCurrentLocale() + public function testGetCurrentLocale(): void { $this->assertEquals( 'en', @@ -737,7 +736,7 @@ public function testGetCurrentLocale() ); } - public function testGetSupportedLanguagesKeys() + public function testGetSupportedLanguagesKeys(): void { $this->assertEquals( ['en', 'es'], @@ -745,7 +744,7 @@ public function testGetSupportedLanguagesKeys() ); } - public function testGetConfigRepository() + public function testGetConfigRepository(): void { $this->assertEquals( app('config'), @@ -753,7 +752,7 @@ public function testGetConfigRepository() ); } - public function testCreateUrlFromUri() + public function testCreateUrlFromUri(): void { $this->assertEquals( 'http://localhost/view/1', @@ -770,10 +769,8 @@ public function testCreateUrlFromUri() } - /** - * @dataProvider accept_language_variations_data - */ - public function testLanguageNegotiation($accept_string, $must_resolve_to, $asd = null) { + #[DataProvider('accept_language_variations_data')] + public function testLanguageNegotiation($accept_string, $must_resolve_to, $asd = null): void { $full_config = include __DIR__ . '/full-config/config.php'; @@ -795,7 +792,7 @@ public function testLanguageNegotiation($accept_string, $must_resolve_to, $asd = } - public function accept_language_variations_data() { + public static function accept_language_variations_data(): array { $variations = [ ['en-GB', 'en-GB'], ['en-US', 'en-US'], @@ -816,7 +813,7 @@ public function accept_language_variations_data() { return $dataset; } - public function testLanguageNegotiationWithMapping() { + public function testLanguageNegotiationWithMapping(): void { $accept_string = 'en-GB'; $must_resolve_to = 'uk'; @@ -848,7 +845,7 @@ public function testLanguageNegotiationWithMapping() { $this->assertEquals($must_resolve_to, $language); } - public function testSetLocaleWithMapping() + public function testSetLocaleWithMapping(): void { app('config')->set('laravellocalization.localesMapping', [ 'en' => 'custom',