Skip to content

Commit

Permalink
Fixed cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Jun 9, 2024
1 parent 328ca8e commit 4755742
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Middlewares/CookiesLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Middlewares/HeaderLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Middlewares/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Middlewares/ParameterLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Middlewares/ParameterRedirectLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Middlewares/SessionLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 11 additions & 6 deletions tests/Feature/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 4755742

Please sign in to comment.