Skip to content

Commit fba3b98

Browse files
authored
[12.x] Add assertClientError method to TestResponse (#55750)
1 parent 8113c82 commit fba3b98

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
@@ -131,6 +131,21 @@ public function assertSuccessfulPrecognition()
131131
return $this;
132132
}
133133

134+
/**
135+
* Assert that the response is a client error.
136+
*
137+
* @return $this
138+
*/
139+
public function assertClientError()
140+
{
141+
PHPUnit::withResponse($this)->assertTrue(
142+
$this->isClientError(),
143+
$this->statusMessageWithDetails('>=400, < 500', $this->getStatusCode())
144+
);
145+
146+
return $this;
147+
}
148+
134149
/**
135150
* Assert that the response is a server error.
136151
*

tests/Testing/TestResponseTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,18 @@ public function testAssertUnprocessable()
10861086
$response->assertUnprocessable();
10871087
}
10881088

1089+
public function testAssertClientError()
1090+
{
1091+
$statusCode = 400;
1092+
1093+
$baseResponse = tap(new Response, function ($response) use ($statusCode) {
1094+
$response->setStatusCode($statusCode);
1095+
});
1096+
1097+
$response = TestResponse::fromBaseResponse($baseResponse);
1098+
$response->assertClientError();
1099+
}
1100+
10891101
public function testAssertServerError()
10901102
{
10911103
$statusCode = 500;

0 commit comments

Comments
 (0)