Skip to content

Commit

Permalink
Update to use new reactphp/async package instead of clue/reactphp-block
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Aug 5, 2022
1 parent aba7c0e commit fe9df48
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 130 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions tests/FdServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions tests/FunctionalConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down Expand Up @@ -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);

Expand All @@ -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));
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
54 changes: 27 additions & 27 deletions tests/FunctionalSecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand All @@ -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);

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit fe9df48

Please sign in to comment.