@@ -157,4 +157,98 @@ public function testXmlMethodReturnsXmlResponse()
157
157
$ this ->assertEquals ('application/xml ' , $ response ->getHeaderLine ('Content-Type ' ));
158
158
$ this ->assertEquals ('<?xml version="1.0" encoding="utf-8"?><body>Hello wörld!</body> ' , (string ) $ response ->getBody ());
159
159
}
160
+
161
+ public function testParseMessageWithMinimalOkResponse ()
162
+ {
163
+ $ response = Response::parseMessage ("HTTP/1.1 200 OK \r\n" );
164
+
165
+ $ this ->assertEquals ('1.1 ' , $ response ->getProtocolVersion ());
166
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
167
+ $ this ->assertEquals ('OK ' , $ response ->getReasonPhrase ());
168
+ $ this ->assertEquals (array (), $ response ->getHeaders ());
169
+ }
170
+
171
+ public function testParseMessageWithSimpleOkResponse ()
172
+ {
173
+ $ response = Response::parseMessage ("HTTP/1.1 200 OK \r\nServer: demo \r\n" );
174
+
175
+ $ this ->assertEquals ('1.1 ' , $ response ->getProtocolVersion ());
176
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
177
+ $ this ->assertEquals ('OK ' , $ response ->getReasonPhrase ());
178
+ $ this ->assertEquals (array ('Server ' => array ('demo ' )), $ response ->getHeaders ());
179
+ }
180
+
181
+ public function testParseMessageWithSimpleOkResponseWithCustomReasonPhrase ()
182
+ {
183
+ $ response = Response::parseMessage ("HTTP/1.1 200 Mostly Okay \r\nServer: demo \r\n" );
184
+
185
+ $ this ->assertEquals ('1.1 ' , $ response ->getProtocolVersion ());
186
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
187
+ $ this ->assertEquals ('Mostly Okay ' , $ response ->getReasonPhrase ());
188
+ $ this ->assertEquals (array ('Server ' => array ('demo ' )), $ response ->getHeaders ());
189
+ }
190
+
191
+ public function testParseMessageWithSimpleOkResponseWithEmptyReasonPhraseAppliesDefault ()
192
+ {
193
+ $ response = Response::parseMessage ("HTTP/1.1 200 \r\nServer: demo \r\n" );
194
+
195
+ $ this ->assertEquals ('1.1 ' , $ response ->getProtocolVersion ());
196
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
197
+ $ this ->assertEquals ('OK ' , $ response ->getReasonPhrase ());
198
+ $ this ->assertEquals (array ('Server ' => array ('demo ' )), $ response ->getHeaders ());
199
+ }
200
+
201
+ public function testParseMessageWithSimpleOkResponseWithoutReasonPhraseAndWhitespaceSeparatorAppliesDefault ()
202
+ {
203
+ $ response = Response::parseMessage ("HTTP/1.1 200 \r\nServer: demo \r\n" );
204
+
205
+ $ this ->assertEquals ('1.1 ' , $ response ->getProtocolVersion ());
206
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
207
+ $ this ->assertEquals ('OK ' , $ response ->getReasonPhrase ());
208
+ $ this ->assertEquals (array ('Server ' => array ('demo ' )), $ response ->getHeaders ());
209
+ }
210
+
211
+ public function testParseMessageWithHttp10SimpleOkResponse ()
212
+ {
213
+ $ response = Response::parseMessage ("HTTP/1.0 200 OK \r\nServer: demo \r\n" );
214
+
215
+ $ this ->assertEquals ('1.0 ' , $ response ->getProtocolVersion ());
216
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
217
+ $ this ->assertEquals ('OK ' , $ response ->getReasonPhrase ());
218
+ $ this ->assertEquals (array ('Server ' => array ('demo ' )), $ response ->getHeaders ());
219
+ }
220
+
221
+ public function testParseMessageWithHttp10SimpleOkResponseWithLegacyNewlines ()
222
+ {
223
+ $ response = Response::parseMessage ("HTTP/1.0 200 OK \nServer: demo \r\n" );
224
+
225
+ $ this ->assertEquals ('1.0 ' , $ response ->getProtocolVersion ());
226
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
227
+ $ this ->assertEquals ('OK ' , $ response ->getReasonPhrase ());
228
+ $ this ->assertEquals (array ('Server ' => array ('demo ' )), $ response ->getHeaders ());
229
+ }
230
+
231
+ public function testParseMessageWithInvalidHttpProtocolVersion12Throws ()
232
+ {
233
+ $ this ->setExpectedException ('InvalidArgumentException ' );
234
+ Response::parseMessage ("HTTP/1.2 200 OK \r\n" );
235
+ }
236
+
237
+ public function testParseMessageWithInvalidHttpProtocolVersion2Throws ()
238
+ {
239
+ $ this ->setExpectedException ('InvalidArgumentException ' );
240
+ Response::parseMessage ("HTTP/2 200 OK \r\n" );
241
+ }
242
+
243
+ public function testParseMessageWithInvalidStatusCodeUnderflowThrows ()
244
+ {
245
+ $ this ->setExpectedException ('InvalidArgumentException ' );
246
+ Response::parseMessage ("HTTP/1.1 99 OK \r\n" );
247
+ }
248
+
249
+ public function testParseMessageWithInvalidResponseHeaderFieldThrows ()
250
+ {
251
+ $ this ->setExpectedException ('InvalidArgumentException ' );
252
+ Response::parseMessage ("HTTP/1.1 200 OK \r\nServer \r\n" );
253
+ }
160
254
}
0 commit comments