@@ -114,6 +114,21 @@ public function testConnectFailed(): void
114114 $ this ->assertFalse ($ this ->isPropertyInitialized ($ client , 'esl ' ));
115115 }
116116
117+ public function testDataHandlerOnParsingError (): void
118+ {
119+ $ context = $ this ->prepareClientAndConnectors ();
120+ $ this ->setPropertyValue ($ context ->client , 'authenticated ' , true );
121+ $ dataHandler = $ this ->getMethod ($ context ->client , 'dataHandler ' );
122+
123+ $ this ->setPropertyValue ($ context ->client , 'esl ' , new AsyncConnection (AsyncConnection::INBOUND_CLIENT ));
124+
125+ $ context ->client ->on ('error ' , function (\Throwable $ t ) {
126+ $ this ->assertInstanceOf (ESL \Exception \ESLException::class, $ t );
127+ });
128+
129+ $ dataHandler ->invokeArgs ($ context ->client , ["Content-Type: bogus/no-such-thing \n\n" ]);
130+ }
131+
117132 public function testDataHandlerOnPreAuth (): void
118133 {
119134 $ context = $ this ->prepareClientAndConnectors ();
@@ -253,6 +268,10 @@ public function testDataHandlerOnOutOfSequence(): void
253268
254269 $ response = "Content-Type: api/response \n\n" ;
255270
271+ $ context ->client ->on ('error ' , function (\Throwable $ t ) {
272+ $ this ->assertInstanceOf (ReactESLException::class, $ t );
273+ });
274+
256275 $ context ->esl
257276 ->method ('consume ' )
258277 ->with ($ response , [])
@@ -262,7 +281,6 @@ public function testDataHandlerOnOutOfSequence(): void
262281 return ESL \Connection::SUCCESS ;
263282 }));
264283
265- $ this ->expectException (ReactESLException::class);
266284 $ dataHandler ->invokeArgs ($ context ->client , [$ response ]);
267285 }
268286
@@ -334,17 +352,6 @@ public function testPreAuthHandlerOnCommandReplySuccess(): void
334352 $ this ->assertTrue ($ this ->getPropertyValue ($ context ->client , 'authenticated ' ));
335353 }
336354
337- public function testPreAuthHandlerOnCommandReplyFailure (): void
338- {
339- $ context = $ this ->prepareClientAndConnectors ();
340- $ preAuthHandler = $ this ->getMethod ($ context ->client , 'preAuthHandler ' );
341-
342- $ this ->expectException (ReactESLException::class);
343- $ preAuthHandler ->invokeArgs ($ context ->client , [
344- (new ESL \Response \CommandReply )->setHeader (ESL \AbstractHeader::REPLY_TEXT , '-ERR invalid ' )
345- ]);
346- }
347-
348355 public function testPreAuthHandlerOnDisconnectNotice (): void
349356 {
350357 $ context = $ this ->prepareClientAndConnectors ();
@@ -377,8 +384,22 @@ public function testPreAuthHandlerOnUnexpectedResponse(): void
377384 $ context = $ this ->prepareClientAndConnectors ();
378385 $ preAuthHandler = $ this ->getMethod ($ context ->client , 'preAuthHandler ' );
379386
380- $ this ->expectException (ReactESLException::class);
381387 $ preAuthHandler ->invokeArgs ($ context ->client , [new ESL \Response \ApiResponse ]);
388+ $ context ->promise
389+ ->then (function () {
390+ $ this ->fail ('Should never resolve ' );
391+ })
392+ ->otherwise (function (\Throwable $ t ) {
393+ $ this ->assertInstanceOf (ReactESLException::class, $ t );
394+ });
395+ }
396+
397+ public function testClose (): void
398+ {
399+ $ context = $ this ->prepareClientAndConnectors ();
400+
401+ $ context ->stream ->expects ($ this ->once ())->method ('close ' );
402+ $ context ->client ->close ();
382403 }
383404
384405 private function prepareClientAndConnectors (): stdClass
@@ -408,12 +429,4 @@ private function prepareClientAndConnectors(): stdClass
408429
409430 return $ ret ;
410431 }
411-
412- public function testClose (): void
413- {
414- $ context = $ this ->prepareClientAndConnectors ();
415-
416- $ context ->stream ->expects ($ this ->once ())->method ('close ' );
417- $ context ->client ->close ();
418- }
419432}
0 commit comments