@@ -87,6 +87,41 @@ public function testEmitsDataAndC0()
8787 $ this ->input ->emit ('data ' , array ("hello world \n" ));
8888 }
8989
90+ public function testEmitsDataInTwoChunksWithC0InBetween ()
91+ {
92+ // first data event is everything before control code
93+ $ first = $ this ->expectCallableOnceWith ('hello ' );
94+ $ this ->parser ->once ('data ' , $ first );
95+
96+ // second data event will fire with remaining buffer
97+ $ second = $ this ->expectCallableOnceWith ('world ' );
98+ $ parser = $ this ->parser ;
99+ $ this ->parser ->once ('data ' , function () use ($ parser , $ second ) {
100+ $ parser ->once ('data ' , $ second );
101+ });
102+
103+ $ this ->input ->emit ('data ' , array ("hello \nworld " ));
104+ }
105+
106+ public function testEmitsDataInTwoChunkWithC0InBetweenWhileAddingDuringDataEvent ()
107+ {
108+ // first data event is everything before control code
109+ $ first = $ this ->expectCallableOnceWith ('hello ' );
110+ $ this ->parser ->once ('data ' , $ first );
111+
112+ // second data event will fire with remaining buffer
113+ // we write to buffer while processing the first event and expect the full buffer
114+ $ second = $ this ->expectCallableOnceWith ('worldagain ' );
115+ $ input = $ this ->input ;
116+ $ parser = $ this ->parser ;
117+ $ this ->parser ->once ('data ' , function () use ($ input , $ parser , $ second ) {
118+ $ parser ->once ('data ' , $ second );
119+ $ input ->emit ('data ' , array ('again ' ));
120+ });
121+
122+ $ this ->input ->emit ('data ' , array ("hello \nworld " ));
123+ }
124+
90125 public function testEmitsC0AndData ()
91126 {
92127 $ this ->parser ->on ('data ' , $ this ->expectCallableOnceWith ("hello world " ));
0 commit comments