File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -217,8 +217,10 @@ public function close()
217217 $ this ->connecting ->then (function (ConnectionInterface $ connection ) {
218218 $ connection ->close ();
219219 });
220- $ this ->connecting ->cancel ();
221- $ this ->connecting = null ;
220+ if ($ this ->connecting !== null ) {
221+ $ this ->connecting ->cancel ();
222+ $ this ->connecting = null ;
223+ }
222224 }
223225
224226 if ($ this ->idleTimer !== null ) {
Original file line number Diff line number Diff line change @@ -701,6 +701,25 @@ public function testCloseAfterPingWillCancelTimerWhenPingFromUnderlyingConnectio
701701 $ connection ->close ();
702702 }
703703
704+ public function testCloseAfterPingHasResolvedWillCloseUnderlyingConnectionWithoutTryingToCancelConnection ()
705+ {
706+ $ base = $ this ->getMockBuilder ('React\MySQL\Io\LazyConnection ' )->setMethods (array ('ping ' , 'close ' ))->disableOriginalConstructor ()->getMock ();
707+ $ base ->expects ($ this ->once ())->method ('ping ' )->willReturn (\React \Promise \resolve ());
708+ $ base ->expects ($ this ->once ())->method ('close ' )->willReturnCallback (function () use ($ base ) {
709+ $ base ->emit ('close ' );
710+ });
711+
712+ $ factory = $ this ->getMockBuilder ('React\MySQL\Factory ' )->disableOriginalConstructor ()->getMock ();
713+ $ factory ->expects ($ this ->once ())->method ('createConnection ' )->willReturn (\React \Promise \resolve ($ base ));
714+
715+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
716+
717+ $ connection = new LazyConnection ($ factory , '' , $ loop );
718+
719+ $ connection ->ping ();
720+ $ connection ->close ();
721+ }
722+
704723 public function testCloseAfterQuitAfterPingWillCloseUnderlyingConnectionWhenQuitIsStillPending ()
705724 {
706725 $ base = $ this ->getMockBuilder ('React\MySQL\ConnectionInterface ' )->getMock ();
You can’t perform that action at this time.
0 commit comments