22
33namespace Clue \Tests \React \Ami ;
44
5- use Clue \React \Ami \Factory ;
6- use Clue \React \Ami \Client ;
75use Clue \React \Ami \ActionSender ;
8- use Clue \React \Block ;
9- use React \Promise \PromiseInterface ;
6+ use Clue \React \Ami \Client ;
7+ use Clue \React \Ami \Factory ;
8+ use Clue \React \Ami \Protocol \Response ;
9+ use React \EventLoop \Loop ;
1010
1111class FunctionalTest extends TestCase
1212{
@@ -19,7 +19,6 @@ class FunctionalTest extends TestCase
1919 public static function setUpLoopBeforeClass ()
2020 {
2121 self ::$ address = getenv ('LOGIN ' );
22- self ::$ loop = \React \EventLoop \Factory::create ();
2322 }
2423
2524 /**
@@ -34,10 +33,16 @@ public function setUpSkipTest()
3433
3534 public function testConnection ()
3635 {
37- $ factory = new Factory (self ::$ loop );
36+ $ factory = new Factory ();
37+
38+ $ client = \React \Async \await ($ factory ->createClient (self ::$ address ));
39+ assert ($ client instanceof Client);
3840
39- $ client = $ this ->waitFor ($ factory ->createClient (self ::$ address ));
40- /* @var $client Client */
41+ // let loop tick for reactphp/async v4 to clean up any remaining references
42+ // @link https://github.com/reactphp/async/pull/65 reported upstream // TODO remove me once merged
43+ if (function_exists ('React\Async\async ' )) {
44+ \React \Async \delay (0.0 );
45+ }
4146
4247 $ this ->assertFalse ($ client ->isBusy ());
4348
@@ -52,7 +57,7 @@ public function testPing(Client $client)
5257 {
5358 $ sender = new ActionSender ($ client );
5459
55- $ pong = $ this -> waitFor ($ sender ->ping ());
60+ $ pong = \ React \ Async \await ($ sender ->ping ());
5661
5762 $ this ->assertInstanceOf ('Clue\React\Ami\Protocol\Response ' , $ pong );
5863 }
@@ -64,7 +69,7 @@ public function testPing(Client $client)
6469 public function testInvalidCommandGetsRejected (Client $ client )
6570 {
6671 $ this ->setExpectedException ('Exception ' );
67- $ this -> waitFor ($ client ->request ($ client ->createAction ('Invalid ' )));
72+ \ React \ Async \await ($ client ->request ($ client ->createAction ('Invalid ' )));
6873 }
6974
7075 /**
@@ -75,15 +80,20 @@ public function testActionSenderLogoffDisconnects(Client $client)
7580 {
7681 $ sender = new ActionSender ($ client );
7782
78- $ ret = $ this ->waitFor ($ sender ->logoff ());
83+ $ ret = \React \Async \await ($ sender ->logoff ());
84+ assert ($ ret instanceof Response);
7985
80- $ this ->assertInstanceOf ('Clue\React\Ami\Protocol\Response ' , $ ret );
86+ // let loop tick for reactphp/async v4 to clean up any remaining references
87+ // @link https://github.com/reactphp/async/pull/65 reported upstream // TODO remove me once merged
88+ if (function_exists ('React\Async\async ' )) {
89+ \React \Async \delay (0.0 );
90+ }
8191
8292 $ this ->assertFalse ($ client ->isBusy ());
8393
8494 //$client->on('close', $this->expectCallableOnce());
8595
86- self :: $ loop -> run ();
96+ Loop:: run ();
8797
8898 return $ client ;
8999 }
@@ -95,11 +105,6 @@ public function testActionSenderLogoffDisconnects(Client $client)
95105 public function testSendRejectedAfterClose (Client $ client )
96106 {
97107 $ this ->setExpectedException ('Exception ' );
98- $ this ->waitFor ($ client ->request ($ client ->createAction ('Ping ' )));
99- }
100-
101- private function waitFor (PromiseInterface $ promise )
102- {
103- return Block \await ($ promise , self ::$ loop , 5.0 );
108+ \React \Async \await ($ client ->request ($ client ->createAction ('Ping ' )));
104109 }
105110}
0 commit comments