Completed
Push — master ( c168df...1c946f )
by Vincent
13:50 queued 10s
created

AssertInclude::assertDocumentContainsInclude()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 7
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 6
     * @throws \PHPUnit\Framework\ExpectationFailedException
24
     */
25 6
    public static function assertIncludeObjectContains($expected, $json)
26 3
    {
27
        if (!\is_array($expected)) {
0 ignored issues
show
introduced by
The condition is_array($expected) is always true.
Loading history...
28
            static::invalidArgument(
29
                1,
30
                'array',
31
                $expected
32
            );
33
        }
34
35
        static::assertResourceCollectionContains($expected, $json);
36
    }
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\ExpectationFailedException
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