From f7584d3f93d3de1c94d175d17c9d22c6fd225e7b Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 10:21:32 +1100 Subject: [PATCH 01/23] Extract status assertions to trait --- .../Testing/Concerns/AssertsStatusCodes.php | 83 +++++++++++++++++++ src/Illuminate/Testing/TestResponse.php | 77 +---------------- 2 files changed, 84 insertions(+), 76 deletions(-) create mode 100644 src/Illuminate/Testing/Concerns/AssertsStatusCodes.php diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php new file mode 100644 index 000000000000..29e574918e7d --- /dev/null +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -0,0 +1,83 @@ +assertStatus(200); + } + + /** + * Assert that the response has a 201 status code. + * + * @return $this + */ + public function assertCreated() + { + return $this->assertStatus(201); + } + + /** + * Assert that the response has the given status code and no content. + * + * @param int $status + * @return $this + */ + public function assertNoContent($status = 204) + { + $this->assertStatus($status); + + PHPUnit::assertEmpty($this->getContent(), 'Response content is not empty.'); + + return $this; + } + + /** + * Assert that the response has an unauthorized status code. + * + * @return $this + */ + public function assertUnauthorized() + { + return $this->assertStatus(401); + } + + /** + * Assert that the response has a forbidden status code. + * + * @return $this + */ + public function assertForbidden() + { + return $this->assertStatus(403); + } + + /** + * Assert that the response has a not found status code. + * + * @return $this + */ + public function assertNotFound() + { + return $this->assertStatus(404); + } + + /** + * Assert that the response has a 422 status code. + * + * @return $this + */ + public function assertUnprocessable() + { + return $this->assertStatus(422); + } +} diff --git a/src/Illuminate/Testing/TestResponse.php b/src/Illuminate/Testing/TestResponse.php index 5c59ccfa4131..630fbb87a590 100644 --- a/src/Illuminate/Testing/TestResponse.php +++ b/src/Illuminate/Testing/TestResponse.php @@ -32,7 +32,7 @@ */ class TestResponse implements ArrayAccess { - use Tappable, Macroable { + use Concerns\AssertsStatusCodes, Tappable, Macroable { __call as macroCall; } @@ -95,81 +95,6 @@ public function assertSuccessful() return $this; } - /** - * Assert that the response has a 200 status code. - * - * @return $this - */ - public function assertOk() - { - return $this->assertStatus(200); - } - - /** - * Assert that the response has a 201 status code. - * - * @return $this - */ - public function assertCreated() - { - return $this->assertStatus(201); - } - - /** - * Assert that the response has the given status code and no content. - * - * @param int $status - * @return $this - */ - public function assertNoContent($status = 204) - { - $this->assertStatus($status); - - PHPUnit::assertEmpty($this->getContent(), 'Response content is not empty.'); - - return $this; - } - - /** - * Assert that the response has a not found status code. - * - * @return $this - */ - public function assertNotFound() - { - return $this->assertStatus(404); - } - - /** - * Assert that the response has a forbidden status code. - * - * @return $this - */ - public function assertForbidden() - { - return $this->assertStatus(403); - } - - /** - * Assert that the response has an unauthorized status code. - * - * @return $this - */ - public function assertUnauthorized() - { - return $this->assertStatus(401); - } - - /** - * Assert that the response has a 422 status code. - * - * @return $this - */ - public function assertUnprocessable() - { - return $this->assertStatus(422); - } - /** * Assert that the response is a server error. * From 0e4748fd9c7ba56d926f2d12646bb069d66cfd7a Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 10:35:49 +1100 Subject: [PATCH 02/23] Adds bad request status assertion --- .../Testing/Concerns/AssertsStatusCodes.php | 10 ++++++++++ tests/Testing/TestResponseTest.php | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index 29e574918e7d..bf75db44cdec 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -41,6 +41,16 @@ public function assertNoContent($status = 204) return $this; } + /** + * Assert that the response has a bad request status code. + * + * @return $this + */ + public function assertBadRequest() + { + return $this->assertStatus(400); + } + /** * Assert that the response has an unauthorized status code. * diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 3a375d6c845c..1f29b935c27b 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -593,6 +593,25 @@ public function testAssertUnauthorized() $response->assertUnauthorized(); } + public function testAssertBadRequest() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_BAD_REQUEST) + ); + + $response->assertBadRequest(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [400] but received 200.\nFailed asserting that 400 is identical to 200."); + + $response->assertBadRequest(); + $this->fail(); + } + public function testAssertUnprocessable() { $statusCode = 500; From 4c749e8e5e50b295e015183ba55d8629b9312b51 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 10:40:59 +1100 Subject: [PATCH 03/23] Adds request timeout status assertion --- .../Testing/Concerns/AssertsStatusCodes.php | 10 ++++++++++ tests/Testing/TestResponseTest.php | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index bf75db44cdec..08f917eef25d 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -81,6 +81,16 @@ public function assertNotFound() return $this->assertStatus(404); } + /** + * Assert that the response has a request timeout status code. + * + * @return $this + */ + public function assertRequestTimeout() + { + return $this->assertStatus(408); + } + /** * Assert that the response has a 422 status code. * diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 1f29b935c27b..95c04fe80d2f 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -612,6 +612,25 @@ public function testAssertBadRequest() $this->fail(); } + public function testAssertRequestTimeout() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_REQUEST_TIMEOUT) + ); + + $response->assertRequestTimeout(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [408] but received 200.\nFailed asserting that 408 is identical to 200."); + + $response->assertRequestTimeout(); + $this->fail(); + } + public function testAssertUnprocessable() { $statusCode = 500; From 7b3f06753e08053fcc25efdca42ebf14b48db262 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 10:43:35 +1100 Subject: [PATCH 04/23] Adds payment required status assertion --- .../Testing/Concerns/AssertsStatusCodes.php | 10 ++++++++++ tests/Testing/TestResponseTest.php | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index 08f917eef25d..4ccf22e83a08 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -61,6 +61,16 @@ public function assertUnauthorized() return $this->assertStatus(401); } + /** + * Assert that the response has a payment required status code. + * + * @return $this + */ + public function assertPaymentRequired() + { + return $this->assertStatus(402); + } + /** * Assert that the response has a forbidden status code. * diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 95c04fe80d2f..41312b2f910b 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -631,6 +631,25 @@ public function testAssertRequestTimeout() $this->fail(); } + public function testAssertPaymetRequired() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_PAYMENT_REQUIRED) + ); + + $response->assertPaymentRequired(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [402] but received 200.\nFailed asserting that 402 is identical to 200."); + + $response->assertPaymentRequired(); + $this->fail(); + } + public function testAssertUnprocessable() { $statusCode = 500; From 4c3c8cf16723cba64ce04c400ae977876b6c4629 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 10:47:41 +1100 Subject: [PATCH 05/23] Adds accepted status assertion --- .../Testing/Concerns/AssertsStatusCodes.php | 10 ++++++++++ tests/Testing/TestResponseTest.php | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index 4ccf22e83a08..c8056a3e72d7 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -26,6 +26,16 @@ public function assertCreated() return $this->assertStatus(201); } + /** + * Assert that the response has an accepted status code. + * + * @return $this + */ + public function assertAccepted() + { + return $this->assertStatus(202); + } + /** * Assert that the response has the given status code and no content. * diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 41312b2f910b..9bcee0a25db1 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -650,6 +650,25 @@ public function testAssertPaymetRequired() $this->fail(); } + public function testAssertAccepted() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_ACCEPTED) + ); + + $response->assertAccepted(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [202] but received 200.\nFailed asserting that 202 is identical to 200."); + + $response->assertAccepted(); + $this->fail(); + } + public function testAssertUnprocessable() { $statusCode = 500; From 41402030eef7e3634d38713634ac3033aaa5cdef Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 10:50:50 +1100 Subject: [PATCH 06/23] Adds moved permanently status code --- .../Testing/Concerns/AssertsStatusCodes.php | 11 +++++++++++ tests/Testing/TestResponseTest.php | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index c8056a3e72d7..5f238b3d2670 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -51,6 +51,17 @@ public function assertNoContent($status = 204) return $this; } + /** + * Assert that the response has a moved permanently status code. + * + * @param int $status + * @return $this + */ + public function assertMovedPermanently() + { + return $this->assertStatus(301); + } + /** * Assert that the response has a bad request status code. * diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 9bcee0a25db1..dc98befb08c4 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -650,6 +650,25 @@ public function testAssertPaymetRequired() $this->fail(); } + public function testAssertMovedPermanently() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_MOVED_PERMANENTLY) + ); + + $response->assertMovedPermanently(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [301] but received 200.\nFailed asserting that 301 is identical to 200."); + + $response->assertMovedPermanently(); + $this->fail(); + } + public function testAssertAccepted() { $response = TestResponse::fromBaseResponse( From 3e4bc0a1b46e6822261ee98b37f43796644c0714 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 10:52:20 +1100 Subject: [PATCH 07/23] Adds found status assertion --- .../Testing/Concerns/AssertsStatusCodes.php | 11 +++++++++++ tests/Testing/TestResponseTest.php | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index 5f238b3d2670..efc1b266a570 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -62,6 +62,17 @@ public function assertMovedPermanently() return $this->assertStatus(301); } + /** + * Assert that the response has a found status code. + * + * @param int $status + * @return $this + */ + public function assertFound() + { + return $this->assertStatus(302); + } + /** * Assert that the response has a bad request status code. * diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index dc98befb08c4..b1788b983859 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -669,6 +669,25 @@ public function testAssertMovedPermanently() $this->fail(); } + public function testAssertFound() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_FOUND) + ); + + $response->assertFound(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [302] but received 200.\nFailed asserting that 302 is identical to 200."); + + $response->assertFound(); + $this->fail(); + } + public function testAssertAccepted() { $response = TestResponse::fromBaseResponse( From c5228304808f51912ca32c7b2f1df630c185d5ee Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 11:01:01 +1100 Subject: [PATCH 08/23] Adds conflict status assertion --- .../Testing/Concerns/AssertsStatusCodes.php | 10 ++++++++++ tests/Testing/TestResponseTest.php | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index efc1b266a570..deaae85fec86 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -133,6 +133,16 @@ public function assertRequestTimeout() return $this->assertStatus(408); } + /** + * Assert that the response has a conflict status code. + * + * @return $this + */ + public function assertConflict() + { + return $this->assertStatus(409); + } + /** * Assert that the response has a 422 status code. * diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index b1788b983859..0c07c277ce01 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -688,6 +688,25 @@ public function testAssertFound() $this->fail(); } + public function testAssertConflict() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_CONFLICT) + ); + + $response->assertConflict(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [409] but received 200.\nFailed asserting that 409 is identical to 200."); + + $response->assertConflict(); + $this->fail(); + } + public function testAssertAccepted() { $response = TestResponse::fromBaseResponse( From ee6432a17caa28faf4369a5ec3e50839e3744d02 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 11:18:35 +1100 Subject: [PATCH 09/23] Adds too many requests status assertion --- .../Testing/Concerns/AssertsStatusCodes.php | 10 ++++++++++ tests/Testing/TestResponseTest.php | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index deaae85fec86..ed1eee091442 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -152,4 +152,14 @@ public function assertUnprocessable() { return $this->assertStatus(422); } + + /** + * Assert that the response has a too many requests status code. + * + * @return $this + */ + public function assertTooManyRequests() + { + return $this->assertStatus(429); + } } diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 0c07c277ce01..4206f0509920 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -707,6 +707,25 @@ public function testAssertConflict() $this->fail(); } + public function testAssertTooManyRequests() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_TOO_MANY_REQUESTS) + ); + + $response->assertTooManyRequests(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [429] but received 200.\nFailed asserting that 429 is identical to 200."); + + $response->assertTooManyRequests(); + $this->fail(); + } + public function testAssertAccepted() { $response = TestResponse::fromBaseResponse( From 36836be59908552888b81c7805b27104aecc2cb8 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 11:40:41 +1100 Subject: [PATCH 10/23] Extracts status code checks to trait --- .../Client/Concerns/DeterminesStatusCode.php | 46 +++++++++++++++++++ src/Illuminate/Http/Client/Response.php | 42 +---------------- 2 files changed, 47 insertions(+), 41 deletions(-) create mode 100644 src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php new file mode 100644 index 000000000000..95f24d095990 --- /dev/null +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -0,0 +1,46 @@ +status() === 200; + } + + /** + * Determine if the response was a 401 "Unauthorized" response. + * + * @return bool + */ + public function unauthorized() + { + return $this->status() === 401; + } + + /** + * Determine if the response was a 403 "Forbidden" response. + * + * @return bool + */ + public function forbidden() + { + return $this->status() === 403; + } + + /** + * Determine if the response was a 404 "Not Found" response. + * + * @return bool + */ + public function notFound() + { + return $this->status() === 404; + } +} diff --git a/src/Illuminate/Http/Client/Response.php b/src/Illuminate/Http/Client/Response.php index ea88958f9af0..65fda6063f00 100644 --- a/src/Illuminate/Http/Client/Response.php +++ b/src/Illuminate/Http/Client/Response.php @@ -9,7 +9,7 @@ class Response implements ArrayAccess { - use Macroable { + use Concerns\DeterminesStatusCode, Macroable { __call as macroCall; } @@ -164,16 +164,6 @@ public function successful() return $this->status() >= 200 && $this->status() < 300; } - /** - * Determine if the response code was "OK". - * - * @return bool - */ - public function ok() - { - return $this->status() === 200; - } - /** * Determine if the response was a redirect. * @@ -184,36 +174,6 @@ public function redirect() return $this->status() >= 300 && $this->status() < 400; } - /** - * Determine if the response was a 401 "Unauthorized" response. - * - * @return bool - */ - public function unauthorized() - { - return $this->status() === 401; - } - - /** - * Determine if the response was a 403 "Forbidden" response. - * - * @return bool - */ - public function forbidden() - { - return $this->status() === 403; - } - - /** - * Determine if the response was a 404 "Not Found" response. - * - * @return bool - */ - public function notFound() - { - return $this->status() === 404; - } - /** * Determine if the response indicates a client or server error occurred. * From bd6d70993c38794d8347cbeaa50f58daf491d588 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 11:44:58 +1100 Subject: [PATCH 11/23] Adds created status check --- .../Http/Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 95f24d095990..55b52f4aa671 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -14,6 +14,16 @@ public function ok() return $this->status() === 200; } + /** + * Determine if the response code was "created". + * + * @return bool + */ + public function created() + { + return $this->status() === 201; + } + /** * Determine if the response was a 401 "Unauthorized" response. * diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 398b1ff616b3..0dcba770670b 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -17,6 +17,7 @@ use Illuminate\Http\Client\RequestException; use Illuminate\Http\Client\Response; use Illuminate\Http\Client\ResponseSequence; +use Illuminate\Http\Response as HttpResponse; use Illuminate\Support\Collection; use Illuminate\Support\Fluent; use Illuminate\Support\Str; @@ -56,6 +57,20 @@ public function testStubbedResponsesAreReturnedAfterFaking() $this->assertTrue($response->ok()); } + public function testCreatedRequest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_CREATED), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->created()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->created()); + } + public function testUnauthorizedRequest() { $this->factory->fake([ From 66f42e7fb0dac29de66ec7511ab8628db7c4a082 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 11:46:02 +1100 Subject: [PATCH 12/23] Adds accepted status check --- .../Http/Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 55b52f4aa671..9f1327bec8fa 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -24,6 +24,16 @@ public function created() return $this->status() === 201; } + /** + * Determine if the response code was "accepted". + * + * @return bool + */ + public function accepted() + { + return $this->status() === 202; + } + /** * Determine if the response was a 401 "Unauthorized" response. * diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 0dcba770670b..ca811353c5ad 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -71,6 +71,20 @@ public function testCreatedRequest() $this->assertFalse($response->created()); } + public function testAcceptedRequest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_ACCEPTED), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->accepted()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->accepted()); + } + public function testUnauthorizedRequest() { $this->factory->fake([ From dfee998e3825790a27daada0dd3151ef21f21848 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 11:49:43 +1100 Subject: [PATCH 13/23] Adds no content status check --- .../Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 9f1327bec8fa..fbebe349d567 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -34,6 +34,16 @@ public function accepted() return $this->status() === 202; } + /** + * Determine if the response code was "no content". + * + * @return bool + */ + public function noContent($status = 204) + { + return $this->status() === $status && $this->body() === ''; + } + /** * Determine if the response was a 401 "Unauthorized" response. * diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index ca811353c5ad..4ddfea4f1afc 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -85,6 +85,24 @@ public function testAcceptedRequest() $this->assertFalse($response->accepted()); } + public function testNoContentRequest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_NO_CONTENT), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + 'basecamp.laravel.com' => $this->factory::response('foo', HttpResponse::HTTP_NO_CONTENT), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->noContent()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->noContent()); + + $response = $this->factory->post('http://basecamp.laravel.com'); + $this->assertFalse($response->noContent()); + } + public function testUnauthorizedRequest() { $this->factory->fake([ From e1e0fddb19ebaedc9c712f9be13b957a054e4e75 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 11:51:36 +1100 Subject: [PATCH 14/23] Adds moved permanently status check --- .../Client/Concerns/DeterminesStatusCode.php | 11 +++++++++++ tests/Http/HttpClientTest.php | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index fbebe349d567..4e70c61dd43a 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -37,6 +37,7 @@ public function accepted() /** * Determine if the response code was "no content". * + * @param int $status * @return bool */ public function noContent($status = 204) @@ -44,6 +45,16 @@ public function noContent($status = 204) return $this->status() === $status && $this->body() === ''; } + /** + * Determine if the response code was "moved permanently". + * + * @return bool + */ + public function movedPermanently() + { + return $this->status() === 301; + } + /** * Determine if the response was a 401 "Unauthorized" response. * diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 4ddfea4f1afc..cb20caf6c821 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -86,11 +86,24 @@ public function testAcceptedRequest() } public function testNoContentRequest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_MOVED_PERMANENTLY), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->movedPermanently()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->movedPermanently()); + } + + public function testMovedPermanentlyRequest() { $this->factory->fake([ 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_NO_CONTENT), 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), - 'basecamp.laravel.com' => $this->factory::response('foo', HttpResponse::HTTP_NO_CONTENT), ]); $response = $this->factory->post('http://vapor.laravel.com'); @@ -98,9 +111,6 @@ public function testNoContentRequest() $response = $this->factory->post('http://forge.laravel.com'); $this->assertFalse($response->noContent()); - - $response = $this->factory->post('http://basecamp.laravel.com'); - $this->assertFalse($response->noContent()); } public function testUnauthorizedRequest() From 56df5fec16e0d8637b37f9c6a900855b1e7f4dfe Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 11:53:08 +1100 Subject: [PATCH 15/23] Adds found status check --- .../Http/Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 4e70c61dd43a..582e9b0d42ff 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -55,6 +55,16 @@ public function movedPermanently() return $this->status() === 301; } + /** + * Determine if the response code was "found". + * + * @return bool + */ + public function found() + { + return $this->status() === 302; + } + /** * Determine if the response was a 401 "Unauthorized" response. * diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index cb20caf6c821..7b317b4769e4 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -113,6 +113,21 @@ public function testMovedPermanentlyRequest() $this->assertFalse($response->noContent()); } + public function testFoundRequest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_FOUND), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->found()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->found()); + } + + public function testUnauthorizedRequest() { $this->factory->fake([ From cd8554c640dbbbcbc083022631745526fb1783fb Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 12:00:11 +1100 Subject: [PATCH 16/23] Adds bad request status check --- .../Http/Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 582e9b0d42ff..a688fc7a7fda 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -65,6 +65,16 @@ public function found() return $this->status() === 302; } + /** + * Determine if the response was a "bad request". + * + * @return bool + */ + public function badRequest() + { + return $this->status() === 400; + } + /** * Determine if the response was a 401 "Unauthorized" response. * diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 7b317b4769e4..21ab0e45ba32 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -127,6 +127,19 @@ public function testFoundRequest() $this->assertFalse($response->found()); } + public function testBadRequestRequest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_BAD_REQUEST), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->badRequest()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->badRequest()); + } public function testUnauthorizedRequest() { From 74ea92f7ffdf447ab72d8fdbd68a7bd3e0445189 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 12:01:56 +1100 Subject: [PATCH 17/23] Adds payment required status check --- .../Http/Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index a688fc7a7fda..2876e64bf7b4 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -85,6 +85,16 @@ public function unauthorized() return $this->status() === 401; } + /** + * Determine if the response was a "payment required". + * + * @return bool + */ + public function paymentRequired() + { + return $this->status() === 402; + } + /** * Determine if the response was a 403 "Forbidden" response. * diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 21ab0e45ba32..975dce2ea704 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -141,6 +141,20 @@ public function testBadRequestRequest() $this->assertFalse($response->badRequest()); } + public function testPaymentRequiredTest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_PAYMENT_REQUIRED), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->paymentRequired()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->paymentRequired()); + } + public function testUnauthorizedRequest() { $this->factory->fake([ From 4648a0776d3886a683d938ea3f5c9dad7d7e4239 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 12:03:53 +1100 Subject: [PATCH 18/23] Adds request timeout status check --- .../Http/Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 2876e64bf7b4..5a0b85f9e0ac 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -114,4 +114,14 @@ public function notFound() { return $this->status() === 404; } + + /** + * Determine if the response was a "Request Timeout". + * + * @return bool + */ + public function requestTimeout() + { + return $this->status() === 408; + } } diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 975dce2ea704..e693c2eb6690 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -155,6 +155,20 @@ public function testPaymentRequiredTest() $this->assertFalse($response->paymentRequired()); } + public function testRequestTimeoutTest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_REQUEST_TIMEOUT), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->requestTimeout()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->requestTimeout()); + } + public function testUnauthorizedRequest() { $this->factory->fake([ From 8572623ce8a13c0dd2df80ea3d49409e72163210 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 12:05:36 +1100 Subject: [PATCH 19/23] Adds conflict status check --- .../Http/Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 5a0b85f9e0ac..4862729b8904 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -124,4 +124,14 @@ public function requestTimeout() { return $this->status() === 408; } + + /** + * Determine if the response was a "Conflict". + * + * @return bool + */ + public function conflict() + { + return $this->status() === 409; + } } diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index e693c2eb6690..4b1db8a24138 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -169,6 +169,20 @@ public function testRequestTimeoutTest() $this->assertFalse($response->requestTimeout()); } + public function testConflictResponseTest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_CONFLICT), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->conflict()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->conflict()); + } + public function testUnauthorizedRequest() { $this->factory->fake([ From c8b5916c4e650af91ccefb903c0795d91bc3c0e8 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 12:07:20 +1100 Subject: [PATCH 20/23] Adds unprocessable entity status check --- .../Http/Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 4862729b8904..7ecf9865ce7c 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -134,4 +134,14 @@ public function conflict() { return $this->status() === 409; } + + /** + * Determine if the response was a "Unprocessable Entity". + * + * @return bool + */ + public function unprocessableEntity() + { + return $this->status() === 422; + } } diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 4b1db8a24138..01181ca70e0f 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -205,6 +205,20 @@ public function testForbiddenRequest() $this->assertTrue($response->forbidden()); } + public function testUnprocessableEntityRequest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_UNPROCESSABLE_ENTITY), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->unprocessableEntity()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->unprocessableEntity()); + } + public function testNotFoundResponse() { $this->factory->fake([ From c90430c7f0d62fe9920b92aad62154ba5e389041 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 12:09:11 +1100 Subject: [PATCH 21/23] Adds too many requests status check --- .../Http/Client/Concerns/DeterminesStatusCode.php | 10 ++++++++++ tests/Http/HttpClientTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 7ecf9865ce7c..6d052ab10035 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -144,4 +144,14 @@ public function unprocessableEntity() { return $this->status() === 422; } + + /** + * Determine if the response was a "Too Many Requests". + * + * @return bool + */ + public function tooManyRequests() + { + return $this->status() === 429; + } } diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 01181ca70e0f..040adc875cf1 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -219,6 +219,20 @@ public function testUnprocessableEntityRequest() $this->assertFalse($response->unprocessableEntity()); } + public function testTooManyRequestsRequest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_TOO_MANY_REQUESTS), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->tooManyRequests()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->tooManyRequests()); + } + public function testNotFoundResponse() { $this->factory->fake([ From da8b4f27b3b1fee08c63850348bff786875f3bfb Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 12:16:51 +1100 Subject: [PATCH 22/23] Standardises dockblocks and formatting --- .../Client/Concerns/DeterminesStatusCode.php | 24 ++++++------- .../Testing/Concerns/AssertsStatusCodes.php | 28 +++++++-------- tests/Http/HttpClientTest.php | 35 ++++++++++--------- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 6d052ab10035..ab9132006ecf 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -5,7 +5,7 @@ trait DeterminesStatusCode { /** - * Determine if the response code was "OK". + * Determine if the response code was 200 "OK" response. * * @return bool */ @@ -15,7 +15,7 @@ public function ok() } /** - * Determine if the response code was "created". + * Determine if the response code was 201 "Created" response. * * @return bool */ @@ -25,7 +25,7 @@ public function created() } /** - * Determine if the response code was "accepted". + * Determine if the response code was 202 "Accepted" response. * * @return bool */ @@ -35,7 +35,7 @@ public function accepted() } /** - * Determine if the response code was "no content". + * Determine if the response code was the given status code and the body has no content. * * @param int $status * @return bool @@ -46,7 +46,7 @@ public function noContent($status = 204) } /** - * Determine if the response code was "moved permanently". + * Determine if the response code was a 301 "Moved Permanently". * * @return bool */ @@ -56,7 +56,7 @@ public function movedPermanently() } /** - * Determine if the response code was "found". + * Determine if the response code was a 302 "Found" response. * * @return bool */ @@ -66,7 +66,7 @@ public function found() } /** - * Determine if the response was a "bad request". + * Determine if the response was a 400 "Bad Request" response. * * @return bool */ @@ -86,7 +86,7 @@ public function unauthorized() } /** - * Determine if the response was a "payment required". + * Determine if the response was a 402 "Payment Required" response. * * @return bool */ @@ -116,7 +116,7 @@ public function notFound() } /** - * Determine if the response was a "Request Timeout". + * Determine if the response was a 408 "Request Timeout" response. * * @return bool */ @@ -126,7 +126,7 @@ public function requestTimeout() } /** - * Determine if the response was a "Conflict". + * Determine if the response was a 409 "Conflict" response. * * @return bool */ @@ -136,7 +136,7 @@ public function conflict() } /** - * Determine if the response was a "Unprocessable Entity". + * Determine if the response was a 422 "Unprocessable Entity" response. * * @return bool */ @@ -146,7 +146,7 @@ public function unprocessableEntity() } /** - * Determine if the response was a "Too Many Requests". + * Determine if the response was a 429 "Too Many Requests" response. * * @return bool */ diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index ed1eee091442..5bdb144cb616 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -7,7 +7,7 @@ trait AssertsStatusCodes { /** - * Assert that the response has a 200 status code. + * Assert that the response has a 200 "OK" status code. * * @return $this */ @@ -17,7 +17,7 @@ public function assertOk() } /** - * Assert that the response has a 201 status code. + * Assert that the response has a 201 "Created" status code. * * @return $this */ @@ -27,7 +27,7 @@ public function assertCreated() } /** - * Assert that the response has an accepted status code. + * Assert that the response has a 202 "Accepted" status code. * * @return $this */ @@ -52,7 +52,7 @@ public function assertNoContent($status = 204) } /** - * Assert that the response has a moved permanently status code. + * Assert that the response has a 301 "Moved Permanently" status code. * * @param int $status * @return $this @@ -63,7 +63,7 @@ public function assertMovedPermanently() } /** - * Assert that the response has a found status code. + * Assert that the response has a 302 "Found" status code. * * @param int $status * @return $this @@ -74,7 +74,7 @@ public function assertFound() } /** - * Assert that the response has a bad request status code. + * Assert that the response has a 400 "Bad Request" status code. * * @return $this */ @@ -84,7 +84,7 @@ public function assertBadRequest() } /** - * Assert that the response has an unauthorized status code. + * Assert that the response has a 402 "Unauthorized" status code. * * @return $this */ @@ -94,7 +94,7 @@ public function assertUnauthorized() } /** - * Assert that the response has a payment required status code. + * Assert that the response has a 402 "Payment Required" status code. * * @return $this */ @@ -104,7 +104,7 @@ public function assertPaymentRequired() } /** - * Assert that the response has a forbidden status code. + * Assert that the response has a 403 "Forbidden" status code. * * @return $this */ @@ -114,7 +114,7 @@ public function assertForbidden() } /** - * Assert that the response has a not found status code. + * Assert that the response has a 404 "Not Found" status code. * * @return $this */ @@ -124,7 +124,7 @@ public function assertNotFound() } /** - * Assert that the response has a request timeout status code. + * Assert that the response has a 408 "Request Timeout" status code. * * @return $this */ @@ -134,7 +134,7 @@ public function assertRequestTimeout() } /** - * Assert that the response has a conflict status code. + * Assert that the response has a 409 "Conflict" status code. * * @return $this */ @@ -144,7 +144,7 @@ public function assertConflict() } /** - * Assert that the response has a 422 status code. + * Assert that the response has a 422 "Unprocessable Entity" status code. * * @return $this */ @@ -154,7 +154,7 @@ public function assertUnprocessable() } /** - * Assert that the response has a too many requests status code. + * Assert that the response has a 429 "Too Many Requests" status code. * * @return $this */ diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 040adc875cf1..93597ca9b12e 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -141,7 +141,7 @@ public function testBadRequestRequest() $this->assertFalse($response->badRequest()); } - public function testPaymentRequiredTest() + public function testPaymentRequiredRequest() { $this->factory->fake([ 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_PAYMENT_REQUIRED), @@ -155,7 +155,7 @@ public function testPaymentRequiredTest() $this->assertFalse($response->paymentRequired()); } - public function testRequestTimeoutTest() + public function testRequestTimeoutRequest() { $this->factory->fake([ 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_REQUEST_TIMEOUT), @@ -169,7 +169,7 @@ public function testRequestTimeoutTest() $this->assertFalse($response->requestTimeout()); } - public function testConflictResponseTest() + public function testConflictResponseRequest() { $this->factory->fake([ 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_CONFLICT), @@ -183,40 +183,41 @@ public function testConflictResponseTest() $this->assertFalse($response->conflict()); } - public function testUnauthorizedRequest() + public function testUnprocessableEntityRequest() { $this->factory->fake([ - 'laravel.com' => $this->factory::response('', 401), + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_UNPROCESSABLE_ENTITY), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), ]); - $response = $this->factory->post('http://laravel.com'); + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->unprocessableEntity()); - $this->assertTrue($response->unauthorized()); + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->unprocessableEntity()); } - public function testForbiddenRequest() + + public function testUnauthorizedRequest() { $this->factory->fake([ - 'laravel.com' => $this->factory::response('', 403), + 'laravel.com' => $this->factory::response('', 401), ]); $response = $this->factory->post('http://laravel.com'); - $this->assertTrue($response->forbidden()); + $this->assertTrue($response->unauthorized()); } - public function testUnprocessableEntityRequest() + public function testForbiddenRequest() { $this->factory->fake([ - 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_UNPROCESSABLE_ENTITY), - 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + 'laravel.com' => $this->factory::response('', 403), ]); - $response = $this->factory->post('http://vapor.laravel.com'); - $this->assertTrue($response->unprocessableEntity()); + $response = $this->factory->post('http://laravel.com'); - $response = $this->factory->post('http://forge.laravel.com'); - $this->assertFalse($response->unprocessableEntity()); + $this->assertTrue($response->forbidden()); } public function testTooManyRequestsRequest() From 9bf87f736cabf371381e015208a66aa65892ef65 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 25 Jan 2023 12:22:00 +1100 Subject: [PATCH 23/23] Fixes ordering and typo --- tests/Http/HttpClientTest.php | 31 +++++++++++++++--------------- tests/Testing/TestResponseTest.php | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 93597ca9b12e..36a4eb168af1 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -85,7 +85,7 @@ public function testAcceptedRequest() $this->assertFalse($response->accepted()); } - public function testNoContentRequest() + public function testMovedPermanentlyRequest() { $this->factory->fake([ 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_MOVED_PERMANENTLY), @@ -99,7 +99,7 @@ public function testNoContentRequest() $this->assertFalse($response->movedPermanently()); } - public function testMovedPermanentlyRequest() + public function testNoContentRequest() { $this->factory->fake([ 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_NO_CONTENT), @@ -197,6 +197,19 @@ public function testUnprocessableEntityRequest() $this->assertFalse($response->unprocessableEntity()); } + public function testTooManyRequestsRequest() + { + $this->factory->fake([ + 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_TOO_MANY_REQUESTS), + 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), + ]); + + $response = $this->factory->post('http://vapor.laravel.com'); + $this->assertTrue($response->tooManyRequests()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->tooManyRequests()); + } public function testUnauthorizedRequest() { @@ -220,20 +233,6 @@ public function testForbiddenRequest() $this->assertTrue($response->forbidden()); } - public function testTooManyRequestsRequest() - { - $this->factory->fake([ - 'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_TOO_MANY_REQUESTS), - 'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK), - ]); - - $response = $this->factory->post('http://vapor.laravel.com'); - $this->assertTrue($response->tooManyRequests()); - - $response = $this->factory->post('http://forge.laravel.com'); - $this->assertFalse($response->tooManyRequests()); - } - public function testNotFoundResponse() { $this->factory->fake([ diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 4206f0509920..474ff871bbb4 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -631,7 +631,7 @@ public function testAssertRequestTimeout() $this->fail(); } - public function testAssertPaymetRequired() + public function testAssertPaymentRequired() { $response = TestResponse::fromBaseResponse( (new Response)->setStatusCode(Response::HTTP_PAYMENT_REQUIRED)