diff --git a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php index d34b43f5cac7..22b91d6e2420 100644 --- a/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php +++ b/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php @@ -141,6 +141,16 @@ public function assertConflict() return $this->assertStatus(409); } + /** + * Assert that the response has a 410 "Gone" status code. + * + * @return $this + */ + public function assertGone() + { + return $this->assertStatus(410); + } + /** * Assert that the response has a 415 "Unsupported Media Type" status code. * @@ -170,4 +180,24 @@ public function assertTooManyRequests() { return $this->assertStatus(429); } + + /** + * Assert that the response has a 500 "Internal Server Error" status code. + * + * @return $this + */ + public function assertInternalServerError() + { + return $this->assertStatus(500); + } + + /** + * Assert that the response has a 503 "Service Unavailable" status code. + * + * @return $this + */ + public function assertServiceUnavailable() + { + return $this->assertStatus(503); + } } diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 005c1efca231..0cf30888eabb 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -707,6 +707,24 @@ public function testAssertConflict() $this->fail(); } + public function testAssertGone() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_GONE) + ); + + $response->assertGone(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [410] but received 200.\nFailed asserting that 410 is identical to 200."); + + $response->assertGone(); + } + public function testAssertTooManyRequests() { $response = TestResponse::fromBaseResponse( @@ -773,6 +791,42 @@ public function testAssertServerError() $response->assertServerError(); } + public function testAssertInternalServerError() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR) + ); + + $response->assertInternalServerError(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [500] but received 200.\nFailed asserting that 500 is identical to 200."); + + $response->assertInternalServerError(); + } + + public function testAssertServiceUnavailable() + { + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_SERVICE_UNAVAILABLE) + ); + + $response->assertServiceUnavailable(); + + $response = TestResponse::fromBaseResponse( + (new Response)->setStatusCode(Response::HTTP_OK) + ); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage("Expected response status code [503] but received 200.\nFailed asserting that 503 is identical to 200."); + + $response->assertServiceUnavailable(); + } + public function testAssertNoContentAsserts204StatusCodeByDefault() { $statusCode = 500;