diff --git a/src/Illuminate/Testing/TestResponse.php b/src/Illuminate/Testing/TestResponse.php index e638dfedbed0..2770f1b60794 100644 --- a/src/Illuminate/Testing/TestResponse.php +++ b/src/Illuminate/Testing/TestResponse.php @@ -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. * diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 3e0f82076901..6d14cd4b660a 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -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;