From 4ea66d814fe3303a97560797110be439d007c668 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 22 Jun 2024 13:22:58 +0300 Subject: [PATCH 1/2] Removed extra trait from tests --- tests/Concerns/Routes.php | 101 -------------------------------------- tests/TestCase.php | 96 +++++++++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 103 deletions(-) delete mode 100644 tests/Concerns/Routes.php diff --git a/tests/Concerns/Routes.php b/tests/Concerns/Routes.php deleted file mode 100644 index c1a7542..0000000 --- a/tests/Concerns/Routes.php +++ /dev/null @@ -1,101 +0,0 @@ -middleware('web') - ->group(function () { - app('router') - ->middleware(LocalizationByParameter::class) - ->get('path/{foo}/{locale?}', $this->jsonResponse()) - ->name('via.parameter'); - - app('router') - ->middleware(LocalizationByParameterWithRedirect::class) - ->get('redirect/{foo}/{locale?}', $this->jsonResponse()) - ->name('via.parameter.redirect'); - - app('router') - ->middleware(LocalizationByParameterWithRedirect::class) - ->get('not-named/redirect/{foo}/{locale?}', $this->jsonResponse()); - - app('router') - ->middleware(LocalizationByHeader::class) - ->get('header/{foo}', $this->jsonResponse()) - ->name('via.header'); - - app('router') - ->middleware(LocalizationByCookie::class) - ->get('cookie/{foo}', $this->jsonResponse()) - ->name('via.cookie'); - - app('router') - ->middleware(LocalizationBySession::class) - ->get('session/{foo}', $this->jsonResponse()) - ->name('via.session'); - - app('router') - ->middleware(LocalizationByModel::class) - ->get('model/default/{foo}', $this->jsonResponse()) - ->name('via.model.default'); - - app('router') - ->middleware(LocalizationByModel::class . ':foo') - ->get('model/guard/{foo}', $this->jsonResponse()) - ->name('via.model.guard'); - - app('router') - ->middleware([ - LocalizationByParameter::class, - LocalizationByParameterWithRedirect::class, - LocalizationByHeader::class, - LocalizationByCookie::class, - LocalizationBySession::class, - LocalizationByModel::class, - ]) - ->get('clean/{foo}', $this->jsonResponse()) - ->name('clean'); - }); - - app('router')->localizedGroup(function () { - app('router') - ->middleware('web') - ->get('group/macro/{foo}', $this->jsonResponse()) - ->name('via.group.macro'); - }); - - LocalizationRoute::group(function () { - app('router') - ->middleware('web') - ->get('group/facade/{foo}', $this->jsonResponse()) - ->name('via.group.facade'); - }); - } - - protected function jsonResponse(): Closure - { - return fn (string $foo) => response()->json([ - $foo => __(LocaleValue::TranslationKey), - ]); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index bf0a85d..2407f7e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,18 +2,24 @@ namespace Tests; +use Closure; use LaravelLang\Config\Enums\Name; use LaravelLang\Config\ServiceProvider as ConfigServiceProvider; use LaravelLang\Locales\ServiceProvider as LocalesServiceProvider; +use LaravelLang\Routes\Facades\LocalizationRoute; +use LaravelLang\Routes\Middlewares\LocalizationByCookie; +use LaravelLang\Routes\Middlewares\LocalizationByHeader; +use LaravelLang\Routes\Middlewares\LocalizationByModel; +use LaravelLang\Routes\Middlewares\LocalizationByParameter; +use LaravelLang\Routes\Middlewares\LocalizationByParameterWithRedirect; +use LaravelLang\Routes\Middlewares\LocalizationBySession; use LaravelLang\Routes\ServiceProvider; use Orchestra\Testbench\TestCase as BaseTestCase; use Tests\Concerns\Locales; -use Tests\Concerns\Routes; use Tests\Constants\LocaleValue; abstract class TestCase extends BaseTestCase { - use Routes; use Locales; protected function getPackageProviders($app): array @@ -46,4 +52,90 @@ protected function defineDatabaseMigrations(): void { $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); } + + /** + * Define routes setup. + * + * @param \Illuminate\Routing\Router $router + * + * @return void + */ + protected function defineRoutes($router): void + { + $router + ->middleware('web') + ->group(function () use ($router) { + $router + ->middleware(LocalizationByParameter::class) + ->get('path/{foo}/{locale?}', $this->jsonResponse()) + ->name('via.parameter'); + + $router + ->middleware(LocalizationByParameterWithRedirect::class) + ->get('redirect/{foo}/{locale?}', $this->jsonResponse()) + ->name('via.parameter.redirect'); + + $router + ->middleware(LocalizationByParameterWithRedirect::class) + ->get('not-named/redirect/{foo}/{locale?}', $this->jsonResponse()); + + $router + ->middleware(LocalizationByHeader::class) + ->get('header/{foo}', $this->jsonResponse()) + ->name('via.header'); + + $router + ->middleware(LocalizationByCookie::class) + ->get('cookie/{foo}', $this->jsonResponse()) + ->name('via.cookie'); + + $router + ->middleware(LocalizationBySession::class) + ->get('session/{foo}', $this->jsonResponse()) + ->name('via.session'); + + $router + ->middleware(LocalizationByModel::class) + ->get('model/default/{foo}', $this->jsonResponse()) + ->name('via.model.default'); + + $router + ->middleware(LocalizationByModel::class . ':foo') + ->get('model/guard/{foo}', $this->jsonResponse()) + ->name('via.model.guard'); + + $router + ->middleware([ + LocalizationByParameter::class, + LocalizationByParameterWithRedirect::class, + LocalizationByHeader::class, + LocalizationByCookie::class, + LocalizationBySession::class, + LocalizationByModel::class, + ]) + ->get('clean/{foo}', $this->jsonResponse()) + ->name('clean'); + }); + + $router->localizedGroup(function () use ($router) { + $router + ->middleware('web') + ->get('group/macro/{foo}', $this->jsonResponse()) + ->name('via.group.macro'); + }); + + LocalizationRoute::group(function () use ($router) { + $router + ->middleware('web') + ->get('group/facade/{foo}', $this->jsonResponse()) + ->name('via.group.facade'); + }); + } + + protected function jsonResponse(): Closure + { + return fn (string $foo) => response()->json([ + $foo => __(LocaleValue::TranslationKey), + ]); + } } From 219a88bd51eac36f7a66202002931f2f8835fb5d Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 22 Jun 2024 13:23:44 +0300 Subject: [PATCH 2/2] Fixed code-style --- tests/TestCase.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 2407f7e..99f175d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -57,8 +57,6 @@ protected function defineDatabaseMigrations(): void * Define routes setup. * * @param \Illuminate\Routing\Router $router - * - * @return void */ protected function defineRoutes($router): void {