Passed
Push — master ( fae453...efb6a4 )
by Vincent
02:44
created

PaginationTest::response_pagination_links()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 22
rs 9.8333
cc 1
nc 1
nop 0
1
<?php
2
namespace VGirol\JsonApiAssert\Laravel\Tests\Asserts\Response;
3
4
use Illuminate\Foundation\Testing\TestResponse;
5
use Illuminate\Http\Response;
6
use VGirol\JsonApiAssert\Laravel\Assert;
7
use VGirol\JsonApiAssert\Laravel\Tests\TestCase;
8
use VGirol\JsonApiAssert\Messages;
9
10
class PaginationTest extends TestCase
11
{
12
    /**
13
     * @test
14
     */
15
    public function response_pagination_links()
16
    {
17
        $status = 200;
18
        $headers = [
19
            'Content-Type' => [self::$mediaType]
20
        ];
21
22
        $content = [
23
            'links' => [
24
                'first' => 'url',
25
                'last' => 'url'
26
            ]
27
        ];
28
        $expected = [
29
            'first' => 'url',
30
            'last' => 'url'
31
        ];
32
33
        $response = Response::create(json_encode($content), $status, $headers);
34
        $response = TestResponse::fromBaseResponse($response);
35
36
        $response->assertJsonApiPaginationLinks($expected);
37
    }
38
39
    /**
40
     * @test
41
     * @dataProvider paginationLinksFailedProvider
42
     */
43
    public function response_pagination_links_failed($content, $expected, $failureMsg)
44
    {
45
        $fn = function ($content, $expected) {
46
            $status = 200;
47
            $headers = [
48
                'Content-Type' => [self::$mediaType]
49
            ];
50
51
            $response = Response::create(json_encode($content), $status, $headers);
52
            $response = TestResponse::fromBaseResponse($response);
53
54
            $response->assertJsonApiPaginationLinks($expected);
55
        };
56
57
        Assert::assertTestFail($fn, $failureMsg, $content, $expected);
58
    }
59
60
    public function paginationLinksFailedProvider()
61
    {
62
        return [
63
            'no links member' => [
64
                [
65
                    'meta' => [
66
                        'bad' => 'content'
67
                    ]
68
                ],
69
                [
70
                    'first' => 'url',
71
                    'last' => 'url'
72
                ],
73
                sprintf(Messages::HAS_MEMBER, 'links')
74
            ],
75
            'bad links member' => [
76
                [
77
                    'links' => [
78
                        'first' => 'url',
79
                        'bad' => 'url'
80
                    ]
81
                ],
82
                [
83
                    'first' => 'url',
84
                    'last' => 'url'
85
                ],
86
                null
87
            ],
88
            'no match' => [
89
                [
90
                    'links' => [
91
                        'first' => 'url',
92
                        'last' => 'url2'
93
                    ]
94
                ],
95
                [
96
                    'first' => 'url',
97
                    'last' => 'url'
98
                ],
99
                null
100
            ]
101
        ];
102
    }
103
}
104