File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -302,6 +302,10 @@ protected function configure(array $options): void
302302 */
303303 public function waitForData (float $ maxSeconds ): ?bool
304304 {
305+ if (!$ this ->isConnected ()) {
306+ return null ;
307+ }
308+
305309 return $ this ->socket ->waitForData ($ maxSeconds );
306310 }
307311}
Original file line number Diff line number Diff line change @@ -233,6 +233,10 @@ public function send(string $data): ?int
233233 */
234234 public function waitForData (float $ maxSeconds ): ?bool
235235 {
236+ if (null === $ this ->socket ) {
237+ return null ;
238+ }
239+
236240 $ read = [$ this ->socket ];
237241 $ write = null ;
238242 $ except = null ;
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ public function testSend(): void
8989 $ instance ->addRequestHeader ('X-Test ' , 'Custom Request Header ' );
9090
9191 self ::assertNull ($ instance ->receive (), 'Receive before connect ' );
92+ self ::assertNull ($ instance ->waitForData (0 ), 'Wait for data before connect ' );
9293
9394 $ success = $ instance ->connect ();
9495 self ::assertTrue ($ success , 'Client can connect to test server ' );
@@ -123,6 +124,7 @@ public function testSend(): void
123124 $ instance ->disconnect ();
124125
125126 self ::assertFalse ($ instance ->isConnected ());
127+ self ::assertNull ($ instance ->waitForData (0 ), 'Wait for data after disconnect ' );
126128 } finally {
127129 $ helper ->tearDown ();
128130 }
Original file line number Diff line number Diff line change @@ -110,6 +110,13 @@ public function testSendTooEarly(): void
110110 $ instance ->send ('foo ' );
111111 }
112112
113+ public function testWaitForDataTooEarly (): void
114+ {
115+ $ instance = self ::getInstance ('ws://localhost:8000 ' );
116+
117+ self ::assertNull ($ instance ->waitForData (0 ));
118+ }
119+
113120 /**
114121 * Test the connect, send, receive method.
115122 */
You can’t perform that action at this time.
0 commit comments