Skip to content

Commit

Permalink
[8.x] Add unprocessable test response assertion (#38553)
Browse files Browse the repository at this point in the history
* Add assertUnprocessable method
* Add test

Co-authored-by: Joby Harding <[email protected]>
  • Loading branch information
jobyh and jobyh authored Aug 26, 2021
1 parent 93bacdc commit 21d2fb2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ 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 has the given status code.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/Testing/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,22 @@ public function testAssertUnauthorized()
$response->assertUnauthorized();
}

public function testAssertUnprocessable()
{
$statusCode = 500;

$this->expectException(AssertionFailedError::class);

$this->expectExceptionMessage('Expected response status code');

$baseResponse = tap(new Response, function ($response) use ($statusCode) {
$response->setStatusCode($statusCode);
});

$response = TestResponse::fromBaseResponse($baseResponse);
$response->assertUnprocessable();
}

public function testAssertNoContentAsserts204StatusCodeByDefault()
{
$statusCode = 500;
Expand Down

0 comments on commit 21d2fb2

Please sign in to comment.