8000 add assert fragments (#54576) · laravel/framework@241bab4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 241bab4

Browse files
add assert fragments (#54576)
1 parent 102d770 commit 241bab4

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Illuminate/Testing/TestResponse.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,21 @@ public function assertSimilarJson(array $data)
815815
return $this;
816816
}
817817

818+
/**
819+
* Assert that the response contains the given JSON fragments.
820+
*
821+
* @param array $data
822+
* @return $this
823+
*/
824+
public function assertJsonFragments(array $data)
825+
{
826+
foreach ($data as $fragment) {
827+
$this->assertJsonFragment($fragment);
828+
}
829+
830+
return $this;
831+
}
832+
818833
/**
819834
* Assert that the response contains the given JSON fragment.
820835
*

tests/Testing/TestResponseTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,20 @@ public function testAssertJsonFragment()
14831483
$response->assertJsonFragment(['id' => 10]);
14841484
}
14851485

1486+
public function testAssertJsonFragments()
1487+
{
1488+
$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceStub));
1489+
1490+
$response->assertJsonFragments([
1491+
['foo' => 'foo 0'],
1492+
]);
1493+
1494+
$response->assertJsonFragments([
1495+
['foo' => 'foo 0'],
1496+
['foo' => 'foo 1'],
1497+
]);
1498+
}
1499+
14861500
public function testAssertJsonFragmentCanFail()
14871501
{
14881502
$this->expectException(AssertionFailedError::class);

0 commit comments

Comments
 (0)
0