Completed
Push — master ( 90b7b5...6b8d75 )
by Vincent
05:41 queued 10s
created

AssertJsonapiObject   A

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 10
cts 10
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\Foundation\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\ExpectationFailedException
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 1
                $expected
29
            );
30
        }
31
32
        // Decode JSON response
33 15
        $json = $response->json();
0 ignored issues
show
Bug introduced by
The method json() does not exist on Illuminate\Foundation\Testing\TestResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        /** @scrutinizer ignore-call */ 
34
        $json = $response->json();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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