@@ -228,7 +228,28 @@ public function testCloseAfterGetRequestFromConstructorFailsWillCancelPendingRet
228228 $ es ->close ();
229229 }
230230
231- public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithInvalidStatusCode ()
231+ public function provideInvalidStatusCode ()
232+ {
233+ return [
234+ [
235+ new Response (400 , ['Content-Type ' => 'text/event-stream ' ], '' ),
236+ 'Expected "200 OK" response status, "400 Bad Request" response status returned '
237+ ],
238+ [
239+ new Response (500 , ['Content-Type ' => 'text/event-stream ' ], '' , '1.1 ' , "Intern \xE4l Server Err \xF6r " ),
240+ 'Expected "200 OK" response status, "500 Intern\344l Server Err\366r" response status returned '
241+ ],
242+ [
243+ new Response (400 , ['Content-Type ' => 'text/event-stream ' ], '' , '1.1 ' , str_repeat ('a ' , 200 )),
244+ 'Expected "200 OK" response status, "400 ' . str_repeat ('a ' , 96 ) . '" response status returned '
245+ ]
246+ ];
247+ }
248+
249+ /**
250+ * @dataProvider provideInvalidStatusCode
251+ */
252+ public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithInvalidStatusCode ($ response , $ expectedMessage )
232253 {
233254 $ deferred = new Deferred ();
234255 $ browser = $ this ->getMockBuilder ('React\Http\Browser ' )->disableOriginalConstructor ()->getMock ();
@@ -244,14 +265,45 @@ public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithIn
244265 $ caught = $ e ;
245266 });
246267
247- $ response = new Response (400 , array ('Content-Type ' => 'text/event-stream ' ), '' );
248268 $ deferred ->resolve ($ response );
249269
250270 $ this ->assertEquals (EventSource::CLOSED , $ readyState );
251- $ this ->assertInstanceOf ('UnexpectedValueException ' , $ caught );
252- }
253-
254- public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithInvalidContentType ()
271+ $ this ->assertInstanceOf ('React\Http\Message\ResponseException ' , $ caught );
272+ $ this ->assertEquals ($ expectedMessage , $ caught ->getMessage ());
273+ $ this ->assertEquals ($ response ->getStatusCode (), $ caught ->getCode ());
274+ $ this ->assertSame ($ response , $ caught ->getResponse ());
275+ }
276+
277+ public function provideInvalidContentType ()
278+ {
279+ return [
280+ [
281+ new Response (200 , [], '' ),
282+ 'Expected "Content-Type: text/event-stream" response header, no "Content-Type" response header returned '
283+ ],
284+ [
285+ new Response (200 , ['Content-Type ' => '' ], '' ),
286+ 'Expected "Content-Type: text/event-stream" response header, "Content-Type: " response header returned '
287+ ],
288+ [
289+ new Response (200 , ['Content-Type ' => 'text/html ' ], '' ),
290+ 'Expected "Content-Type: text/event-stream" response header, "Content-Type: text/html" response header returned '
291+ ],
292+ [
293+ new Response (200 , ['Content-Type ' => "application/json; invalid=a \xE4b " ], '' ),
294+ 'Expected "Content-Type: text/event-stream" response header, "Content-Type: application/json; invalid=a\344b" response header returned '
295+ ],
296+ [
297+ new Response (200 , ['Content-Type ' => str_repeat ('a ' , 200 )], '' ),
298+ 'Expected "Content-Type: text/event-stream" response header, "Content-Type: ' . str_repeat ('a ' , 86 ) . '" response header returned '
299+ ]
300+ ];
301+ }
302+
303+ /**
304+ * @dataProvider provideInvalidContentType
305+ */
306+ public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithInvalidContentType ($ response , $ expectedMessage )
255307 {
256308 $ deferred = new Deferred ();
257309 $ browser = $ this ->getMockBuilder ('React\Http\Browser ' )->disableOriginalConstructor ()->getMock ();
@@ -267,11 +319,12 @@ public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithIn
267319 $ caught = $ e ;
268320 });
269321
270- $ response = new Response (200 , array (), '' );
271322 $ deferred ->resolve ($ response );
272323
273324 $ this ->assertEquals (EventSource::CLOSED , $ readyState );
274- $ this ->assertInstanceOf ('UnexpectedValueException ' , $ caught );
325+ $ this ->assertInstanceOf ('React\Http\Message\ResponseException ' , $ caught );
326+ $ this ->assertEquals ($ expectedMessage , $ caught ->getMessage ());
327+ $ this ->assertSame ($ response , $ caught ->getResponse ());
275328 }
276329
277330 public function testConstructorWillReportOpenWhenGetResponseResolvesWithValidResponse ()
0 commit comments