File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -656,6 +656,35 @@ public function testSplitMessagesWithWindowsEndOfLineSequence()
656656 }
657657 }
658658
659+ public function testSplitMessagesWithBufferedWindowsEndOfLineSequence ()
660+ {
661+ $ deferred = new Deferred ();
662+ $ browser = $ this ->getMockBuilder ('React\Http\Browser ' )->disableOriginalConstructor ()->getMock ();
663+ $ browser ->expects ($ this ->once ())->method ('withRejectErrorResponse ' )->willReturnSelf ();
664+ $ browser ->expects ($ this ->once ())->method ('requestStreaming ' )->willReturn ($ deferred ->promise ());
665+
666+ $ es = new EventSource ('http://example.com ' , $ browser );
667+
668+ $ stream = new ThroughStream ();
669+ $ response = new Response (200 , array ('Content-Type ' => 'text/event-stream ' ), new ReadableBodyStream ($ stream ));
670+ $ deferred ->resolve ($ response );
671+
672+ $ messages = [];
673+ $ es ->on ('message ' , function ($ m ) use (&$ messages ) {
674+ $ messages [] = $ m ;
675+ });
676+
677+ $ stream ->write ("data:hello \r\n\r" );
678+ $ stream ->write ("\ndata:hi \r\n\r\n" );
679+
680+ $ expected = ['hello ' , 'hi ' ];
681+ $ this ->assertCount (count ($ expected ), $ messages );
682+ foreach ($ messages as $ i => $ message ) {
683+ $ this ->assertInstanceOf ('Clue\React\EventSource\MessageEvent ' , $ message );
684+ $ this ->assertEquals ($ expected [$ i ], $ message ->data );
685+ }
686+ }
687+
659688 public function testSplitMessagesWithMixedEndOfLine ()
660689 {
661690 $ deferred = new Deferred ();
You can’t perform that action at this time.
0 commit comments