1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace VGirol\JsonApiAssert\Asserts\Content; |
||
6 | |||
7 | use VGirol\JsonApiConstant\Members; |
||
8 | |||
9 | /** |
||
10 | * This trait adds the ability to test include content. |
||
11 | */ |
||
12 | trait AssertInclude |
||
13 | { |
||
14 | /** |
||
15 | * Asserts that an array of included resource objects contains a given resource object or collection. |
||
16 | * |
||
17 | * (@see assertResourceCollectionContains) |
||
18 | * |
||
19 | * @param array $expected A single resource object or an array of expected resource objects |
||
20 | * @param array $json The array of included resource objects to inspect |
||
21 | * |
||
22 | * @return void |
||
23 | * @throws \PHPUnit\Framework\AssertionFailedError |
||
24 | */ |
||
25 | 6 | public static function assertIncludeObjectContains($expected, $json) |
|
26 | { |
||
27 | 6 | if (!\is_array($expected)) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
28 | static::invalidArgument( |
||
29 | 1, |
||
30 | 'array', |
||
31 | $expected |
||
32 | ); |
||
33 | } |
||
34 | |||
35 | 6 | static::assertResourceCollectionContains($expected, $json); |
|
36 | 3 | } |
|
37 | |||
38 | /** |
||
39 | * Asserts that a JSON document contains an expected included collection. |
||
40 | * |
||
41 | * @param array $expected A single resource object or an array of expected resource objects |
||
42 | * @param array $json The JSON document to be tested |
||
43 | * |
||
44 | * @return void |
||
45 | * @throws \PHPUnit\Framework\AssertionFailedError |
||
46 | */ |
||
47 | public static function assertDocumentContainsInclude($expected, $json) |
||
48 | { |
||
49 | static::assertHasMember(Members::INCLUDED, $json); |
||
50 | |||
51 | $included = $json[Members::INCLUDED]; |
||
52 | |||
53 | static::assertIncludeObjectContains($expected, $included); |
||
54 | } |
||
55 | } |
||
56 |