diff --git a/src/Middlewares/CookiesLocale.php b/src/Middlewares/CookiesLocale.php index 060fd4c..a44e9b0 100644 --- a/src/Middlewares/CookiesLocale.php +++ b/src/Middlewares/CookiesLocale.php @@ -8,7 +8,7 @@ class CookiesLocale extends Middleware { - protected function detect(Request $request): string|int|float|bool|null + protected function detect(Request $request): bool|float|int|string|null { return $request->cookie($this->names()->cookie); } diff --git a/src/Middlewares/HeaderLocale.php b/src/Middlewares/HeaderLocale.php index fe60dcf..bf0feba 100644 --- a/src/Middlewares/HeaderLocale.php +++ b/src/Middlewares/HeaderLocale.php @@ -8,7 +8,7 @@ class HeaderLocale extends Middleware { - protected function detect(Request $request): string|int|float|bool|null + protected function detect(Request $request): bool|float|int|string|null { return $request->header($this->names()->header); } diff --git a/src/Middlewares/Middleware.php b/src/Middlewares/Middleware.php index 31578b3..208e8c6 100644 --- a/src/Middlewares/Middleware.php +++ b/src/Middlewares/Middleware.php @@ -15,7 +15,7 @@ abstract class Middleware { use KeyNames; - abstract protected function detect(Request $request): string|int|float|bool|null; + abstract protected function detect(Request $request): bool|float|int|string|null; public function __invoke(Request $request, Closure $next) { diff --git a/src/Middlewares/ParameterLocale.php b/src/Middlewares/ParameterLocale.php index e948c4e..d61652e 100644 --- a/src/Middlewares/ParameterLocale.php +++ b/src/Middlewares/ParameterLocale.php @@ -8,7 +8,7 @@ class ParameterLocale extends Middleware { - protected function detect(Request $request): string|int|float|bool|null + protected function detect(Request $request): bool|float|int|string|null { return $request->route()->parameter($this->names()->parameter); } diff --git a/src/Middlewares/ParameterRedirectLocale.php b/src/Middlewares/ParameterRedirectLocale.php index beb867e..424d32f 100644 --- a/src/Middlewares/ParameterRedirectLocale.php +++ b/src/Middlewares/ParameterRedirectLocale.php @@ -26,7 +26,7 @@ public function __invoke(Request $request, Closure $next) return parent::__invoke($request, $next); } - protected function detect(Request $request): string|int|float|bool|null + protected function detect(Request $request): bool|float|int|string|null { return $request->route()?->parameter($this->names()->parameter); } @@ -60,7 +60,7 @@ protected function defaultLocale(): string return Locales::getDefault()->code; } - protected function isInstalled(string|int|float|bool|null $parameter): bool + protected function isInstalled(bool|float|int|string|null $parameter): bool { return Locales::isInstalled((string) $parameter); } diff --git a/src/Middlewares/SessionLocale.php b/src/Middlewares/SessionLocale.php index 3495d0c..e849e9f 100644 --- a/src/Middlewares/SessionLocale.php +++ b/src/Middlewares/SessionLocale.php @@ -8,7 +8,7 @@ class SessionLocale extends Middleware { - protected function detect(Request $request): string|int|float|bool|null + protected function detect(Request $request): bool|float|int|string|null { return $request->getSession()->get($this->names()->session); } diff --git a/src/Services/Resolver.php b/src/Services/Resolver.php index 5634e4b..a0fcd04 100644 --- a/src/Services/Resolver.php +++ b/src/Services/Resolver.php @@ -8,7 +8,7 @@ class Resolver { - public static function locale(string|int|float|bool|null $locale): string + public static function locale(bool|float|int|string|null $locale): string { return Locales::get($locale)->code ?? Locales::getDefault()->code; } diff --git a/tests/Feature/CookieTest.php b/tests/Feature/CookieTest.php index 227e617..7001a62 100644 --- a/tests/Feature/CookieTest.php +++ b/tests/Feature/CookieTest.php @@ -5,12 +5,13 @@ use LaravelLang\Config\Facades\Config; use Tests\Constants\LocaleValue; -use function Pest\Laravel\withCookie; +use function Pest\Laravel\withCredentials; test('main locale', function (string $locale) { $time = time(); - withCookie(Config::shared()->routes->names->cookie, $locale) + withCredentials() + ->withCookie(Config::shared()->routes->names->cookie, $locale) ->getJson(route('via.cookie', compact('time'))) ->assertSuccessful() ->assertJsonPath('message', LocaleValue::TranslationFrench) @@ -20,7 +21,8 @@ test('aliased locale', function (string $locale) { $time = time(); - withCookie(Config::shared()->routes->names->cookie, $locale) + withCredentials() + ->withCookie(Config::shared()->routes->names->cookie, $locale) ->getJson(route('via.cookie', compact('time'))) ->assertSuccessful() ->assertJsonPath('message', LocaleValue::TranslationGerman) @@ -30,7 +32,8 @@ test('empty locale', function (int|string|null $locale) { $time = time(); - withCookie(Config::shared()->routes->names->cookie, (string) $locale) + withCredentials() + ->withCookie(Config::shared()->routes->names->cookie, (string) $locale) ->getJson(route('via.cookie', compact('time'))) ->assertSuccessful() ->assertJsonPath('message', LocaleValue::TranslationFrench) @@ -40,7 +43,8 @@ test('uninstalled locale', function (string $locale) { $time = time(); - withCookie(Config::shared()->routes->names->cookie, (string) $locale) + withCredentials() + ->withCookie(Config::shared()->routes->names->cookie, $locale) ->getJson(route('via.cookie', compact('time'))) ->assertSuccessful() ->assertJsonPath('message', LocaleValue::TranslationFrench) @@ -50,7 +54,8 @@ test('unknown locale', function (int|string $locale) { $time = time(); - withCookie(Config::shared()->routes->names->cookie, (string) $locale) + withCredentials() + ->withCookie(Config::shared()->routes->names->cookie, (string) $locale) ->getJson(route('via.cookie', compact('time'))) ->assertSuccessful() ->assertJsonPath('message', LocaleValue::TranslationFrench)