GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 319321...4eac6b )
by Maxime
02:20
created

ResponseTest::testWithErrorUsingCustomHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.4286
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace EllipseSynergie\ApiResponse\Tests;
4
5
use EllipseSynergie\ApiResponse\Tests\Laravel\ResponseFake;
6
use EllipseSynergie\ApiResponse\Tests\ResponseFaker as Response;
7
use League\Fractal\Manager;
8
use League\Fractal\Pagination\Cursor;
9
10
/**
11
 * Class ResponseTest
12
 *
13
 * @package EllipseSynergie\ApiResponse\Tests
14
 * @author Maxime Beaudoin <[email protected]>
15
 */
16
class ResponseTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @var Response
20
     */
21
    protected $response;
22
23
    public function setUp()
24
    {
25
        $this->response = new Response(new Manager());
26
    }
27
28
    public function testImplementContractProperly()
29
    {
30
        $this->assertInstanceOf('EllipseSynergie\ApiResponse\Contracts\Response', $this->response);
31
    }
32
33
    public function testGetManager()
34
    {
35
        $this->assertInstanceOf('League\Fractal\Manager', $this->response->getManager());
36
    }
37
38
    public function testSetStatusCodeWorkProperly()
39
    {
40
        $this->response->setStatusCode(201);
41
42
        $this->assertSame(201, $this->response->getStatusCode());
43
    }
44
45
    public function testDefaultStatusCodeIs200()
46
    {
47
        $this->assertSame(200, $this->response->getStatusCode());
48
    }
49
50
    public function testErrorForbiddenStatusCodeIs403()
51
    {
52
        $response = $this->response->errorForbidden();
53
        $this->assertSame(403, $response['status']);
54
    }
55
56
    public function testErrorInternalErrorStatusCodeIs500()
57
    {
58
        $response = $this->response->errorInternalError();
59
        $this->assertSame(500, $response['status']);
60
    }
61
62
    public function testErrorNotFoundStatusCodeIs404()
63
    {
64
        $response = $this->response->errorNotFound();
65
        $this->assertSame(404, $response['status']);
66
    }
67
68
    public function testErrorUnauthorizedStatusCodeIs401()
69
    {
70
        $response = $this->response->errorUnauthorized();
71
        $this->assertSame(401, $response['status']);
72
    }
73
74
    public function testErrorWrongArgsStatusCodeIs400()
75
    {
76
        $response = $this->response->errorWrongArgs();
77
        $this->assertSame(400, $response['status']);
78
    }
79
80
    public function testErrorGoneStatusCodeIs410()
81
    {
82
        $response = $this->response->errorGone();
83
        $this->assertSame(410, $response['status']);
84
    }
85
86
    public function testErrorMethodNotAllowedStatusCodeIs405()
87
    {
88
        $response = $this->response->errorMethodNotAllowed();
89
        $this->assertSame(405, $response['status']);
90
    }
91
92
    public function testErrorUnwillingToProcessStatusCodeIs405()
93
    {
94
        $response = $this->response->errorUnwillingToProcess();
95
        $this->assertSame(431, $response['status']);
96
    }
97
98
    public function testWithItemReturnDataProperly()
99
    {
100
        $item = ['foo' => 'bar'];
101
102
        $response = $this->response->withItem($item, function ($data) {
103
            return $data;
104
        });
105
106
        $this->assertSame('bar', $response['data']['foo']);
107
    }
108
109
    public function testWithItemReturnMetaProperly()
110
    {
111
        $item = ['foo' => 'bar'];
112
113
        $response = $this->response->withItem($item, function ($data) {
114
            return $data;
115
        }, 'data', ['foo' => 'bar']);
116
117
        $this->assertSame('bar', $response['meta']['foo']);
118
    }
119
120
    public function testWithCollectionReturnDataProperly()
121
    {
122
        $item = [
123
            ['foo' => 'bar'],
124
            ['foo' => 'maxime'],
125
        ];
126
127
        $response = $this->response->withCollection($item, function ($data) {
128
            return $data;
129
        });
130
131
        $this->assertSame('bar', $response['data'][0]['foo']);
132
        $this->assertSame('maxime', $response['data'][1]['foo']);
133
    }
134
135
    public function testWithCollectionReturnMetaProperly()
136
    {
137
        $item = [
138
            ['foo' => 'bar'],
139
            ['foo' => 'maxime'],
140
        ];
141
142
        $response = $this->response->withCollection($item, function ($data) {
143
            return $data;
144
        }, null, null, ['foo' => 'bar']);
145
146
        $this->assertSame('bar', $response['meta']['foo']);
147
    }
148
149
    public function testWithCollectionReturnCursorProperly()
150
    {
151
        $item = [
152
            ['foo' => 'bar'],
153
            ['foo' => 'maxime'],
154
        ];
155
156
        $response = $this->response->withCollection($item, function ($data) {
157
            return $data;
158
        }, null, new Cursor(100, 1, 200, 300), ['foo' => 'bar']);
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
159
160
        $this->assertSame(
161
            [
162
                'current' => 100,
163
                'prev' => 1,
164
                'next' => 200,
165
                'count' => 300,
166
            ],
167
            $response['meta']['cursor']
168
        );
169
    }
170
171
    public function testWithErrorUsingCustomHeaders()
172
    {
173
        $response = $this->response
174
            ->setStatusCode(401)
175
            ->withError('Custom message', ResponseFake::CODE_UNAUTHORIZED, [
176
                'Authorization' => 'Foo'
177
            ]);
178
179
        $this->assertSame([
180
            'status' => 401,
181
            'headers' => [
182
                'Authorization' => 'Foo'
183
            ],
184
            'error' => [
185
                'code' => 'GEN-UNAUTHORIZED',
186
                'http_code' => 401,
187
                'message' => 'Custom message'
188
            ]
189
        ], $response);
190
    }
191
}
192