From e98d1785ad51dde1a50ebf0144ef53622eec4bf8 Mon Sep 17 00:00:00 2001 From: Evgeny Ulin Date: Mon, 3 Jun 2024 13:17:01 +0300 Subject: [PATCH 1/2] #82: Moved status api out of versioning routes. --- routes/api.php | 6 ++++-- tests/StatusTest.php | 4 ++-- tests/TestCase.php | 9 ++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/routes/api.php b/routes/api.php index 70321e9..43ab890 100755 --- a/routes/api.php +++ b/routes/api.php @@ -43,8 +43,10 @@ Route::post('auth/forgot-password', [AuthController::class, 'forgotPassword']); Route::post('auth/restore-password', [AuthController::class, 'restorePassword']); Route::post('auth/token/check', [AuthController::class, 'checkRestoreToken']); - - Route::get('status', [StatusController::class, 'status']); }); }); }); + +Route::group(['middleware' => 'guest_group'], function () { + Route::get('status', [StatusController::class, 'status']); +}); diff --git a/tests/StatusTest.php b/tests/StatusTest.php index 537a0e7..4b73268 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -10,7 +10,7 @@ class StatusTest extends TestCase { public function testStatusOk() { - $response = $this->json('get', '/status'); + $response = $this->json('get', '/status', [], [], 0, false); $response->assertOk(); } @@ -23,7 +23,7 @@ public function testStatusServiceUnavailable() DB::shouldReceive('connection')->andReturn($connection); DB::shouldReceive('getPdo')->andThrow(Exception::class); - $response = $this->json('get', '/status'); + $response = $this->json('get', '/status', [], [], 0, false); $response->assertStatus(Response::HTTP_SERVICE_UNAVAILABLE); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 4c31d28..c7a42e5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -67,10 +67,13 @@ public function call($method, $uri, $parameters = [], $cookies = [], $files = [] return parent::call($method, $uri, $parameters, $cookies, $files, $server, $content); } - public function json($method, $uri, array $data = [], array $headers = [], $options = 0, ?VersionEnum $apiVersion = null): TestResponse + public function json($method, $uri, array $data = [], array $headers = [], $options = 0, VersionEnum|bool|null $apiVersion = null): TestResponse { - $apiVersion = (empty($apiVersion)) ? last(VersionEnum::values()) : $apiVersion->value; + if ($apiVersion !== false) { + $apiVersion = (empty($apiVersion)) ? last(VersionEnum::values()) : $apiVersion->value; + $uri = "/v{$apiVersion}{$uri}"; + } - return parent::json($method, "/v{$apiVersion}{$uri}", $data, $headers); + return parent::json($method, $uri, $data, $headers); } } From e86fd4a9de513a8c02b5079b03a946712859ed31 Mon Sep 17 00:00:00 2001 From: Evgeny Ulin Date: Tue, 4 Jun 2024 17:54:02 +0300 Subject: [PATCH 2/2] #82: Used get method for state tests instead of extending json method. --- tests/StatusTest.php | 4 ++-- tests/TestCase.php | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/StatusTest.php b/tests/StatusTest.php index 4b73268..b313376 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -10,7 +10,7 @@ class StatusTest extends TestCase { public function testStatusOk() { - $response = $this->json('get', '/status', [], [], 0, false); + $response = $this->get('/status'); $response->assertOk(); } @@ -23,7 +23,7 @@ public function testStatusServiceUnavailable() DB::shouldReceive('connection')->andReturn($connection); DB::shouldReceive('getPdo')->andThrow(Exception::class); - $response = $this->json('get', '/status', [], [], 0, false); + $response = $this->get('/status'); $response->assertStatus(Response::HTTP_SERVICE_UNAVAILABLE); } diff --git a/tests/TestCase.php b/tests/TestCase.php index c7a42e5..4c31d28 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -67,13 +67,10 @@ public function call($method, $uri, $parameters = [], $cookies = [], $files = [] return parent::call($method, $uri, $parameters, $cookies, $files, $server, $content); } - public function json($method, $uri, array $data = [], array $headers = [], $options = 0, VersionEnum|bool|null $apiVersion = null): TestResponse + public function json($method, $uri, array $data = [], array $headers = [], $options = 0, ?VersionEnum $apiVersion = null): TestResponse { - if ($apiVersion !== false) { - $apiVersion = (empty($apiVersion)) ? last(VersionEnum::values()) : $apiVersion->value; - $uri = "/v{$apiVersion}{$uri}"; - } + $apiVersion = (empty($apiVersion)) ? last(VersionEnum::values()) : $apiVersion->value; - return parent::json($method, $uri, $data, $headers); + return parent::json($method, "/v{$apiVersion}{$uri}", $data, $headers); } }