From cd4b0de8e7f639e14a86a3a2f487b6c637897e56 Mon Sep 17 00:00:00 2001 From: James Dickens Date: Sun, 3 May 2020 20:29:06 +1000 Subject: [PATCH 1/2] Fix assertJsonCount not accepting falsey values --- src/Illuminate/Foundation/Testing/TestResponse.php | 2 +- tests/Foundation/FoundationTestResponseTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index 2db82f7ae3a8..9f6ea7c630a6 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -684,7 +684,7 @@ public function assertJsonStructure(array $structure = null, $responseData = nul */ public function assertJsonCount(int $count, $key = null) { - if ($key) { + if ($key !== null) { PHPUnit::assertCount( $count, data_get($this->json(), $key), "Failed to assert that the response count matched the expected {$count}" diff --git a/tests/Foundation/FoundationTestResponseTest.php b/tests/Foundation/FoundationTestResponseTest.php index 3b3aef467c07..367ee83ed60c 100644 --- a/tests/Foundation/FoundationTestResponseTest.php +++ b/tests/Foundation/FoundationTestResponseTest.php @@ -484,6 +484,9 @@ public function testAssertJsonCount() { $response = TestResponse::fromBaseResponse(new Response(new JsonSerializableMixedResourcesStub)); + // With falsey key + $response->assertJsonCount(1, '0'); + // With simple key $response->assertJsonCount(3, 'bars'); @@ -918,6 +921,7 @@ public function jsonSerialize() 'foobar_foo' => 'foo', 'foobar_bar' => 'bar', ], + '0' => ['foo'], 'bars' => [ ['bar' => 'foo 0', 'foo' => 'bar 0'], ['bar' => 'foo 1', 'foo' => 'bar 1'], From 5a4647398fb33dfd8e2a930d56b02c3ecf9495be Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 3 May 2020 10:33:48 -0500 Subject: [PATCH 2/2] Update TestResponse.php --- src/Illuminate/Foundation/Testing/TestResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index 9f6ea7c630a6..1ffdb81ea8ac 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -684,7 +684,7 @@ public function assertJsonStructure(array $structure = null, $responseData = nul */ public function assertJsonCount(int $count, $key = null) { - if ($key !== null) { + if (! is_null($key)) { PHPUnit::assertCount( $count, data_get($this->json(), $key), "Failed to assert that the response count matched the expected {$count}"