Total Complexity | 3 |
Total Lines | 17 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | trait AssertIncluded |
||
10 | { |
||
11 | public static function assertIncludedObjectContains(TestResponse $response, $expectedCollection, $expectedResourceType) |
||
12 | { |
||
13 | // Decode JSON response |
||
14 | $json = $response->json(); |
||
15 | |||
16 | static::assertHasIncluded($json); |
||
17 | $included = $json['included']; |
||
18 | |||
19 | foreach ($expectedCollection as $expectedModel) { |
||
20 | $resCollection = collect($included)->filter(function ($item) use ($expectedModel, $expectedResourceType) { |
||
21 | return ($item['id'] == $expectedModel->getKey()) && ($item['type'] == $expectedResourceType); |
||
22 | }); |
||
23 | |||
24 | PHPUnit::assertEquals(1, $resCollection->count()); |
||
25 | static::assertResourceObjectEquals($expectedModel, $expectedResourceType, $resCollection->first()); |
||
26 | } |
||
29 |