AssertFetchedCollection   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertFetchedResourceCollectionResponse() 0 23 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 collection response.
11
 */
12
trait AssertFetchedCollection
13
{
14
    /**
15
     * Asserts that the response has "200 Ok" status code and valid content.
16
     *
17
     * @param TestResponse $response
18
     * @param array        $expected The expected collection of resource 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 24
    public static function assertFetchedResourceCollectionResponse(TestResponse $response, $expected, bool $strict)
25
    {
26 24
        $response->assertStatus(200);
27 21
        $response->assertHeader(
28 21
            HttpHeader::HEADER_NAME,
29 21
            HttpHeader::MEDIA_TYPE
30
        );
31
32
        // Decode JSON response
33 18
        $json = $response->json();
34
35
        // Checks response structure
36 18
        static::assertHasValidStructure(
37 18
            $json,
38
            $strict
39
        );
40
41
        // Checks data member
42 15
        static::assertHasData($json);
43 9
        $data = $json[Members::DATA];
44 9
        static::assertResourceCollectionEquals(
45 9
            $expected,
46
            $data
47
        );
48 6
    }
49
}
50