22
33namespace React \Tests \Socket ;
44
5- use Clue \React \Block ;
6- use Evenement \EventEmitterInterface ;
75use React \Promise \Promise ;
86use React \Socket \ConnectionInterface ;
97use React \Socket \SecureConnector ;
108use React \Socket \ServerInterface ;
119use React \Socket \SecureServer ;
1210use React \Socket \TcpConnector ;
1311use React \Socket \TcpServer ;
12+ // use function Clue\React\Block\await;
13+ // use function React\Promise\all;
14+ // use function React\Promise\Timer\timeout;
1415
1516class FunctionalSecureServerTest extends TestCase
1617{
@@ -39,7 +40,7 @@ public function testClientCanConnectToServer()
3940 $ promise = $ connector ->connect ($ server ->getAddress ());
4041
4142 /* @var ConnectionInterface $client */
42- $ client = Block \await ($ promise , null , self ::TIMEOUT );
43+ $ client = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
4344
4445 $ this ->assertInstanceOf ('React\Socket\ConnectionInterface ' , $ client );
4546 $ this ->assertEquals ($ server ->getAddress (), $ client ->getRemoteAddress ());
@@ -68,7 +69,7 @@ public function testClientUsesTls13ByDefaultWhenSupportedByOpenSSL()
6869 $ promise = $ connector ->connect ($ server ->getAddress ());
6970
7071 /* @var ConnectionInterface $client */
71- $ client = Block \await ($ promise , null , self ::TIMEOUT );
72+ $ client = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
7273
7374 $ this ->assertInstanceOf ('React\Socket\Connection ' , $ client );
7475 $ this ->assertTrue (isset ($ client ->stream ));
@@ -107,7 +108,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByClien
107108 $ promise = $ connector ->connect ($ server ->getAddress ());
108109
109110 /* @var ConnectionInterface $client */
110- $ client = Block \await ($ promise , null , self ::TIMEOUT );
111+ $ client = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
111112
112113 $ this ->assertInstanceOf ('React\Socket\Connection ' , $ client );
113114 $ this ->assertTrue (isset ($ client ->stream ));
@@ -138,7 +139,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByServe
138139 $ promise = $ connector ->connect ($ server ->getAddress ());
139140
140141 /* @var ConnectionInterface $client */
141- $ client = Block \await ($ promise , null , self ::TIMEOUT );
142+ $ client = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
142143
143144 $ this ->assertInstanceOf ('React\Socket\Connection ' , $ client );
144145 $ this ->assertTrue (isset ($ client ->stream ));
@@ -170,7 +171,7 @@ public function testClientUsesTls10WhenCryptoMethodIsExplicitlyConfiguredByClien
170171
171172 /* @var ConnectionInterface $client */
172173 try {
173- $ client = Block \await ($ promise , null , self ::TIMEOUT );
174+ $ client = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
174175 } catch (\RuntimeException $ e ) {
175176 // legacy TLS 1.0 would be considered insecure by today's standards, so skip test if connection fails
176177 // OpenSSL error messages are version/platform specific
@@ -212,7 +213,7 @@ public function testServerEmitsConnectionForClientConnection()
212213
213214 // await both client and server side end of connection
214215 /* @var ConnectionInterface[] $both */
215- $ both = Block \awaitAll ( array ($ peer , $ client ), null , self ::TIMEOUT );
216+ $ both = \ Clue \ React \ Block \await ( \ React \ Promise \ Timer \timeout ( \ React \ Promise \all ( array ($ peer , $ client )), self ::TIMEOUT ) );
216217
217218 // both ends of the connection are represented by different instances of ConnectionInterface
218219 $ this ->assertCount (2 , $ both );
@@ -252,7 +253,7 @@ public function testClientEmitsDataEventOnceForDataWrittenFromServer()
252253 }, $ reject );
253254 });
254255
255- $ data = Block \await ($ promise , null , self ::TIMEOUT );
256+ $ data = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
256257
257258 $ this ->assertEquals ('foo ' , $ data );
258259
@@ -293,7 +294,7 @@ public function testWritesDataInMultipleChunksToConnection()
293294 }, $ reject );
294295 });
295296
296- $ received = Block \await ($ promise , null , self ::TIMEOUT );
297+ $ received = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
297298
298299 $ this ->assertEquals (400000 , $ received );
299300
@@ -334,7 +335,7 @@ public function testWritesMoreDataInMultipleChunksToConnection()
334335 }, $ reject );
335336 });
336337
337- $ received = Block \await ($ promise , null , self ::TIMEOUT );
338+ $ received = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
338339
339340 $ this ->assertEquals (2000000 , $ received );
340341
@@ -367,7 +368,7 @@ public function testEmitsDataFromConnection()
367368 $ connection ->write ('foo ' );
368369 });
369370
370- $ data = Block \await ($ promise , null , self ::TIMEOUT );
371+ $ data = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
371372
372373 $ this ->assertEquals ('foo ' , $ data );
373374
@@ -407,7 +408,7 @@ public function testEmitsDataInMultipleChunksFromConnection()
407408 $ connection ->write (str_repeat ('* ' , 400000 ));
408409 });
409410
410- $ received = Block \await ($ promise , null , self ::TIMEOUT );
411+ $ received = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
411412
412413 $ this ->assertEquals (400000 , $ received );
413414
@@ -449,7 +450,7 @@ public function testPipesDataBackInMultipleChunksFromConnection()
449450 }, $ reject );
450451 });
451452
452- $ received = Block \await ($ promise , null , self ::TIMEOUT );
453+ $ received = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
453454
454455 $ this ->assertEquals (400000 , $ received );
455456
@@ -479,7 +480,7 @@ public function testEmitsConnectionForNewTlsv11Connection()
479480 ));
480481 $ promise = $ connector ->connect ($ server ->getAddress ());
481482
482- Block \await ($ promise , null , self ::TIMEOUT );
483+ \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
483484
484485 $ server ->close ();
485486 $ promise ->then (function (ConnectionInterface $ connection ) {
@@ -510,7 +511,7 @@ public function testEmitsErrorForClientWithTlsVersionMismatch()
510511 $ this ->setExpectedException ('RuntimeException ' , 'handshake ' );
511512
512513 try {
513- Block \await ($ promise , null , self ::TIMEOUT );
514+ \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
514515 } catch (\Exception $ e ) {
515516 $ server ->close ();
516517
@@ -536,7 +537,7 @@ public function testServerEmitsConnectionForNewConnectionWithEncryptedCertificat
536537 ));
537538 $ connector ->connect ($ server ->getAddress ());
538539
539- $ connection = Block \await ($ peer , null , self ::TIMEOUT );
540+ $ connection = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ peer , self ::TIMEOUT ) );
540541
541542 $ this ->assertInstanceOf ('React\Socket\ConnectionInterface ' , $ connection );
542543
@@ -559,7 +560,7 @@ public function testClientRejectsWithErrorForServerWithInvalidCertificate()
559560 $ this ->setExpectedException ('RuntimeException ' , 'handshake ' );
560561
561562 try {
562- Block \await ($ promise , null , self ::TIMEOUT );
563+ \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
563564 } catch (\Exception $ e ) {
564565 $ server ->close ();
565566
@@ -589,7 +590,7 @@ public function testServerEmitsErrorForClientWithInvalidCertificate()
589590 $ this ->setExpectedException ('RuntimeException ' , 'handshake ' );
590591
591592 try {
592- Block \await ($ peer , null , self ::TIMEOUT );
593+ \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ peer , self ::TIMEOUT ) );
593594 } catch (\Exception $ e ) {
594595 $ server ->close ();
595596
@@ -618,7 +619,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase
618619 $ this ->setExpectedException ('RuntimeException ' , 'handshake ' );
619620
620621 try {
621- Block \await ($ promise , null , self ::TIMEOUT );
622+ \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
622623 } catch (\Exception $ e ) {
623624 $ server ->close ();
624625
@@ -648,7 +649,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassph
648649 $ this ->setExpectedException ('RuntimeException ' , 'handshake ' );
649650
650651 try {
651- Block \await ($ promise , null , self ::TIMEOUT );
652+ \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
652653 } catch (\Exception $ e ) {
653654 $ server ->close ();
654655
@@ -671,7 +672,7 @@ public function testEmitsErrorForConnectionWithPeerVerification()
671672 $ promise = $ connector ->connect ($ server ->getAddress ());
672673 $ promise ->then (null , $ this ->expectCallableOnce ());
673674
674- Block \await ($ errorEvent , null , self ::TIMEOUT );
675+ \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ errorEvent , self ::TIMEOUT ) );
675676
676677 $ server ->close ();
677678 }
@@ -696,7 +697,7 @@ public function testEmitsErrorIfConnectionIsCancelled()
696697 $ promise ->cancel ();
697698 $ promise ->then (null , $ this ->expectCallableOnce ());
698699
699- Block \await ($ errorEvent , null , self ::TIMEOUT );
700+ \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ errorEvent , self ::TIMEOUT ) );
700701
701702 $ server ->close ();
702703 }
@@ -717,7 +718,7 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake()
717718 $ stream ->close ();
718719 });
719720
720- $ error = Block \await ($ errorEvent , null , self ::TIMEOUT );
721+ $ error = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ errorEvent , self ::TIMEOUT ) );
721722
722723 // Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET)
723724 $ this ->assertInstanceOf ('RuntimeException ' , $ error );
@@ -745,7 +746,7 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake()
745746 $ stream ->end ("\x1e" );
746747 });
747748
748- $ error = Block \await ($ errorEvent , null , self ::TIMEOUT );
749+ $ error = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ errorEvent , self ::TIMEOUT ) );
749750
750751 // Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET)
751752 $ this ->assertInstanceOf ('RuntimeException ' , $ error );
@@ -769,7 +770,7 @@ public function testEmitsNothingIfPlaintextConnectionIsIdle()
769770 $ connector = new TcpConnector ();
770771 $ promise = $ connector ->connect (str_replace ('tls:// ' , '' , $ server ->getAddress ()));
771772
772- $ connection = Block \await ($ promise , null , self ::TIMEOUT );
773+ $ connection = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ promise , self ::TIMEOUT ) );
773774 $ this ->assertInstanceOf ('React\Socket\ConnectionInterface ' , $ connection );
774775
775776 $ server ->close ();
@@ -794,7 +795,7 @@ public function testEmitsErrorIfConnectionIsHttpInsteadOfSecureHandshake()
794795 $ stream ->write ("GET / HTTP/1.0 \r\n\r\n" );
795796 });
796797
797- $ error = Block \await ($ errorEvent , null , self ::TIMEOUT );
798+ $ error = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ errorEvent , self ::TIMEOUT ) );
798799
799800 $ this ->assertInstanceOf ('RuntimeException ' , $ error );
800801
@@ -823,7 +824,7 @@ public function testEmitsErrorIfConnectionIsUnknownProtocolInsteadOfSecureHandsh
823824 $ stream ->write ("Hello world! \n" );
824825 });
825826
826- $ error = Block \await ($ errorEvent , null , self ::TIMEOUT );
827+ $ error = \ Clue \ React \ Block \await (\ React \ Promise \ Timer \timeout ( $ errorEvent , self ::TIMEOUT ) );
827828
828829 $ this ->assertInstanceOf ('RuntimeException ' , $ error );
829830
0 commit comments