Skip to content

Commit afc1f1d

Browse files
authored
Merge pull request #53 from dinooo13/async
Use reactphp/async instead of clue/reactphp-block
2 parents 2a8b1e5 + 1b35c7b commit afc1f1d

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"react/promise": "^3 || ^2.1 || ^1.2"
3535
},
3636
"require-dev": {
37-
"clue/block-react": "~1.0",
37+
"react/async": "^4 || ^3 || ^2",
3838
"phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35"
3939
},
4040
"autoload": {

tests/FactoryTest.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace React\Tests\Datagram;
44

5-
use Clue\React\Block;
65
use React\Datagram\Factory;
76
use React\Datagram\Socket;
87
use React\Promise;
@@ -40,7 +39,7 @@ public function testCreateClient()
4039

4140
$promise = $this->factory->createClient('127.0.0.1:12345');
4241

43-
$capturedClient = Block\await($promise, $this->loop);
42+
$capturedClient = \React\Async\await($promise);
4443
$this->assertInstanceOf('React\Datagram\Socket', $capturedClient);
4544

4645
$this->assertEquals('127.0.0.1:12345', $capturedClient->getRemoteAddress());
@@ -59,7 +58,7 @@ public function testCreateClientLocalhost()
5958

6059
$promise = $this->factory->createClient('localhost:12345');
6160

62-
$capturedClient = Block\await($promise, $this->loop);
61+
$capturedClient = \React\Async\await($promise);
6362
$this->assertInstanceOf('React\Datagram\Socket', $capturedClient);
6463

6564
$this->assertEquals('127.0.0.1:12345', $capturedClient->getRemoteAddress());
@@ -77,7 +76,7 @@ public function testCreateClientLocalhostWithDefaultResolver()
7776

7877
$promise = $this->factory->createClient('localhost:12345');
7978

80-
$capturedClient = Block\await($promise, $this->loop);
79+
$capturedClient = \React\Async\await($promise);
8180
$this->assertInstanceOf('React\Datagram\SocketInterface', $capturedClient);
8281

8382
$capturedClient->close();
@@ -88,7 +87,7 @@ public function testCreateClientIpv6()
8887
$promise = $this->factory->createClient('[::1]:12345');
8988

9089
try {
91-
$capturedClient = Block\await($promise, $this->loop);
90+
$capturedClient = \React\Async\await($promise);
9291
} catch (\Exception $e) {
9392
$this->markTestSkipped('Unable to start IPv6 client socket (IPv6 not supported on this system?)');
9493
}
@@ -107,7 +106,7 @@ public function testCreateServer()
107106
{
108107
$promise = $this->factory->createServer('127.0.0.1:12345');
109108

110-
$capturedServer = Block\await($promise, $this->loop);
109+
$capturedServer = \React\Async\await($promise);
111110
$this->assertInstanceOf('React\Datagram\Socket', $capturedServer);
112111

113112
$this->assertEquals('127.0.0.1:12345', $capturedServer->getLocalAddress());
@@ -122,7 +121,7 @@ public function testCreateServerRandomPort()
122121
{
123122
$promise = $this->factory->createServer('127.0.0.1:0');
124123

125-
$capturedServer = Block\await($promise, $this->loop);
124+
$capturedServer = \React\Async\await($promise);
126125
$this->assertInstanceOf('React\Datagram\Socket', $capturedServer);
127126

128127
$this->assertNotEquals('127.0.0.1:0', $capturedServer->getLocalAddress());
@@ -135,15 +134,15 @@ public function testCreateClientWithIpWillNotUseResolver()
135134
{
136135
$this->resolver->expects($this->never())->method('resolve');
137136

138-
$client = Block\await($this->factory->createClient('127.0.0.1:0'), $this->loop);
137+
$client = \React\Async\await($this->factory->createClient('127.0.0.1:0'));
139138
$client->close();
140139
}
141140

142141
public function testCreateClientWithHostnameWillUseResolver()
143142
{
144143
$this->resolver->expects($this->once())->method('resolve')->with('example.com')->willReturn(Promise\resolve('127.0.0.1'));
145144

146-
$client = Block\await($this->factory->createClient('example.com:0'), $this->loop);
145+
$client = \React\Async\await($this->factory->createClient('example.com:0'));
147146
$client->close();
148147
}
149148

@@ -152,19 +151,19 @@ public function testCreateClientWithHostnameWillRejectIfResolverRejects()
152151
$this->resolver->expects($this->once())->method('resolve')->with('example.com')->willReturn(Promise\reject(new \RuntimeException('test')));
153152

154153
$this->setExpectedException('RuntimeException');
155-
Block\await($this->factory->createClient('example.com:0'), $this->loop);
154+
\React\Async\await($this->factory->createClient('example.com:0'));
156155
}
157156

158157
public function testCreateClientWithInvalidHostnameWillReject()
159158
{
160159
$this->setExpectedException('Exception', 'Unable to create client socket');
161-
Block\await($this->factory->createClient('/////'), $this->loop);
160+
\React\Async\await($this->factory->createClient('/////'));
162161
}
163162

164163
public function testCreateServerWithInvalidHostnameWillReject()
165164
{
166165
$this->setExpectedException('Exception', 'Unable to create server socket');
167-
Block\await($this->factory->createServer('/////'), $this->loop);
166+
\React\Async\await($this->factory->createServer('/////'));
168167
}
169168

170169
public function testCancelCreateClientWithCancellableHostnameResolver()
@@ -176,7 +175,7 @@ public function testCancelCreateClientWithCancellableHostnameResolver()
176175
$promise->cancel();
177176

178177
$this->setExpectedException('RuntimeException');
179-
Block\await($promise, $this->loop);
178+
\React\Async\await($promise);
180179
}
181180

182181
public function testCancelCreateClientWithUncancellableHostnameResolver()
@@ -188,6 +187,6 @@ public function testCancelCreateClientWithUncancellableHostnameResolver()
188187
$promise->cancel();
189188

190189
$this->setExpectedException('RuntimeException');
191-
Block\await($promise, $this->loop);
190+
\React\Async\await($promise);
192191
}
193192
}

