AssertJsonapiObject   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 9
c 0
b 0
f 0
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertResponseJsonapiObjectEquals() 0 18 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