From ccdddafb6100b45c44570587c415fed4cf05c3b6 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Mon, 17 Jun 2024 23:51:49 +1000 Subject: [PATCH] [11.x] Add unprocessableContent and update unprocessableEntity (#51815) * Add unprocessableContent and update unprocessableEntity * Update some docblocks --- .../Http/Client/Concerns/DeterminesStatusCode.php | 14 ++++++++++++-- .../Testing/Concerns/AssertsStatusCodes.php | 2 +- tests/Http/HttpClientTest.php | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php index 29a33c07c7c1..249739cb2331 100644 --- a/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php +++ b/src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php @@ -146,15 +146,25 @@ public function conflict() } /** - * Determine if the response was a 422 "Unprocessable Entity" response. + * Determine if the response was a 422 "Unprocessable Content" response. * * @return bool */ - public function unprocessableEntity() + public function unprocessableContent() { return $this->status() === 422; } + /** + * Determine if the response was a 422 "Unprocessable Content" response. + * + * @return bool + */ + public function unprocessableEntity() + { + return $this->unprocessableContent(); + } + /** * Determine if the response was a 429 "Too Many Requests" response. * diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index 1c891b0df0e9..f329f631fa1e 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -212,7 +212,7 @@ public function assertUnsupportedMediaType() } /** - * Assert that the response has a 422 "Unprocessable Entity" status code. + * Assert that the response has a 422 "Unprocessable Content" status code. * * @return $this */ diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 75fd630a418f..35993030837e 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -206,6 +206,20 @@ public function testConflictResponseRequest() $this->assertFalse($response->conflict()); } + public function testUnprocessableContentRequest() + { + $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->unprocessableContent()); + + $response = $this->factory->post('http://forge.laravel.com'); + $this->assertFalse($response->unprocessableContent()); + } + public function testUnprocessableEntityRequest() { $this->factory->fake([