Skip to content

Commit 7161c83

Browse files
Allow nested errors in json assertion (#33989)
1 parent 21520ee commit 7161c83

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Illuminate/Testing/TestResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ public function assertJsonValidationErrors($errors, $responseKey = 'errors')
729729

730730
PHPUnit::assertNotEmpty($errors, 'No validation errors were provided.');
731731

732-
$jsonErrors = $this->json()[$responseKey] ?? [];
732+
$jsonErrors = Arr::get($this->json(), $responseKey) ?? [];
733733

734734
$errorMessage = $jsonErrors
735735
? 'Response has the following JSON validation errors:'.

tests/Testing/TestResponseTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,20 @@ public function testAssertJsonValidationErrorsCustomErrorsName()
611611
$testResponse->assertJsonValidationErrors('foo', 'data');
612612
}
613613

614+
public function testAssertJsonValidationErrorsCustomNestedErrorsName()
615+
{
616+
$data = [
617+
'status' => 'ok',
618+
'data' => ['errors' => ['foo' => 'oops']],
619+
];
620+
621+
$testResponse = TestResponse::fromBaseResponse(
622+
(new Response)->setContent(json_encode($data))
623+
);
624+
625+
$testResponse->assertJsonValidationErrors('foo', 'data.errors');
626+
}
627+
614628
public function testAssertJsonValidationErrorsCanFail()
615629
{
616630
$this->expectException(AssertionFailedError::class);

0 commit comments

Comments
 (0)