I've got a method in a controller that collects data from the database and sends it to a resource class before returning it to the user as JSON. When I inspect the data in Paw or using dd() it shows all of the expected records in data[0]['records'].
However, when I create 25 instances of the model using factory(Model::class, 25)->create() and verify the count using ->assertJsonCount(25, 'data.*.records'); it shows that it has only one record.
When I dd() before the assertion (after the creation of the data) I see the valid data structure.
When I dd($response->json()['data'][0]['records']) I can see the records array with all 25 items.
In TestResponse.php, line 476 I dump dd(data_get($this->json(), $key)); and see that the data is encased within an array that was not there before!
What is going on?
assertJsonCountThere was 1 failure:
1) Tests\Feature\RecordTest::a_user_can_view_the_records
Failed to assert that the response count matched the expected 25
Failed asserting that actual size 1 matches expected size 25.
/home/vagrant/dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:481
/home/vagrant/dev/api/tests/Feature/RecordTest.php:65
Do $this->assertJsonCount(25, 'data.0.records');
That fixed the issue, thanks!
Most helpful comment
Do $this->assertJsonCount(25, 'data.0.records');