AssertInclude::assertIncludeObjectContains()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 11
ccs 3
cts 6
cp 0.5
crap 2.5
rs 10
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
The condition is_array($expected) is always true.
Loading history...
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