testShouldProxyWithRequestTarget()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 9.7998
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OAuth2\HttpClient\Test\Request;
6
7
use Facile\OAuth2\HttpClient\Request\OAuth2Request;
8
use PHPUnit\Framework\TestCase;
9
use Psr\Http\Message\RequestInterface;
10
use Psr\Http\Message\StreamInterface;
11
use Psr\Http\Message\UriInterface;
12
13
class OAuth2RequestTest extends TestCase
14
{
15
    public function testGrantParams(): void
16
    {
17
        $request = $this->prophesize(RequestInterface::class);
18
        $oauth2Request = new OAuth2Request($request->reveal());
19
20
        $params = ['foo' => 'bar'];
21
22
        $this->assertSame([], $oauth2Request->getGrantParams());
23
24
        $requestWithGrantParams = $oauth2Request->withGrantParams($params);
25
        $this->assertNotSame($oauth2Request, $requestWithGrantParams);
26
        $this->assertSame($params, $requestWithGrantParams->getGrantParams());
27
28
        $this->assertNotSame($oauth2Request, $requestWithGrantParams->withoutGrantParam('foo'));
29
        $this->assertSame([], $requestWithGrantParams->withoutGrantParam('foo')->getGrantParams());
30
31
        $this->assertNotSame($oauth2Request, $requestWithGrantParams->withGrantParam('baz', 'foz'));
32
        $this->assertSame(['foo' => 'bar', 'baz' => 'foz'], $requestWithGrantParams->withGrantParam('baz', 'foz')->getGrantParams());
33
    }
34
35
    public function testShouldProxyProtocolVersion(): void
36
    {
37
        $request = $this->prophesize(RequestInterface::class);
38
        $oauth2Request = new OAuth2Request($request->reveal());
39
40
        $expected = 'foo';
41
        $request->withProtocolVersion($expected)->shouldBeCalled()->willReturn($request->reveal());
42
        $request->getProtocolVersion()->shouldBeCalled()->willReturn($expected);
43
        $requestWith = $oauth2Request->withProtocolVersion($expected);
44
        $this->assertNotSame($oauth2Request, $requestWith);
45
        $this->assertSame($expected, $requestWith->getProtocolVersion());
46
    }
47
48
    public function testShouldProxyWithProtocolVersion(): void
49
    {
50
        $request = $this->prophesize(RequestInterface::class);
51
        $newRequest = $this->prophesize(RequestInterface::class);
52
        $oauth2Request = new OAuth2Request($request->reveal());
53
54
        $request->withProtocolVersion('foo')->shouldBeCalled()->willReturn($newRequest->reveal());
55
        $newRequest->getMethod()->willReturn('baz');
0 ignored issues
show
Bug introduced by
The method getMethod() does not exist on Prophecy\Prophecy\ObjectProphecy. Did you maybe mean getMethodProphecies()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
56
        $requestWith = $oauth2Request->withProtocolVersion('foo');
57
        $this->assertNotSame($oauth2Request, $requestWith);
58
        $this->assertSame('baz', $requestWith->getMethod());
59
    }
60
61
    public function testShouldProxyGetHeaders(): void
62
    {
63
        $request = $this->prophesize(RequestInterface::class);
64
        $oauth2Request = new OAuth2Request($request->reveal());
65
66
        $expected = [
67
            'Authorization' => [
68
                ['foo' => 'bar'],
69
            ],
70
        ];
71
        $request->getHeaders()->shouldBeCalled()->willReturn($expected);
72
        $this->assertSame($expected, $oauth2Request->getHeaders());
73
    }
74
75
    public function testShouldProxyHasHeader(): void
76
    {
77
        $request = $this->prophesize(RequestInterface::class);
78
        $oauth2Request = new OAuth2Request($request->reveal());
79
80
        $request->hasHeader('Authorization')->shouldBeCalled()->willReturn(true);
81
        $this->assertTrue($oauth2Request->hasHeader('Authorization'));
82
    }
83
84
    public function testShouldProxyGetHeader(): void
85
    {
86
        $request = $this->prophesize(RequestInterface::class);
87
        $oauth2Request = new OAuth2Request($request->reveal());
88
89
        $expected = [
90
            'Authorization' => [
91
                ['foo' => 'bar'],
92
            ],
93
        ];
94
        $request->getHeader('Authorization')->shouldBeCalled()->willReturn($expected['Authorization']);
95
        $this->assertSame($expected['Authorization'], $oauth2Request->getHeader('Authorization'));
96
    }
97
98
    public function testShouldProxyGetHeaderLine(): void
99
    {
100
        $request = $this->prophesize(RequestInterface::class);
101
        $oauth2Request = new OAuth2Request($request->reveal());
102
103
        $request->getHeaderLine('name')->shouldBeCalled()->willReturn('foo');
104
        $this->assertSame('foo', $oauth2Request->getHeaderLine('name'));
105
    }
106
107
    public function testShouldProxyWithHeader(): void
108
    {
109
        $request = $this->prophesize(RequestInterface::class);
110
        $newRequest = $this->prophesize(RequestInterface::class);
111
        $oauth2Request = new OAuth2Request($request->reveal());
112
113
        $request->withHeader('foo', 'bar')->shouldBeCalled()->willReturn($newRequest->reveal());
114
        $newRequest->getMethod()->willReturn('baz');
0 ignored issues
show
Bug introduced by
The method getMethod() does not exist on Prophecy\Prophecy\ObjectProphecy. Did you maybe mean getMethodProphecies()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
115
        $requestWith = $oauth2Request->withHeader('foo', 'bar');
116
        $this->assertNotSame($oauth2Request, $requestWith);
117
        $this->assertSame('baz', $requestWith->getMethod());
118
    }
119
120
    public function testShouldProxyWithAddedHeader(): void
121
    {
122
        $request = $this->prophesize(RequestInterface::class);
123
        $newRequest = $this->prophesize(RequestInterface::class);
124
        $oauth2Request = new OAuth2Request($request->reveal());
125
126
        $request->withAddedHeader('foo', 'bar')->shouldBeCalled()->willReturn($newRequest->reveal());
127
        $newRequest->getMethod()->willReturn('baz');
0 ignored issues
show
Bug introduced by
The method getMethod() does not exist on Prophecy\Prophecy\ObjectProphecy. Did you maybe mean getMethodProphecies()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
128
        $requestWith = $oauth2Request->withAddedHeader('foo', 'bar');
129
        $this->assertNotSame($oauth2Request, $requestWith);
130
        $this->assertSame('baz', $requestWith->getMethod());
131
    }
132
133
    public function testShouldProxyWithoutHeader(): void
134
    {
135
        $request = $this->prophesize(RequestInterface::class);
136
        $newRequest = $this->prophesize(RequestInterface::class);
137
        $oauth2Request = new OAuth2Request($request->reveal());
138
139
        $request->withoutHeader('foo')->shouldBeCalled()->willReturn($newRequest->reveal());
140
        $newRequest->getMethod()->willReturn('baz');
0 ignored issues
show
Bug introduced by
The method getMethod() does not exist on Prophecy\Prophecy\ObjectProphecy. Did you maybe mean getMethodProphecies()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
141
        $requestWith = $oauth2Request->withoutHeader('foo');
142
        $this->assertNotSame($oauth2Request, $requestWith);
143
        $this->assertSame('baz', $requestWith->getMethod());
144
    }
145
146
    public function testShouldProxyGetBody(): void
147
    {
148
        $request = $this->prophesize(RequestInterface::class);
149
        $oauth2Request = new OAuth2Request($request->reveal());
150
151
        $expected = $this->prophesize(StreamInterface::class);
152
        $request->getBody()->shouldBeCalled()->willReturn($expected->reveal());
153
        $this->assertSame($expected->reveal(), $oauth2Request->getBody());
154
    }
155
156
    public function testShouldProxyWithBody(): void
157
    {
158
        $request = $this->prophesize(RequestInterface::class);
159
        $newRequest = $this->prophesize(RequestInterface::class);
160
        $oauth2Request = new OAuth2Request($request->reveal());
161
162
        $body = $this->prophesize(StreamInterface::class);
163
164
        $request->withBody($body->reveal())->shouldBeCalled()->willReturn($newRequest->reveal());
165
        $newRequest->getBody()->willReturn($body->reveal());
166
        $requestWith = $oauth2Request->withBody($body->reveal());
167
        $this->assertNotSame($oauth2Request, $requestWith);
168
        $this->assertSame($body->reveal(), $requestWith->getBody());
169
    }
170
171
    public function testShouldProxyGetRequestTarget(): void
172
    {
173
        $request = $this->prophesize(RequestInterface::class);
174
        $oauth2Request = new OAuth2Request($request->reveal());
175
176
        $expected = 'foo';
177
        $request->getRequestTarget()->shouldBeCalled()->willReturn($expected);
178
        $this->assertSame($expected, $oauth2Request->getRequestTarget());
179
    }
180
181
    public function testShouldProxyWithRequestTarget(): void
182
    {
183
        $request = $this->prophesize(RequestInterface::class);
184
        $newRequest = $this->prophesize(RequestInterface::class);
185
        $oauth2Request = new OAuth2Request($request->reveal());
186
187
        $value = 'test';
188
189
        $request->withRequestTarget($value)->shouldBeCalled()->willReturn($newRequest->reveal());
190
        $newRequest->getRequestTarget()->willReturn($value);
191
        $requestWith = $oauth2Request->withRequestTarget($value);
192
        $this->assertNotSame($oauth2Request, $requestWith);
193
        $this->assertSame($value, $requestWith->getRequestTarget());
194
    }
195
196
    public function testShouldProxyGetMethod(): void
197
    {
198
        $request = $this->prophesize(RequestInterface::class);
199
        $oauth2Request = new OAuth2Request($request->reveal());
200
201
        $expected = 'foo';
202
        $request->getMethod()->shouldBeCalled()->willReturn($expected);
0 ignored issues
show
Bug introduced by
The method getMethod() does not exist on Prophecy\Prophecy\ObjectProphecy. Did you maybe mean getMethodProphecies()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
203
        $this->assertSame($expected, $oauth2Request->getMethod());
204
    }
205
206
    public function testShouldProxyWithMethod(): void
207
    {
208
        $request = $this->prophesize(RequestInterface::class);
209
        $newRequest = $this->prophesize(RequestInterface::class);
210
        $oauth2Request = new OAuth2Request($request->reveal());
211
212
        $value = 'test';
213
214
        $request->withMethod($value)->shouldBeCalled()->willReturn($newRequest->reveal());
215
        $newRequest->getMethod()->willReturn($value);
0 ignored issues
show
Bug introduced by
The method getMethod() does not exist on Prophecy\Prophecy\ObjectProphecy. Did you maybe mean getMethodProphecies()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
216
        $requestWith = $oauth2Request->withMethod($value);
217
        $this->assertNotSame($oauth2Request, $requestWith);
218
        $this->assertSame($value, $requestWith->getMethod());
219
    }
220
221
    public function testShouldProxyGetUri(): void
222
    {
223
        $request = $this->prophesize(RequestInterface::class);
224
        $oauth2Request = new OAuth2Request($request->reveal());
225
226
        $expected = $this->prophesize(UriInterface::class);
227
        $request->getUri()->shouldBeCalled()->willReturn($expected->reveal());
228
        $this->assertSame($expected->reveal(), $oauth2Request->getUri());
229
    }
230
231
    public function testShouldProxyWithUri(): void
232
    {
233
        $request = $this->prophesize(RequestInterface::class);
234
        $newRequest = $this->prophesize(RequestInterface::class);
235
        $oauth2Request = new OAuth2Request($request->reveal());
236
237
        $value = $this->prophesize(UriInterface::class);
238
239
        $request->withUri($value->reveal(), false)->shouldBeCalled()->willReturn($newRequest->reveal());
240
        $newRequest->getUri()->willReturn($value->reveal());
241
        $requestWith = $oauth2Request->withUri($value->reveal());
242
        $this->assertNotSame($oauth2Request, $requestWith);
243
        $this->assertSame($value->reveal(), $requestWith->getUri());
244
    }
245
}
246