Skip to content

Commit 4e9a0fd

Browse files
authored
feat: Add assertServerError. (#44619)
1 parent faf3842 commit 4e9a0fd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Illuminate/Testing/TestResponse.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ public function assertUnprocessable()
165165
return $this->assertStatus(422);
166166
}
167167

168+
/**
169+
* Assert that the response is a server error.
170+
*
171+
* @return $this
172+
*/
173+
public function assertServerError()
174+
{
175+
PHPUnit::assertTrue(
176+
$this->isServerError(),
177+
$this->statusMessageWithDetails('>=500, < 600', $this->getStatusCode())
178+
);
179+
180+
return $this;
181+
}
182+
168183
/**
169184
* Assert that the response has the given status code.
170185
*

tests/Testing/TestResponseTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,18 @@ public function testAssertUnprocessable()
580580
$response->assertUnprocessable();
581581
}
582582

583+
public function testAssertServerError()
584+
{
585+
$statusCode = 500;
586+
587+
$baseResponse = tap(new Response, function ($response) use ($statusCode) {
588+
$response->setStatusCode($statusCode);
589+
});
590+
591+
$response = TestResponse::fromBaseResponse($baseResponse);
592+
$response->assertServerError();
593+
}
594+
583595
public function testAssertNoContentAsserts204StatusCodeByDefault()
584596
{
585597
$statusCode = 500;

0 commit comments

Comments
 (0)