1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Sunrise\Http\Client\Curl\Tests; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use LogicException; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
11
|
|
|
use Psr\Http\Message\StreamInterface; |
12
|
|
|
use Sunrise\Http\Client\Curl\MultiResponse; |
13
|
|
|
|
14
|
|
|
final class MultiResponseTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testCreateWithoutResponses(): void |
17
|
|
|
{ |
18
|
|
|
$this->expectException(InvalidArgumentException::class); |
19
|
|
|
new MultiResponse(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testGetResponses(): void |
23
|
|
|
{ |
24
|
|
|
$responses = [ |
25
|
|
|
$this->createMock(ResponseInterface::class), |
26
|
|
|
$this->createMock(ResponseInterface::class), |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
self::assertSame($responses, (new MultiResponse(...$responses))->getResponses()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetProtocolVersion(): void |
33
|
|
|
{ |
34
|
|
|
$response = $this->createMock(ResponseInterface::class); |
35
|
|
|
$multiResponse = new MultiResponse($response); |
36
|
|
|
$this->expectException(LogicException::class); |
37
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
38
|
|
|
$multiResponse->getProtocolVersion(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testWithProtocolVersion(): void |
42
|
|
|
{ |
43
|
|
|
$response = $this->createMock(ResponseInterface::class); |
44
|
|
|
$multiResponse = new MultiResponse($response); |
45
|
|
|
$this->expectException(LogicException::class); |
46
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
47
|
|
|
$multiResponse->withProtocolVersion('1.1'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testGetHeaders(): void |
51
|
|
|
{ |
52
|
|
|
$response = $this->createMock(ResponseInterface::class); |
53
|
|
|
$multiResponse = new MultiResponse($response); |
54
|
|
|
$this->expectException(LogicException::class); |
55
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
56
|
|
|
$multiResponse->getHeaders(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testHasHeader(): void |
60
|
|
|
{ |
61
|
|
|
$response = $this->createMock(ResponseInterface::class); |
62
|
|
|
$multiResponse = new MultiResponse($response); |
63
|
|
|
$this->expectException(LogicException::class); |
64
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
65
|
|
|
$multiResponse->hasHeader('X-Test'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGetHeader(): void |
69
|
|
|
{ |
70
|
|
|
$response = $this->createMock(ResponseInterface::class); |
71
|
|
|
$multiResponse = new MultiResponse($response); |
72
|
|
|
$this->expectException(LogicException::class); |
73
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
74
|
|
|
$multiResponse->getHeader('X-Test'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testGetHeaderLine(): void |
78
|
|
|
{ |
79
|
|
|
$response = $this->createMock(ResponseInterface::class); |
80
|
|
|
$multiResponse = new MultiResponse($response); |
81
|
|
|
$this->expectException(LogicException::class); |
82
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
83
|
|
|
$multiResponse->getHeaderLine('X-Test'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testWithHeader(): void |
87
|
|
|
{ |
88
|
|
|
$response = $this->createMock(ResponseInterface::class); |
89
|
|
|
$multiResponse = new MultiResponse($response); |
90
|
|
|
$this->expectException(LogicException::class); |
91
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
92
|
|
|
$multiResponse->withHeader('X-Test', 'test'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testWithAddedHeader(): void |
96
|
|
|
{ |
97
|
|
|
$response = $this->createMock(ResponseInterface::class); |
98
|
|
|
$multiResponse = new MultiResponse($response); |
99
|
|
|
$this->expectException(LogicException::class); |
100
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
101
|
|
|
$multiResponse->withAddedHeader('X-Test', 'test'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testWithoutHeader(): void |
105
|
|
|
{ |
106
|
|
|
$response = $this->createMock(ResponseInterface::class); |
107
|
|
|
$multiResponse = new MultiResponse($response); |
108
|
|
|
$this->expectException(LogicException::class); |
109
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
110
|
|
|
$multiResponse->withoutHeader('X-Test'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testGetBody(): void |
114
|
|
|
{ |
115
|
|
|
$response = $this->createMock(ResponseInterface::class); |
116
|
|
|
$multiResponse = new MultiResponse($response); |
117
|
|
|
$this->expectException(LogicException::class); |
118
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
119
|
|
|
$multiResponse->getBody(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testWithBody(): void |
123
|
|
|
{ |
124
|
|
|
$body = $this->createMock(StreamInterface::class); |
125
|
|
|
$response = $this->createMock(ResponseInterface::class); |
126
|
|
|
$multiResponse = new MultiResponse($response); |
127
|
|
|
$this->expectException(LogicException::class); |
128
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
129
|
|
|
$multiResponse->withBody($body); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testGetStatusCode(): void |
133
|
|
|
{ |
134
|
|
|
$response = $this->createMock(ResponseInterface::class); |
135
|
|
|
$multiResponse = new MultiResponse($response); |
136
|
|
|
$this->expectException(LogicException::class); |
137
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
138
|
|
|
$multiResponse->getStatusCode(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testWithStatus(): void |
142
|
|
|
{ |
143
|
|
|
$response = $this->createMock(ResponseInterface::class); |
144
|
|
|
$multiResponse = new MultiResponse($response); |
145
|
|
|
$this->expectException(LogicException::class); |
146
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
147
|
|
|
$multiResponse->withStatus(200); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function testGetReasonPhrase(): void |
151
|
|
|
{ |
152
|
|
|
$response = $this->createMock(ResponseInterface::class); |
153
|
|
|
$multiResponse = new MultiResponse($response); |
154
|
|
|
$this->expectException(LogicException::class); |
155
|
|
|
$this->expectExceptionMessage('Not implemented.'); |
156
|
|
|
$multiResponse->getReasonPhrase(); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|