tests/SocketTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace React\Tests\Datagram;
44

55
use React\Datagram\Socket;
6-
use Clue\React\Block;
76

87
class SocketTest extends TestCase
98
{
@@ -25,7 +24,7 @@ public function setUpFactory()
2524
public function testCreateClientCloseWillNotBlock()
2625
{
2726
$promise = $this->factory->createClient('127.0.0.1:12345');
28-
$client = Block\await($promise, $this->loop);
27+
$client = \React\Async\await($promise);
2928

3029
$client->send('test');
3130
$client->close();
@@ -52,7 +51,7 @@ public function testClientCloseAgainWillNotBlock(Socket $client)
5251
public function testCreateClientEndWillNotBlock()
5352
{
5453
$promise = $this->factory->createClient('127.0.0.1:12345');
55-
$client = Block\await($promise, $this->loop);
54+
$client = \React\Async\await($promise);
5655

5756
$client->send('test');
5857
$client->end();
@@ -89,7 +88,7 @@ public function testClientSendAfterEndIsNoop(Socket $client)
8988
public function testClientSendHugeWillFailWithoutCallingCustomErrorHandler()
9089
{
9190
$promise = $this->factory->createClient('127.0.0.1:12345');
92-
$client = Block\await($promise, $this->loop);
91+
$client = \React\Async\await($promise);
9392

9493
$client->send(str_repeat(1, 1024 * 1024));
9594
$client->on('error', $this->expectCallableOnce());
@@ -109,7 +108,7 @@ public function testClientSendHugeWillFailWithoutCallingCustomErrorHandler()
109108
public function testClientSendNoServerWillFail()
110109
{
111110
$promise = $this->factory->createClient('127.0.0.1:1234');
112-
$client = Block\await($promise, $this->loop);
111+
$client = \React\Async\await($promise);
113112

114113
// send a message to a socket that is not actually listening
115114
// expect the remote end to reject this by sending an ICMP message
@@ -135,10 +134,10 @@ public function testClientSendNoServerWillFail()
135134
public function testCreatePair()
136135
{
137136
$promise = $this->factory->createServer('127.0.0.1:0');
138-
$server = Block\await($promise, $this->loop);
137+
$server = \React\Async\await($promise);
139138

140139
$promise = $this->factory->createClient($server->getLocalAddress());
141-
$client = Block\await($promise, $this->loop);
140+
$client = \React\Async\await($promise);
142141

143142
$that = $this;
144143
$server->on('message', function ($message, $remote, $server) use ($that) {
@@ -181,7 +180,7 @@ public function testSanitizeAddress($address)
181180
$promise = $this->factory->createServer($address);
182181

183182
try {
184-
$server = Block\await($promise, $this->loop);
183+
$server = \React\Async\await($promise);
185184
} catch (\Exception $e) {
186185
if (strpos($address, '[') === false) {
187186
throw $e;
@@ -191,7 +190,7 @@ public function testSanitizeAddress($address)
191190
}
192191

193192
$promise = $this->factory->createClient($server->getLocalAddress());
194-
$client = Block\await($promise, $this->loop);
193+
$client = \React\Async\await($promise);
195194

196195
$that = $this;
197196
$server->on('message', function ($message, $remote, $server) use ($that) {

0 commit comments

Comments
 (0)