assertResponseJsonapiObjectEquals()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace VGirol\JsonApiAssert\Laravel\Asserts\Content;
4
5
use Illuminate\Testing\TestResponse;
6
use VGirol\JsonApiConstant\Members;
7
8
/**
9
 * This trait adds the ability to test jsonapi object.
10
 */
11
trait AssertJsonapiObject
12
{
13
    /**
14
     * Asserts that a jsonapi object equals an expected array.
15
     *
16
     * @param TestResponse $response
17
     * @param array       $expected
18
     *
19
     * @return void
20
     * @throws \PHPUnit\Framework\AssertionFailedError
21
     */
22 18
    public static function assertResponseJsonapiObjectEquals(TestResponse $response, $expected)
23
    {
24 18
        if (!\is_array($expected)) {
0 ignored issues
show
introduced by
The condition is_array($expected) is always true.
Loading history...
25 3
            static::invalidArgument(
26 3
                2,
27 3
                'array',
28
                $expected
29
            );
30
        }
31
32
        // Decode JSON response
33 15
        $json = $response->json();
34
35 15
        static::assertHasMember(Members::JSONAPI, $json);
36
37 9
        $jsonapi = $json[Members::JSONAPI];
38
39 9
        static::assertJsonapiObjectEquals($expected, $jsonapi);
40 6
    }
41
}
42