@@ -58,6 +58,7 @@ class SocketPostGlobalState
5858 public static array $ fgetsResponses = [];
5959 public static int $ feofCount = 0 ;
6060 public static bool $ fcloseCalled = false ;
61+ public static bool $ streamSetTimeoutSuccess = true ;
6162}
6263
6364/**
@@ -100,6 +101,14 @@ function feof(\stdClass $handle): bool
100101 return empty (SocketPostGlobalState::$ fgetsResponses );
101102}
102103
104+ /**
105+ * Mock stream_set_timeout in the ReCaptcha\RequestMethod namespace.
106+ */
107+ function stream_set_timeout (\stdClass $ handle , int $ seconds , int $ microseconds = 0 ): bool
108+ {
109+ return SocketPostGlobalState::$ streamSetTimeoutSuccess ;
110+ }
111+
103112/**
104113 * Mock fclose in the ReCaptcha\RequestMethod namespace.
105114 */
@@ -126,6 +135,7 @@ protected function setUp(): void
126135 SocketPostGlobalState::$ fwriteData = '' ;
127136 SocketPostGlobalState::$ fgetsResponses = [];
128137 SocketPostGlobalState::$ fcloseCalled = false ;
138+ SocketPostGlobalState::$ streamSetTimeoutSuccess = true ;
129139 }
130140
131141 public function testSubmit (): void
@@ -147,6 +157,15 @@ public function testSubmit(): void
147157 $ this ->assertTrue (SocketPostGlobalState::$ fcloseCalled );
148158 }
149159
160+ public function testStreamTimeoutFailureReturnsError (): void
161+ {
162+ SocketPostGlobalState::$ streamSetTimeoutSuccess = false ;
163+ $ sp = new SocketPost ();
164+ $ response = $ sp ->submit (new RequestParameters ('secret ' , 'response ' ));
165+
166+ $ this ->assertEquals ('{"success": false, "error-codes": [" ' .ReCaptcha::E_CONNECTION_FAILED .'"]} ' , $ response );
167+ }
168+
150169 public function testUrlFailureReturnsError (): void
151170 {
152171 $ sp = new SocketPost ('invalid_url ' );
0 commit comments