Skip to content

Commit 0a24afd

Browse files
authored
feat: implement 'assertFailedDependency' response assertion (#58061)
1 parent a74e575 commit 0a24afd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Illuminate/Testing/Concerns/AssertsStatusCodes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ public function assertUnprocessable()
221221
return $this->assertStatus(422);
222222
}
223223

224+
/**
225+
* Assert that the response has a 424 "Failed Dependency" status code.
226+
*
227+
* @return $this
228+
*/
229+
public function assertFailedDependency()
230+
{
231+
return $this->assertStatus(424);
232+
}
233+
224234
/**
225235
* Assert that the response has a 429 "Too Many Requests" status code.
226236
*

tests/Testing/TestResponseTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,25 @@ public function testAssertUnprocessable(): void
10871087
$response->assertUnprocessable();
10881088
}
10891089

1090+
public function testAssertFailedDependency(): void
1091+
{
1092+
$response = TestResponse::fromBaseResponse(
1093+
(new Response)->setStatusCode(Response::HTTP_FAILED_DEPENDENCY)
1094+
);
1095+
1096+
$response->assertFailedDependency();
1097+
1098+
$response = TestResponse::fromBaseResponse(
1099+
(new Response)->setStatusCode(Response::HTTP_OK)
1100+
);
1101+
1102+
$this->expectException(AssertionFailedError::class);
1103+
$this->expectExceptionMessage("Expected response status code [424] but received 200.\nFailed asserting that 200 is identical to 424.");
1104+
1105+
$response->assertFailedDependency();
1106+
$this->fail();
1107+
}
1108+
10901109
public function testAssertClientError(): void
10911110
{
10921111
$statusCode = 400;

0 commit comments

Comments
 (0)