@@ -813,7 +813,7 @@ public function testServerParamsWillBeReusedForMultipleRequestsFromSameConnectio
813813 $ clock = $ this ->getMockBuilder ('React\Http\Io\Clock ' )->disableOriginalConstructor ()->getMock ();
814814 $ clock ->expects ($ this ->exactly (2 ))->method ('now ' )->willReturn (1652972091.3958 );
815815
816- $ parser = new RequestHeaderParser ($ clock );
816+ $ parser = $ this -> createRequestHeaderParser ($ clock );
817817
818818 $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('getLocalAddress ' , 'getRemoteAddress ' ))->getMock ();
819819 $ connection ->expects ($ this ->once ())->method ('getLocalAddress ' )->willReturn ('tcp://127.1.1.1:8000 ' );
@@ -848,7 +848,7 @@ public function testServerParamsWillBeRememberedUntilConnectionIsClosed()
848848 {
849849 $ clock = $ this ->getMockBuilder ('React\Http\Io\Clock ' )->disableOriginalConstructor ()->getMock ();
850850
851- $ parser = new RequestHeaderParser ($ clock );
851+ $ parser = $ this -> createRequestHeaderParser ($ clock );
852852
853853 $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('getLocalAddress ' , 'getRemoteAddress ' ))->getMock ();
854854
@@ -887,6 +887,49 @@ public function testQueryParametersWillBeSet()
887887 $ this ->assertEquals ('this ' , $ queryParams ['test ' ]);
888888 }
889889
890+ public function testIdleConnectionWillBeClosedAfterConfiguredTimeout ()
891+ {
892+ $ callback = null ;
893+ $ caughtError = null ;
894+ $ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
895+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
896+ $ loop ->expects ($ this ->exactly (2 ))->method ('addTimer ' )->with (0.1 , $ this ->callback (function ($ cb ) use (&$ tick , &$ callback ) {
897+ $ callback = $ cb ;
898+ return true ;
899+ }))->willReturn ($ timer );
900+ $ loop ->expects ($ this ->any ())->method ('cancelTimer ' )->with ($ timer );
901+
902+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('close ' ))->getMock ();
903+ $ connection ->expects ($ this ->once ())->method ('close ' );
904+
905+ $ parser = $ this ->createRequestHeaderParser (new Clock ($ loop ), 0.1 , $ loop );
906+ $ parser ->on ('error ' , function ($ error ) use (&$ caughtError ) {
907+ $ caughtError = $ error ;
908+ });
909+
910+ $ parser ->handle ($ connection );
911+
912+ $ connection ->emit ('data ' , array ("GET /foo.php?hello=world&test=this HTTP/ " ));
913+
914+ self ::assertTrue (is_callable ($ callback ));
915+ $ callback ();
916+
917+ self ::assertInstanceOf ('\RuntimeException ' , $ caughtError );
918+ self ::assertSame ('Request timed out ' , $ caughtError ->getMessage ());
919+ }
920+
921+ public function testIdleConnectionWillNotBeClosedAfterConfiguredTimeoutOnFullRequest ()
922+ {
923+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('close ' ))->getMock ();
924+ $ connection ->expects ($ this ->never ())->method ('close ' );
925+
926+ $ parser = $ this ->createRequestHeaderParser (new Clock ($ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ()), 0.1 );
927+
928+ $ parser ->handle ($ connection );
929+
930+ $ connection ->emit ('data ' , array ($ this ->createGetRequest ()));
931+ }
932+
890933 private function createGetRequest ()
891934 {
892935 $ data = "GET / HTTP/1.1 \r\n" ;
0 commit comments