Skip to content

Commit aba7c0e

Browse files
committed
Avoid using deprecated functions from clue/reactphp-block
1 parent 12baa6c commit aba7c0e

15 files changed

+162
-137
lines changed

tests/FdServerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace React\Tests\Socket;
44

5-
use Clue\React\Block;
65
use React\Promise\Promise;
76
use React\Socket\ConnectionInterface;
87
use React\Socket\FdServer;
8+
// use function Clue\React\Block\await;
9+
// use function React\Promise\Timer\timeout;
910

1011
class FdServerTest extends TestCase
1112
{
@@ -322,7 +323,7 @@ public function testServerEmitsConnectionEventForNewConnection()
322323
$server->on('connection', $resolve);
323324
});
324325

325-
$connection = Block\await($promise, null, 1.0);
326+
$connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, 1.0));
326327

327328
/**
328329
* @var ConnectionInterface $connection

tests/FunctionalConnectorTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace React\Tests\Socket;
44

5-
use Clue\React\Block;
65
use React\EventLoop\Loop;
76
use React\Promise\Deferred;
87
use React\Socket\ConnectionInterface;
98
use React\Socket\Connector;
109
use React\Socket\ConnectorInterface;
1110
use React\Socket\TcpServer;
11+
// use function Clue\React\Block\await;
12+
// use function React\Promise\Stream\buffer;
13+
// use function React\Promise\Timer\timeout;
1214

1315
class FunctionalConnectorTest extends TestCase
1416
{
@@ -24,7 +26,7 @@ public function connectionToTcpServerShouldSucceedWithLocalhost()
2426

2527
$connector = new Connector(array());
2628

27-
$connection = Block\await($connector->connect('localhost:9998'), null, self::TIMEOUT);
29+
$connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('localhost:9998'), self::TIMEOUT));
2830

2931
$server->close();
3032

@@ -63,11 +65,11 @@ public function testConnectTwiceWithoutHappyEyeBallsOnlySendsSingleDnsQueryDueTo
6365
fclose($client);
6466
});
6567

66-
$connection = Block\await($connector->connect('example.com:80'));
68+
$connection = \Clue\React\Block\await($connector->connect('example.com:80'));
6769
$connection->close();
6870
$this->assertEquals(1, $received);
6971

70-
$connection = Block\await($connector->connect('example.com:80'));
72+
$connection = \Clue\React\Block\await($connector->connect('example.com:80'));
7173
$connection->close();
7274
$this->assertEquals(1, $received);
7375

@@ -85,7 +87,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP()
8587

8688
$connector = new Connector(array('happy_eyeballs' => true));
8789

88-
$ip = Block\await($this->request('dual.tlund.se', $connector), null, self::TIMEOUT);
90+
$ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('dual.tlund.se', $connector), self::TIMEOUT));
8991

9092
$this->assertNotFalse(inet_pton($ip));
9193
}
@@ -99,7 +101,7 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP()
99101
$connector = new Connector(array('happy_eyeballs' => true));
100102

101103
try {
102-
$ip = Block\await($this->request('ipv4.tlund.se', $connector), null, self::TIMEOUT);
104+
$ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('ipv4.tlund.se', $connector), self::TIMEOUT));
103105
} catch (\Exception $e) {
104106
$this->checkIpv4();
105107
throw $e;
@@ -118,7 +120,7 @@ public function connectionToRemoteTCP6ServerShouldResultInOurIP()
118120
$connector = new Connector(array('happy_eyeballs' => true));
119121

120122
try {
121-
$ip = Block\await($this->request('ipv6.tlund.se', $connector), null, self::TIMEOUT);
123+
$ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('ipv6.tlund.se', $connector), self::TIMEOUT));
122124
} catch (\Exception $e) {
123125
$this->checkIpv6();
124126
throw $e;
@@ -151,11 +153,11 @@ public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpCo
151153
});
152154
});
153155

154-
Block\await($deferred->promise(), null, self::TIMEOUT);
156+
\Clue\React\Block\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT));
155157
$server->close();
156158

157159
try {
158-
Block\await($promise, null, self::TIMEOUT);
160+
\Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
159161
$this->fail();
160162
} catch (\Exception $e) {
161163
$this->assertInstanceOf('RuntimeException', $e);

tests/FunctionalSecureServerTest.php

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
namespace React\Tests\Socket;
44

5-
use Clue\React\Block;
6-
use Evenement\EventEmitterInterface;
75
use React\Promise\Promise;
86
use React\Socket\ConnectionInterface;
97
use React\Socket\SecureConnector;
108
use React\Socket\ServerInterface;
119
use React\Socket\SecureServer;
1210
use React\Socket\TcpConnector;
1311
use React\Socket\TcpServer;
12+
// use function Clue\React\Block\await;
13+
// use function React\Promise\all;
14+
// use function React\Promise\Timer\timeout;
1415

1516
class 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

Comments
 (0)