AssertFetchedRelationships   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 15
c 1
b 0
f 0
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertFetchedRelationshipsResponse() 0 24 1
1
<?php
2
3
namespace VGirol\JsonApiAssert\Laravel\Asserts\Response;
4
5
use Illuminate\Testing\TestResponse;
6
use VGirol\JsonApiAssert\Laravel\HttpHeader;
7
use VGirol\JsonApiConstant\Members;
8
9
/**
10
 * This trait adds the ability to test fetching relationship response.
11
 */
12
trait AssertFetchedRelationships
13
{
14
    /**
15
     * Asserts that the response has "200 Ok" status code and valid content.
16
     *
17
     * @param TestResponse $response
18
     * @param array|null   $expected The expected collection of resource identifier objects.
19
     * @param boolean      $strict   If true, unsafe characters are not allowed when checking members name.
20
     *
21
     * @return void
22
     * @throws \PHPUnit\Framework\AssertionFailedError
23
     */
24 51
    public static function assertFetchedRelationshipsResponse(TestResponse $response, $expected, $strict)
25
    {
26 51
        $response->assertStatus(200);
27 45
        $response->assertHeader(
28 45
            HttpHeader::HEADER_NAME,
29 45
            HttpHeader::MEDIA_TYPE
30
        );
31
32
        // Decode JSON response
33 39
        $json = $response->json();
34
35
        // Checks response structure
36 39
        static::assertHasValidStructure(
37 39
            $json,
38
            $strict
39
        );
40
41
        // Checks data member
42 33
        static::assertHasData($json);
43 24
        $data = $json[Members::DATA];
44 24
        static::assertResourceLinkageEquals(
45 24
            $expected,
46
            $data,
47
            $strict
48
        );
49 18
    }
50
}
51