From fe9df486aa38602cf50d86152535333eb6665b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Thu, 4 Aug 2022 11:58:52 +0200 Subject: [PATCH] Update to use new reactphp/async package instead of clue/reactphp-block --- composer.json | 2 +- tests/FdServerTest.php | 4 +-- tests/FunctionalConnectorTest.php | 18 +++++----- tests/FunctionalSecureServerTest.php | 54 ++++++++++++++-------------- tests/FunctionalTcpServerTest.php | 39 ++++++++++++-------- tests/IntegrationTest.php | 46 ++++++++++++------------ tests/LimitingServerTest.php | 8 ++--- tests/SecureIntegrationTest.php | 24 ++++++------- tests/ServerTest.php | 16 ++++----- tests/SocketServerTest.php | 16 ++++----- tests/TcpConnectorTest.php | 20 +++++------ tests/TcpServerTest.php | 7 ++-- tests/TestCase.php | 8 ++--- tests/TimeoutConnectorTest.php | 9 +++-- tests/UnixServerTest.php | 4 +-- 15 files changed, 145 insertions(+), 130 deletions(-) diff --git a/composer.json b/composer.json index ec50942e..ede57084 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,8 @@ "react/stream": "^1.2" }, "require-dev": { - "clue/block-react": "^1.5", "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35", + "react/async": "^4 || ^3 || ^2", "react/promise-stream": "^1.2" }, "autoload": { diff --git a/tests/FdServerTest.php b/tests/FdServerTest.php index 7d1fc547..28499695 100644 --- a/tests/FdServerTest.php +++ b/tests/FdServerTest.php @@ -5,7 +5,7 @@ use React\Promise\Promise; use React\Socket\ConnectionInterface; use React\Socket\FdServer; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Timer\timeout; class FdServerTest extends TestCase @@ -323,7 +323,7 @@ public function testServerEmitsConnectionEventForNewConnection() $server->on('connection', $resolve); }); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, 1.0)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($promise, 1.0)); /** * @var ConnectionInterface $connection diff --git a/tests/FunctionalConnectorTest.php b/tests/FunctionalConnectorTest.php index 707bf575..2012d50e 100644 --- a/tests/FunctionalConnectorTest.php +++ b/tests/FunctionalConnectorTest.php @@ -8,7 +8,7 @@ use React\Socket\Connector; use React\Socket\ConnectorInterface; use React\Socket\TcpServer; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Stream\buffer; // use function React\Promise\Timer\timeout; @@ -26,7 +26,7 @@ public function connectionToTcpServerShouldSucceedWithLocalhost() $connector = new Connector(array()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('localhost:9998'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('localhost:9998'), self::TIMEOUT)); $server->close(); @@ -65,11 +65,11 @@ public function testConnectTwiceWithoutHappyEyeBallsOnlySendsSingleDnsQueryDueTo fclose($client); }); - $connection = \Clue\React\Block\await($connector->connect('example.com:80')); + $connection = \React\Async\await($connector->connect('example.com:80')); $connection->close(); $this->assertEquals(1, $received); - $connection = \Clue\React\Block\await($connector->connect('example.com:80')); + $connection = \React\Async\await($connector->connect('example.com:80')); $connection->close(); $this->assertEquals(1, $received); @@ -87,7 +87,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP() $connector = new Connector(array('happy_eyeballs' => true)); - $ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('dual.tlund.se', $connector), self::TIMEOUT)); + $ip = \React\Async\await(\React\Promise\Timer\timeout($this->request('dual.tlund.se', $connector), self::TIMEOUT)); $this->assertNotFalse(inet_pton($ip)); } @@ -101,7 +101,7 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP() $connector = new Connector(array('happy_eyeballs' => true)); try { - $ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('ipv4.tlund.se', $connector), self::TIMEOUT)); + $ip = \React\Async\await(\React\Promise\Timer\timeout($this->request('ipv4.tlund.se', $connector), self::TIMEOUT)); } catch (\Exception $e) { $this->checkIpv4(); throw $e; @@ -120,7 +120,7 @@ public function connectionToRemoteTCP6ServerShouldResultInOurIP() $connector = new Connector(array('happy_eyeballs' => true)); try { - $ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('ipv6.tlund.se', $connector), self::TIMEOUT)); + $ip = \React\Async\await(\React\Promise\Timer\timeout($this->request('ipv6.tlund.se', $connector), self::TIMEOUT)); } catch (\Exception $e) { $this->checkIpv6(); throw $e; @@ -153,11 +153,11 @@ public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpCo }); }); - \Clue\React\Block\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT)); $server->close(); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->fail(); } catch (\Exception $e) { $this->assertInstanceOf('RuntimeException', $e); diff --git a/tests/FunctionalSecureServerTest.php b/tests/FunctionalSecureServerTest.php index 890c48f9..4d616ae7 100644 --- a/tests/FunctionalSecureServerTest.php +++ b/tests/FunctionalSecureServerTest.php @@ -9,7 +9,7 @@ use React\Socket\SecureServer; use React\Socket\TcpConnector; use React\Socket\TcpServer; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\all; // use function React\Promise\Timer\timeout; @@ -40,7 +40,7 @@ public function testClientCanConnectToServer() $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $client); $this->assertEquals($server->getAddress(), $client->getRemoteAddress()); @@ -69,7 +69,7 @@ public function testClientUsesTls13ByDefaultWhenSupportedByOpenSSL() $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\Connection', $client); $this->assertTrue(isset($client->stream)); @@ -108,7 +108,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByClien $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\Connection', $client); $this->assertTrue(isset($client->stream)); @@ -139,7 +139,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByServe $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\Connection', $client); $this->assertTrue(isset($client->stream)); @@ -171,7 +171,7 @@ public function testClientUsesTls10WhenCryptoMethodIsExplicitlyConfiguredByClien /* @var ConnectionInterface $client */ try { - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\RuntimeException $e) { // legacy TLS 1.0 would be considered insecure by today's standards, so skip test if connection fails // OpenSSL error messages are version/platform specific @@ -213,7 +213,7 @@ public function testServerEmitsConnectionForClientConnection() // await both client and server side end of connection /* @var ConnectionInterface[] $both */ - $both = \Clue\React\Block\await(\React\Promise\Timer\timeout(\React\Promise\all(array($peer, $client)), self::TIMEOUT)); + $both = \React\Async\await(\React\Promise\Timer\timeout(\React\Promise\all(array($peer, $client)), self::TIMEOUT)); // both ends of the connection are represented by different instances of ConnectionInterface $this->assertCount(2, $both); @@ -253,7 +253,7 @@ public function testClientEmitsDataEventOnceForDataWrittenFromServer() }, $reject); }); - $data = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $data = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals('foo', $data); @@ -294,7 +294,7 @@ public function testWritesDataInMultipleChunksToConnection() }, $reject); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(400000, $received); @@ -335,7 +335,7 @@ public function testWritesMoreDataInMultipleChunksToConnection() }, $reject); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(2000000, $received); @@ -368,7 +368,7 @@ public function testEmitsDataFromConnection() $connection->write('foo'); }); - $data = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $data = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals('foo', $data); @@ -408,7 +408,7 @@ public function testEmitsDataInMultipleChunksFromConnection() $connection->write(str_repeat('*', 400000)); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(400000, $received); @@ -450,7 +450,7 @@ public function testPipesDataBackInMultipleChunksFromConnection() }, $reject); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(400000, $received); @@ -480,7 +480,7 @@ public function testEmitsConnectionForNewTlsv11Connection() )); $promise = $connector->connect($server->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -511,7 +511,7 @@ public function testEmitsErrorForClientWithTlsVersionMismatch() $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -537,7 +537,7 @@ public function testServerEmitsConnectionForNewConnectionWithEncryptedCertificat )); $connector->connect($server->getAddress()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); @@ -560,7 +560,7 @@ public function testClientRejectsWithErrorForServerWithInvalidCertificate() $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -590,7 +590,7 @@ public function testServerEmitsErrorForClientWithInvalidCertificate() $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -619,7 +619,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -649,7 +649,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassph $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -672,7 +672,7 @@ public function testEmitsErrorForConnectionWithPeerVerification() $promise = $connector->connect($server->getAddress()); $promise->then(null, $this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $server->close(); } @@ -697,7 +697,7 @@ public function testEmitsErrorIfConnectionIsCancelled() $promise->cancel(); $promise->then(null, $this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $server->close(); } @@ -718,7 +718,7 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake() $stream->close(); }); - $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + $error = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); // Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET) $this->assertInstanceOf('RuntimeException', $error); @@ -746,7 +746,7 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake() $stream->end("\x1e"); }); - $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + $error = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); // Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET) $this->assertInstanceOf('RuntimeException', $error); @@ -770,7 +770,7 @@ public function testEmitsNothingIfPlaintextConnectionIsIdle() $connector = new TcpConnector(); $promise = $connector->connect(str_replace('tls://', '', $server->getAddress())); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); $server->close(); @@ -795,7 +795,7 @@ public function testEmitsErrorIfConnectionIsHttpInsteadOfSecureHandshake() $stream->write("GET / HTTP/1.0\r\n\r\n"); }); - $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + $error = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $this->assertInstanceOf('RuntimeException', $error); @@ -824,7 +824,7 @@ public function testEmitsErrorIfConnectionIsUnknownProtocolInsteadOfSecureHandsh $stream->write("Hello world!\n"); }); - $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + $error = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $this->assertInstanceOf('RuntimeException', $error); diff --git a/tests/FunctionalTcpServerTest.php b/tests/FunctionalTcpServerTest.php index 6cb6219a..6918b237 100644 --- a/tests/FunctionalTcpServerTest.php +++ b/tests/FunctionalTcpServerTest.php @@ -6,7 +6,7 @@ use React\Socket\ConnectionInterface; use React\Socket\TcpConnector; use React\Socket\TcpServer; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Timer\timeout; class FunctionalTcpServerTest extends TestCase @@ -27,7 +27,8 @@ public function testEmitsConnectionForNewConnection() $promise->then($this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $server->close(); @@ -47,7 +48,8 @@ public function testEmitsNoConnectionForNewConnectionWhenPaused() $promise->then($this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); } public function testConnectionForNewConnectionWhenResumedAfterPause() @@ -66,7 +68,8 @@ public function testConnectionForNewConnectionWhenResumedAfterPause() $promise->then($this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -88,7 +91,8 @@ public function testEmitsConnectionWithRemoteIp() $promise->then($this->expectCallableOnce()); - $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $peer = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('127.0.0.1:', $peer); @@ -114,7 +118,8 @@ public function testEmitsConnectionWithLocalIp() $promise->then($this->expectCallableOnce()); - $local = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $local = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('127.0.0.1:', $local); $this->assertEquals($server->getAddress(), $local); @@ -143,7 +148,8 @@ public function testEmitsConnectionWithLocalIpDespiteListeningOnAll() $promise->then($this->expectCallableOnce()); - $local = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $local = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('127.0.0.1:', $local); @@ -169,7 +175,7 @@ public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer() $connection->end(); }); - $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $peer = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertContainsString('127.0.0.1:', $peer); @@ -191,7 +197,8 @@ public function testEmitsConnectionWithRemoteNullAddressAfterConnectionIsClosedB $promise->then($this->expectCallableOnce()); - $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $peer = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertNull($peer); @@ -217,7 +224,7 @@ public function testEmitsConnectionEvenIfClientConnectionIsCancelled() $promise->then(null, $this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } @@ -241,7 +248,8 @@ public function testEmitsConnectionForNewIpv6Connection() $promise->then($this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -268,7 +276,8 @@ public function testEmitsConnectionWithRemoteIpv6() $promise->then($this->expectCallableOnce()); - $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $peer = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('[::1]:', $peer); @@ -297,7 +306,8 @@ public function testEmitsConnectionWithLocalIpv6() $promise->then($this->expectCallableOnce()); - $local = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $local = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('[::1]:', $local); $this->assertEquals($server->getAddress(), $local); @@ -362,7 +372,8 @@ public function testEmitsConnectionWithInheritedContextOptions() $promise->then($this->expectCallableOnce()); - $all = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $all = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertEquals(array('socket' => array('backlog' => 4)), $all); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 04e88bee..6fba9d97 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -7,7 +7,7 @@ use React\Socket\DnsConnector; use React\Socket\SecureConnector; use React\Socket\TcpConnector; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Timer\timeout; // use function React\Promise\Timer\sleep; @@ -21,7 +21,7 @@ public function gettingStuffFromGoogleShouldWork() { $connector = new Connector(array()); - $conn = \Clue\React\Block\await($connector->connect('google.com:80')); + $conn = \React\Async\await($connector->connect('google.com:80')); $this->assertContainsString(':80', $conn->getRemoteAddress()); $this->assertNotEquals('google.com:80', $conn->getRemoteAddress()); @@ -42,7 +42,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork() $secureConnector = new Connector(array()); - $conn = \Clue\React\Block\await($secureConnector->connect('tls://google.com:443')); + $conn = \React\Async\await($secureConnector->connect('tls://google.com:443')); $conn->write("GET / HTTP/1.0\r\n\r\n"); @@ -68,7 +68,7 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst() $dns ); - $conn = \Clue\React\Block\await($connector->connect('google.com:443')); + $conn = \React\Async\await($connector->connect('google.com:443')); $conn->write("GET / HTTP/1.0\r\n\r\n"); @@ -82,7 +82,7 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork() { $connector = new Connector(array()); - $conn = \Clue\React\Block\await($connector->connect('google.com:443')); + $conn = \React\Async\await($connector->connect('google.com:443')); $this->assertContainsString(':443', $conn->getRemoteAddress()); $this->assertNotEquals('google.com:443', $conn->getRemoteAddress()); @@ -108,7 +108,7 @@ public function testConnectingFailsIfConnectorUsesInvalidDnsResolverAddress() )); $this->setExpectedException('RuntimeException'); - \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); } public function testCancellingPendingConnectionWithoutTimeoutShouldNotCreateAnyGarbageReferences() @@ -165,11 +165,11 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect connection refused error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); + \React\Async\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(2.0)); + \React\Async\await(\React\Promise\Timer\sleep(2.0)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -200,9 +200,9 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a connection timeout error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); + \React\Async\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -232,9 +232,9 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a connection timeout error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); + \React\Async\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -264,11 +264,11 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a DNS error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); + \React\Async\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(2.0)); + \React\Async\await(\React\Promise\Timer\sleep(2.0)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -306,11 +306,11 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a TLS error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.4)); + \React\Async\await(\React\Promise\Timer\sleep(0.4)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(self::TIMEOUT - 0.5)); + \React\Async\await(\React\Promise\Timer\sleep(self::TIMEOUT - 0.5)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -335,7 +335,7 @@ function ($conn) { $conn->close(); } ); - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); unset($promise); $this->assertEquals(0, gc_collect_cycles()); @@ -348,7 +348,7 @@ public function testConnectingFailsIfTimeoutIsTooSmall() )); $this->setExpectedException('RuntimeException'); - \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); } public function testSelfSignedRejectsIfVerificationIsEnabled() @@ -364,7 +364,7 @@ public function testSelfSignedRejectsIfVerificationIsEnabled() )); $this->setExpectedException('RuntimeException'); - \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); } public function testSelfSignedResolvesIfVerificationIsDisabled() @@ -379,7 +379,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled() ) )); - $conn = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); + $conn = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); $conn->close(); // if we reach this, then everything is good diff --git a/tests/LimitingServerTest.php b/tests/LimitingServerTest.php index ce13aed4..70c776cb 100644 --- a/tests/LimitingServerTest.php +++ b/tests/LimitingServerTest.php @@ -6,7 +6,7 @@ use React\Socket\ConnectionInterface; use React\Socket\LimitingServer; use React\Socket\TcpServer; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Timer\timeout; class LimitingServerTest extends TestCase @@ -158,7 +158,7 @@ public function testSocketDisconnectionWillRemoveFromList() }); }); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array(), $server->getConnections()); @@ -179,7 +179,7 @@ public function testPausingServerWillEmitOnlyOneButAcceptTwoConnectionsDueToOper $first = stream_socket_client($server->getAddress()); $second = stream_socket_client($server->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); fclose($first); fclose($second); @@ -209,7 +209,7 @@ public function testPausingServerWillEmitTwoConnectionsFromBacklog() $second = stream_socket_client($server->getAddress()); fclose($second); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } diff --git a/tests/SecureIntegrationTest.php b/tests/SecureIntegrationTest.php index 696d99c8..cf22c6ca 100644 --- a/tests/SecureIntegrationTest.php +++ b/tests/SecureIntegrationTest.php @@ -10,7 +10,7 @@ use React\Socket\SecureServer; use React\Socket\TcpConnector; use React\Socket\TcpServer; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\all; // use function React\Promise\Timer\timeout; @@ -52,7 +52,7 @@ public function tearDownServer() public function testConnectToServer() { - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ $client->close(); @@ -67,7 +67,7 @@ public function testConnectToServerEmitsConnection() $promiseClient = $this->connector->connect($this->address); - list($_, $client) = \Clue\React\Block\await(\React\Promise\Timer\timeout(\React\Promise\all(array($promiseServer, $promiseClient)), self::TIMEOUT)); + list($_, $client) = \React\Async\await(\React\Promise\Timer\timeout(\React\Promise\all(array($promiseServer, $promiseClient)), self::TIMEOUT)); /* @var $client ConnectionInterface */ $client->close(); @@ -83,13 +83,13 @@ public function testSendSmallDataToServerReceivesOneChunk() }); }); - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ $client->write('hello'); // await server to report one "data" event - $data = \Clue\React\Block\await(\React\Promise\Timer\timeout($received->promise(), self::TIMEOUT)); + $data = \React\Async\await(\React\Promise\Timer\timeout($received->promise(), self::TIMEOUT)); $client->close(); @@ -124,14 +124,14 @@ public function testSendDataWithEndToServerReceivesAllData() }); }); - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ $data = str_repeat('a', 200000); $client->end($data); // await server to report connection "close" event - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($disconnected->promise(), self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($disconnected->promise(), self::TIMEOUT)); $this->assertEquals(strlen($data), strlen($received)); $this->assertEquals($data, $received); @@ -159,7 +159,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData() $connection->write($data); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(strlen($data), strlen($received)); $this->assertEquals($data, $received); @@ -175,12 +175,12 @@ public function testConnectToServerWhichSendsSmallDataReceivesOneChunk() $peer->write('hello'); }); - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ // await client to report one "data" event $receive = $this->createPromiseForEvent($client, 'data', $this->expectCallableOnceWith('hello')); - \Clue\React\Block\await(\React\Promise\Timer\timeout($receive, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($receive, self::TIMEOUT)); $client->close(); } @@ -192,7 +192,7 @@ public function testConnectToServerWhichSendsDataWithEndReceivesAllData() $peer->end($data); }); - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ // await data from client until it closes @@ -223,7 +223,7 @@ public function testConnectToServerWhichSendsDataWithoutEndingReceivesAllData() }, $reject); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(strlen($data), $received); diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 83db34f3..7e069c88 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -7,7 +7,7 @@ use React\Socket\Server; use React\Socket\TcpConnector; use React\Socket\UnixConnector; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Timer\sleep; // use function React\Promise\Timer\timeout; @@ -55,7 +55,7 @@ public function testConstructorCreatesExpectedTcpServer() $promise = $connector->connect($server->getAddress()); $promise->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -78,7 +78,7 @@ public function testConstructorCreatesExpectedUnixServer() $connector->connect($server->getAddress()) ->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); $connection->close(); $server->close(); @@ -130,7 +130,7 @@ public function testEmitsConnectionForNewConnection() $client = stream_socket_client($server->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } @@ -143,7 +143,7 @@ public function testDoesNotEmitConnectionForNewConnectionToPausedServer() $client = stream_socket_client($server->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); + \React\Async\await(\React\Promise\Timer\sleep(0.1)); } public function testDoesEmitConnectionForNewConnectionToResumedServer() @@ -160,7 +160,7 @@ public function testDoesEmitConnectionForNewConnectionToResumedServer() $server->resume(); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } @@ -197,7 +197,7 @@ public function testEmitsConnectionWithInheritedContextOptions() $client = stream_socket_client($server->getAddress()); - $all = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $all = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array('socket' => array('backlog' => 4)), $all); @@ -219,7 +219,7 @@ public function testDoesNotEmitSecureConnectionForNewPlaintextConnectionThatIsId $client = stream_socket_client(str_replace('tls://', '', $server->getAddress())); - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); + \React\Async\await(\React\Promise\Timer\sleep(0.1)); $server->close(); } diff --git a/tests/SocketServerTest.php b/tests/SocketServerTest.php index 20419d9f..9c6779e7 100644 --- a/tests/SocketServerTest.php +++ b/tests/SocketServerTest.php @@ -7,7 +7,7 @@ use React\Socket\SocketServer; use React\Socket\TcpConnector; use React\Socket\UnixConnector; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Timer\sleep; // use function React\Promise\Timer\timeout; @@ -76,7 +76,7 @@ public function testConstructorCreatesExpectedTcpServer() $promise = $connector->connect($socket->getAddress()); $promise->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); $socket->close(); $promise->then(function (ConnectionInterface $connection) { @@ -99,7 +99,7 @@ public function testConstructorCreatesExpectedUnixServer() $connector->connect($socket->getAddress()) ->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); $socket->close(); } @@ -165,7 +165,7 @@ public function testEmitsConnectionForNewConnection() $client = stream_socket_client($socket->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $socket->close(); } @@ -178,7 +178,7 @@ public function testDoesNotEmitConnectionForNewConnectionToPausedServer() $client = stream_socket_client($socket->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); + \React\Async\await(\React\Promise\Timer\sleep(0.1)); } public function testDoesEmitConnectionForNewConnectionToResumedServer() @@ -195,7 +195,7 @@ public function testDoesEmitConnectionForNewConnectionToResumedServer() $socket->resume(); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $socket->close(); } @@ -234,7 +234,7 @@ public function testEmitsConnectionWithInheritedContextOptions() $client = stream_socket_client($socket->getAddress()); - $all = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $all = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array('socket' => array('backlog' => 4)), $all); @@ -256,7 +256,7 @@ public function testDoesNotEmitSecureConnectionForNewPlaintextConnectionThatIsId $client = stream_socket_client(str_replace('tls://', '', $socket->getAddress())); - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); + \React\Async\await(\React\Promise\Timer\sleep(0.1)); $socket->close(); } diff --git a/tests/TcpConnectorTest.php b/tests/TcpConnectorTest.php index 3793ecef..5f73dc3e 100644 --- a/tests/TcpConnectorTest.php +++ b/tests/TcpConnectorTest.php @@ -7,7 +7,7 @@ use React\Socket\TcpConnector; use React\Socket\TcpServer; use React\Promise\Promise; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Timer\timeout; class TcpConnectorTest extends TestCase @@ -43,7 +43,7 @@ public function connectionToEmptyPortShouldFailWithoutCallingCustomErrorHandler( ); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); restore_error_handler(); } catch (\Exception $e) { @@ -79,7 +79,7 @@ public function connectionToTcpServerShouldSucceed() $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); @@ -131,7 +131,7 @@ class_exists('PHPUnit\Framework\Error\Warning', true); } $this->setExpectedException('RuntimeException'); - \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); } /** @test */ @@ -163,7 +163,7 @@ public function connectionToInvalidNetworkShouldFailWithUnreachableError() 'Connection to ' . $address . ' failed: ' . (function_exists('socket_strerror') ? socket_strerror($enetunreach) . ' (ENETUNREACH)' : 'Network is unreachable'), $enetunreach ); - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } /** @test */ @@ -173,7 +173,7 @@ public function connectionToTcpServerShouldSucceedWithRemoteAdressSameAsTarget() $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $this->assertEquals('tcp://127.0.0.1:9999', $connection->getRemoteAddress()); @@ -189,7 +189,7 @@ public function connectionToTcpServerShouldSucceedWithLocalAdressOnLocalhost() $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $this->assertContainsString('tcp://127.0.0.1:', $connection->getLocalAddress()); @@ -206,7 +206,7 @@ public function connectionToTcpServerShouldSucceedWithNullAddressesAfterConnecti $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $server->close(); @@ -260,7 +260,7 @@ public function connectionToIp6TcpServerShouldSucceed() $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('[::1]:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('[::1]:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $this->assertEquals('tcp://[::1]:9999', $connection->getRemoteAddress()); @@ -359,7 +359,7 @@ public function cancellingConnectionShouldRejectPromise() ); try { - \Clue\React\Block\await($promise); + \React\Async\await($promise); } catch (\Exception $e) { $server->close(); throw $e; diff --git a/tests/TcpServerTest.php b/tests/TcpServerTest.php index 3774e2c9..db9aba83 100644 --- a/tests/TcpServerTest.php +++ b/tests/TcpServerTest.php @@ -6,7 +6,7 @@ use React\Socket\TcpServer; use React\Stream\DuplexResourceStream; use React\Promise\Promise; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Timer\sleep; // use function React\Promise\Timer\timeout; @@ -55,7 +55,7 @@ public function testServerEmitsConnectionEventForNewConnection() $server->on('connection', $resolve); }); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); } @@ -74,6 +74,7 @@ public function testConnectionWithManyClients() $this->tick(); $this->tick(); $this->tick(); + $this->tick(); } public function testDataEventWillNotBeEmittedWhenClientSendsNoData() @@ -376,6 +377,6 @@ private function tick() $this->markTestSkipped('Not supported on Windows'); } - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.0)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 9389c51c..eae46612 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,10 +2,10 @@ namespace React\Tests\Socket; -use React\Stream\ReadableStreamInterface; -use React\Promise\Promise; use PHPUnit\Framework\TestCase as BaseTestCase; -// use function Clue\React\Block\await; +use React\Promise\Promise; +use React\Stream\ReadableStreamInterface; +// use function React\Async\await; // use function React\Promise\Timer\timeout; class TestCase extends BaseTestCase @@ -77,7 +77,7 @@ protected function buffer(ReadableStreamInterface $stream, $timeout) return ''; } - return \Clue\React\Block\await(\React\Promise\Timer\timeout(new Promise( + return \React\Async\await(\React\Promise\Timer\timeout(new Promise( function ($resolve, $reject) use ($stream) { $buffer = ''; $stream->on('data', function ($chunk) use (&$buffer) { diff --git a/tests/TimeoutConnectorTest.php b/tests/TimeoutConnectorTest.php index 05e88fc7..490c7d4c 100644 --- a/tests/TimeoutConnectorTest.php +++ b/tests/TimeoutConnectorTest.php @@ -6,7 +6,7 @@ use React\Promise; use React\EventLoop\Loop; use React\Promise\Deferred; -// use function Clue\React\Block\await; +// use function React\Async\await; class TimeoutConnectorTest extends TestCase { @@ -32,12 +32,15 @@ public function testRejectsWithTimeoutReasonOnTimeout() $timeout = new TimeoutConnector($connector, 0.01); + $promise = $timeout->connect('google.com:80'); + Loop::run(); + $this->setExpectedException( 'RuntimeException', 'Connection to google.com:80 timed out after 0.01 seconds (ETIMEDOUT)', \defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 110 ); - \Clue\React\Block\await($timeout->connect('google.com:80')); + \React\Async\await($promise); } public function testRejectsWithOriginalReasonWhenConnectorRejects() @@ -54,7 +57,7 @@ public function testRejectsWithOriginalReasonWhenConnectorRejects() 'Failed', 42 ); - \Clue\React\Block\await($timeout->connect('google.com:80')); + \React\Async\await($timeout->connect('google.com:80')); } public function testResolvesWhenConnectorResolves() diff --git a/tests/UnixServerTest.php b/tests/UnixServerTest.php index 1e3eafff..c6f83c91 100644 --- a/tests/UnixServerTest.php +++ b/tests/UnixServerTest.php @@ -5,7 +5,7 @@ use React\EventLoop\Loop; use React\Socket\UnixServer; use React\Stream\DuplexResourceStream; -// use function Clue\React\Block\await; +// use function React\Async\await; // use function React\Promise\Timer\sleep; class UnixServerTest extends TestCase @@ -384,6 +384,6 @@ private function getRandomSocketUri() private function tick() { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.0)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); } }