Skip to content

Commit 5408e69

Browse files
cluggtaylorotwell
andauthored
[6.x] Fix assertJsonCount not accepting falsey keys (#32655)
* Fix assertJsonCount not accepting falsey values * Update TestResponse.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent f6d3f3a commit 5408e69

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Illuminate/Foundation/Testing/TestResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ public function assertJsonStructure(array $structure = null, $responseData = nul
684684
*/
685685
public function assertJsonCount(int $count, $key = null)
686686
{
687-
if ($key) {
687+
if (! is_null($key)) {
688688
PHPUnit::assertCount(
689689
$count, data_get($this->json(), $key),
690690
"Failed to assert that the response count matched the expected {$count}"

tests/Foundation/FoundationTestResponseTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ public function testAssertJsonCount()
484484
{
485485
$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableMixedResourcesStub));
486486

487+
// With falsey key
488+
$response->assertJsonCount(1, '0');
489+
487490
// With simple key
488491
$response->assertJsonCount(3, 'bars');
489492

@@ -918,6 +921,7 @@ public function jsonSerialize()
918921
'foobar_foo' => 'foo',
919922
'foobar_bar' => 'bar',
920923
],
924+
'0' => ['foo'],
921925
'bars' => [
922926
['bar' => 'foo 0', 'foo' => 'bar 0'],
923927
['bar' => 'foo 1', 'foo' => 'bar 1'],

0 commit comments

Comments
 (0)