Skip to content

Commit

Permalink
Update assertions on included record set
Browse files Browse the repository at this point in the history
  • Loading branch information
huntie committed Sep 21, 2017
1 parent b13a78f commit 5adc644
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tests/Serializers/ResourceSerializerTest.php
Expand Up @@ -103,10 +103,14 @@ public function testIncludedRecords()
$included = $serializer->getIncluded();

$this->assertInstanceOf(Collection::class, $included);
$this->assertJsonApiObjectCollection(['data' => $included->toArray()], 6);
$this->assertCount(6, $included);

foreach ($included as $record) {
$this->assertRegExp('/posts|comments|user/', $record['type'], 'Unexpected record type included with resource');
$expected = array_flatten([$user->posts, $user->comments, $user->comments->pluck('creator')]);
$types = ['posts', 'posts', 'comments', 'comments', 'users', 'users'];

for ($i = 0; $i < count($included); $i++) {
$this->assertEquals($types[$i], $included[$i]['type']);
$this->assertEquals($expected[$i]->id, $included[$i]['id']);
}
}

Expand Down

0 comments on commit 5adc644

Please sign in to comment.