@@ -346,7 +346,7 @@ public function testConstructorWillReportOpenWhenGetResponseResolvesWithValidRes
346346 $ this ->assertEquals (EventSource::OPEN , $ readyState );
347347 }
348348
349- public function testCloseResponseStreamWillStartRetryTimerWithoutErrorEvent ()
349+ public function testCloseResponseStreamWillStartRetryTimerWithErrorEvent ()
350350 {
351351 $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
352352 $ loop ->expects ($ this ->once ())->method ('addTimer ' )->with (
@@ -373,7 +373,33 @@ public function testCloseResponseStreamWillStartRetryTimerWithoutErrorEvent()
373373 $ stream ->close ();
374374
375375 $ this ->assertEquals (EventSource::CONNECTING , $ es ->readyState );
376- $ this ->assertNull ($ error );
376+ $ this ->assertInstanceOf ('RuntimeException ' , $ error );
377+ $ this ->assertEquals ('Stream closed, reconnecting in 3 seconds ' , $ error ->getMessage ());
378+ }
379+
380+ public function testCloseResponseStreamWillNotStartRetryTimerWhenEventSourceIsClosedFromErrorHandler ()
381+ {
382+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
383+ $ loop ->expects ($ this ->never ())->method ('addTimer ' );
384+
385+ $ deferred = new Deferred ();
386+ $ browser = $ this ->getMockBuilder ('React\Http\Browser ' )->disableOriginalConstructor ()->getMock ();
387+ $ browser ->expects ($ this ->once ())->method ('withRejectErrorResponse ' )->willReturnSelf ();
388+ $ browser ->expects ($ this ->once ())->method ('requestStreaming ' )->willReturn ($ deferred ->promise ());
389+
390+ $ es = new EventSource ('http://example.com ' , $ loop , $ browser );
391+
392+ $ stream = new ThroughStream ();
393+ $ response = new Response (200 , array ('Content-Type ' => 'text/event-stream ' ), new ReadableBodyStream ($ stream ));
394+ $ deferred ->resolve ($ response );
395+
396+ $ es ->on ('error ' , function ($ e ) use ($ es ) {
397+ $ es ->close ();
398+ });
399+
400+ $ stream ->close ();
401+
402+ $ this ->assertEquals (EventSource::CLOSED , $ es ->readyState );
377403 }
378404
379405 public function testCloseFromOpenEventWillCloseResponseStreamAndCloseEventSource ()
0 commit comments