Skip to content

Commit

Permalink
[11.x] Add unprocessableContent and update unprocessableEntity (#51815)
Browse files Browse the repository at this point in the history
* Add unprocessableContent and update unprocessableEntity

* Update some docblocks
  • Loading branch information
dwightwatson authored Jun 17, 2024
1 parent 7a8a054 commit ccdddaf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Testing/Concerns/AssertsStatusCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down

0 comments on commit ccdddaf

Please sign in to comment.