1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Tests\Helpers\Stubs; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
use Psr\Http\Message\StreamInterface; |
9
|
|
|
|
10
|
|
|
class ResponseStub implements ResponseInterface |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
private $headers = []; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Retrieves the HTTP protocol version as a string. |
17
|
|
|
* |
18
|
|
|
* The string MUST contain only the HTTP version number (e.g., "1.1", "1.0"). |
19
|
|
|
* |
20
|
|
|
* @return string HTTP protocol version. |
21
|
|
|
*/ |
22
|
|
|
public function getProtocolVersion() |
23
|
|
|
{ |
24
|
|
|
// TODO: Implement getProtocolVersion() method. |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Return an instance with the specified HTTP protocol version. |
29
|
|
|
* |
30
|
|
|
* The version string MUST contain only the HTTP version number (e.g., |
31
|
|
|
* "1.1", "1.0"). |
32
|
|
|
* |
33
|
|
|
* This method MUST be implemented in such a way as to retain the |
34
|
|
|
* immutability of the message, and MUST return an instance that has the |
35
|
|
|
* new protocol version. |
36
|
|
|
* |
37
|
|
|
* @param string $version HTTP protocol version |
38
|
|
|
* @return static |
39
|
|
|
*/ |
40
|
|
|
public function withProtocolVersion($version) |
41
|
|
|
{ |
42
|
|
|
// TODO: Implement withProtocolVersion() method. |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Retrieves all message header values. |
47
|
|
|
* |
48
|
|
|
* The keys represent the header name as it will be sent over the wire, and |
49
|
|
|
* each value is an array of strings associated with the header. |
50
|
|
|
* |
51
|
|
|
* // Represent the headers as a string |
52
|
|
|
* foreach ($message->getHeaders() as $name => $values) { |
53
|
|
|
* echo $name . ": " . implode(", ", $values); |
54
|
|
|
* } |
55
|
|
|
* |
56
|
|
|
* // Emit headers iteratively: |
57
|
|
|
* foreach ($message->getHeaders() as $name => $values) { |
58
|
|
|
* foreach ($values as $value) { |
59
|
|
|
* header(sprintf('%s: %s', $name, $value), false); |
60
|
|
|
* } |
61
|
|
|
* } |
62
|
|
|
* |
63
|
|
|
* While header names are not case-sensitive, getHeaders() will preserve the |
64
|
|
|
* exact case in which headers were originally specified. |
65
|
|
|
* |
66
|
|
|
* @return string[][] Returns an associative array of the message's headers. Each |
67
|
|
|
* key MUST be a header name, and each value MUST be an array of strings |
68
|
|
|
* for that header. |
69
|
|
|
*/ |
70
|
|
|
public function getHeaders() |
71
|
|
|
{ |
72
|
|
|
return $this->headers; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Checks if a header exists by the given case-insensitive name. |
77
|
|
|
* |
78
|
|
|
* @param string $name Case-insensitive header field name. |
79
|
|
|
* @return bool Returns true if any header names match the given header |
80
|
|
|
* name using a case-insensitive string comparison. Returns false if |
81
|
|
|
* no matching header name is found in the message. |
82
|
|
|
*/ |
83
|
|
|
public function hasHeader($name) |
84
|
|
|
{ |
85
|
|
|
// TODO: Implement hasHeader() method. |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Retrieves a message header value by the given case-insensitive name. |
90
|
|
|
* |
91
|
|
|
* This method returns an array of all the header values of the given |
92
|
|
|
* case-insensitive header name. |
93
|
|
|
* |
94
|
|
|
* If the header does not appear in the message, this method MUST return an |
95
|
|
|
* empty array. |
96
|
|
|
* |
97
|
|
|
* @param string $name Case-insensitive header field name. |
98
|
|
|
* @return string[] An array of string values as provided for the given |
99
|
|
|
* header. If the header does not appear in the message, this method MUST |
100
|
|
|
* return an empty array. |
101
|
|
|
*/ |
102
|
|
|
public function getHeader($name) |
103
|
|
|
{ |
104
|
|
|
// TODO: Implement getHeader() method. |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Retrieves a comma-separated string of the values for a single header. |
109
|
|
|
* |
110
|
|
|
* This method returns all of the header values of the given |
111
|
|
|
* case-insensitive header name as a string concatenated together using |
112
|
|
|
* a comma. |
113
|
|
|
* |
114
|
|
|
* NOTE: Not all header values may be appropriately represented using |
115
|
|
|
* comma concatenation. For such headers, use getHeader() instead |
116
|
|
|
* and supply your own delimiter when concatenating. |
117
|
|
|
* |
118
|
|
|
* If the header does not appear in the message, this method MUST return |
119
|
|
|
* an empty string. |
120
|
|
|
* |
121
|
|
|
* @param string $name Case-insensitive header field name. |
122
|
|
|
* @return string A string of values as provided for the given header |
123
|
|
|
* concatenated together using a comma. If the header does not appear in |
124
|
|
|
* the message, this method MUST return an empty string. |
125
|
|
|
*/ |
126
|
|
|
public function getHeaderLine($name) |
127
|
|
|
{ |
128
|
|
|
// TODO: Implement getHeaderLine() method. |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Return an instance with the provided value replacing the specified header. |
133
|
|
|
* |
134
|
|
|
* While header names are case-insensitive, the casing of the header will |
135
|
|
|
* be preserved by this function, and returned from getHeaders(). |
136
|
|
|
* |
137
|
|
|
* This method MUST be implemented in such a way as to retain the |
138
|
|
|
* immutability of the message, and MUST return an instance that has the |
139
|
|
|
* new and/or updated header and value. |
140
|
|
|
* |
141
|
|
|
* @param string $name Case-insensitive header field name. |
142
|
|
|
* @param string|string[] $value Header value(s). |
143
|
|
|
* @return static |
144
|
|
|
* @throws \InvalidArgumentException for invalid header names or values. |
145
|
|
|
*/ |
146
|
|
|
public function withHeader($name, $value) |
147
|
|
|
{ |
148
|
|
|
$this->headers[$name] = $value; |
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Return an instance with the specified header appended with the given value. |
154
|
|
|
* |
155
|
|
|
* Existing values for the specified header will be maintained. The new |
156
|
|
|
* value(s) will be appended to the existing list. If the header did not |
157
|
|
|
* exist previously, it will be added. |
158
|
|
|
* |
159
|
|
|
* This method MUST be implemented in such a way as to retain the |
160
|
|
|
* immutability of the message, and MUST return an instance that has the |
161
|
|
|
* new header and/or value. |
162
|
|
|
* |
163
|
|
|
* @param string $name Case-insensitive header field name to add. |
164
|
|
|
* @param string|string[] $value Header value(s). |
165
|
|
|
* @return static |
166
|
|
|
* @throws \InvalidArgumentException for invalid header names or values. |
167
|
|
|
*/ |
168
|
|
|
public function withAddedHeader($name, $value) |
169
|
|
|
{ |
170
|
|
|
return $this->withHeader($name, $value); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Return an instance without the specified header. |
175
|
|
|
* |
176
|
|
|
* Header resolution MUST be done without case-sensitivity. |
177
|
|
|
* |
178
|
|
|
* This method MUST be implemented in such a way as to retain the |
179
|
|
|
* immutability of the message, and MUST return an instance that removes |
180
|
|
|
* the named header. |
181
|
|
|
* |
182
|
|
|
* @param string $name Case-insensitive header field name to remove. |
183
|
|
|
* @return static |
184
|
|
|
*/ |
185
|
|
|
public function withoutHeader($name) |
186
|
|
|
{ |
187
|
|
|
// TODO: Implement withoutHeader() method. |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Gets the body of the message. |
192
|
|
|
* |
193
|
|
|
* @return StreamInterface Returns the body as a stream. |
194
|
|
|
*/ |
195
|
|
|
public function getBody() |
196
|
|
|
{ |
197
|
|
|
return new StreamStub(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Return an instance with the specified message body. |
202
|
|
|
* |
203
|
|
|
* The body MUST be a StreamInterface object. |
204
|
|
|
* |
205
|
|
|
* This method MUST be implemented in such a way as to retain the |
206
|
|
|
* immutability of the message, and MUST return a new instance that has the |
207
|
|
|
* new body stream. |
208
|
|
|
* |
209
|
|
|
* @param StreamInterface $body Body. |
210
|
|
|
* @return static |
211
|
|
|
* @throws \InvalidArgumentException When the body is not valid. |
212
|
|
|
*/ |
213
|
|
|
public function withBody(StreamInterface $body) |
214
|
|
|
{ |
215
|
|
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Gets the response status code. |
220
|
|
|
* |
221
|
|
|
* The status code is a 3-digit integer result code of the server's attempt |
222
|
|
|
* to understand and satisfy the request. |
223
|
|
|
* |
224
|
|
|
* @return int Status code. |
225
|
|
|
*/ |
226
|
|
|
public function getStatusCode() |
227
|
|
|
{ |
228
|
|
|
// TODO: Implement getStatusCode() method. |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Return an instance with the specified status code and, optionally, reason phrase. |
233
|
|
|
* |
234
|
|
|
* If no reason phrase is specified, implementations MAY choose to default |
235
|
|
|
* to the RFC 7231 or IANA recommended reason phrase for the response's |
236
|
|
|
* status code. |
237
|
|
|
* |
238
|
|
|
* This method MUST be implemented in such a way as to retain the |
239
|
|
|
* immutability of the message, and MUST return an instance that has the |
240
|
|
|
* updated status and reason phrase. |
241
|
|
|
* |
242
|
|
|
* @link http://tools.ietf.org/html/rfc7231#section-6 |
243
|
|
|
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
244
|
|
|
* @param int $code The 3-digit integer result code to set. |
245
|
|
|
* @param string $reasonPhrase The reason phrase to use with the |
246
|
|
|
* provided status code; if none is provided, implementations MAY |
247
|
|
|
* use the defaults as suggested in the HTTP specification. |
248
|
|
|
* @return static |
249
|
|
|
* @throws \InvalidArgumentException For invalid status code arguments. |
250
|
|
|
*/ |
251
|
|
|
public function withStatus($code, $reasonPhrase = '') |
252
|
|
|
{ |
253
|
|
|
// TODO: Implement withStatus() method. |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Gets the response reason phrase associated with the status code. |
258
|
|
|
* |
259
|
|
|
* Because a reason phrase is not a required element in a response |
260
|
|
|
* status line, the reason phrase value MAY be null. Implementations MAY |
261
|
|
|
* choose to return the default RFC 7231 recommended reason phrase (or those |
262
|
|
|
* listed in the IANA HTTP Status Code Registry) for the response's |
263
|
|
|
* status code. |
264
|
|
|
* |
265
|
|
|
* @link http://tools.ietf.org/html/rfc7231#section-6 |
266
|
|
|
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
267
|
|
|
* @return string Reason phrase; must return an empty string if none present. |
268
|
|
|
*/ |
269
|
|
|
public function getReasonPhrase() |
270
|
|
|
{ |
271
|
|
|
// TODO: Implement getReasonPhrase() method. |
272
|
|
|
} |
273
|
|
|
} |