Skip to content

Commit a2ae0f1

Browse files
committed
Avoid using deprecated functions from clue/reactphp-block
1 parent 90413fb commit a2ae0f1

5 files changed

+33
-32
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"clue/http-proxy-react": "^1.7",
4343
"clue/reactphp-ssh-proxy": "^1.3",
4444
"clue/socks-react": "^1.3",
45-
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
45+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
46+
"react/promise-timer": "^1.9"
4647
},
4748
"autoload": {
4849
"psr-4": { "React\\Http\\": "src" }

tests/Client/FunctionalIntegrationTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testRequestToLocalhostEmitsSingleRemoteConnection()
5151
$promise = Stream\first($request, 'close');
5252
$request->end();
5353

54-
Block\await($promise, null, self::TIMEOUT_LOCAL);
54+
Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT_LOCAL));
5555
}
5656

5757
public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResponse()
@@ -73,7 +73,7 @@ public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResp
7373
$promise = Stream\first($request, 'close');
7474
$request->end();
7575

76-
Block\await($promise, null, self::TIMEOUT_LOCAL);
76+
Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT_LOCAL));
7777
}
7878

7979
/** @group internet */
@@ -94,7 +94,7 @@ public function testSuccessfulResponseEmitsEnd()
9494
$promise = Stream\first($request, 'close');
9595
$request->end();
9696

97-
Block\await($promise, null, self::TIMEOUT_REMOTE);
97+
Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT_REMOTE));
9898
}
9999

100100
/** @group internet */
@@ -122,7 +122,7 @@ public function testPostDataReturnsData()
122122

123123
$request->end($data);
124124

125-
$buffer = Block\await($deferred->promise(), null, self::TIMEOUT_REMOTE);
125+
$buffer = Block\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT_REMOTE));
126126

127127
$this->assertNotEquals('', $buffer);
128128

@@ -154,7 +154,7 @@ public function testPostJsonReturnsData()
154154

155155
$request->end($data);
156156

157-
$buffer = Block\await($deferred->promise(), null, self::TIMEOUT_REMOTE);
157+
$buffer = Block\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT_REMOTE));
158158

159159
$this->assertNotEquals('', $buffer);
160160

tests/FunctionalBrowserTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public function testReceiveStreamAndExplicitlyCloseConnectionEvenWhenServerKeeps
531531
$response = Block\await($this->browser->get($this->base . 'get', array()));
532532
$this->assertEquals('hello', (string)$response->getBody());
533533

534-
$ret = Block\await($closed->promise(), null, 0.1);
534+
$ret = Block\await(\React\Promise\Timer\timeout($closed->promise(), 0.1));
535535
$this->assertTrue($ret);
536536

537537
$socket->close();

tests/FunctionalHttpServerTest.php

+23-23
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testPlainHttpOnRandomPort()
3737
return Stream\buffer($conn);
3838
});
3939

40-
$response = Block\await($result, null, 1.0);
40+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
4141

4242
$this->assertContainsString("HTTP/1.0 200 OK", $response);
4343
$this->assertContainsString('http://' . noScheme($socket->getAddress()) . '/', $response);
@@ -64,7 +64,7 @@ function () {
6464
return Stream\buffer($conn);
6565
});
6666

67-
$response = Block\await($result, null, 1.0);
67+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
6868

6969
$this->assertContainsString("HTTP/1.0 404 Not Found", $response);
7070

@@ -88,7 +88,7 @@ public function testPlainHttpOnRandomPortWithoutHostHeaderUsesSocketUri()
8888
return Stream\buffer($conn);
8989
});
9090

91-
$response = Block\await($result, null, 1.0);
91+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
9292

9393
$this->assertContainsString("HTTP/1.0 200 OK", $response);
9494
$this->assertContainsString('http://' . noScheme($socket->getAddress()) . '/', $response);
@@ -113,7 +113,7 @@ public function testPlainHttpOnRandomPortWithOtherHostHeaderTakesPrecedence()
113113
return Stream\buffer($conn);
114114
});
115115

116-
$response = Block\await($result, null, 1.0);
116+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
117117

118118
$this->assertContainsString("HTTP/1.0 200 OK", $response);
119119
$this->assertContainsString('http://localhost:1000/', $response);
@@ -146,7 +146,7 @@ public function testSecureHttpsOnRandomPort()
146146
return Stream\buffer($conn);
147147
});
148148

149-
$response = Block\await($result, null, 1.0);
149+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
150150

151151
$this->assertContainsString("HTTP/1.0 200 OK", $response);
152152
$this->assertContainsString('https://' . noScheme($socket->getAddress()) . '/', $response);
@@ -183,7 +183,7 @@ public function testSecureHttpsReturnsData()
183183
return Stream\buffer($conn);
184184
});
185185

186-
$response = Block\await($result, null, 1.0);
186+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
187187

188188
$this->assertContainsString("HTTP/1.0 200 OK", $response);
189189
$this->assertContainsString("\r\nContent-Length: 33000\r\n", $response);
@@ -217,7 +217,7 @@ public function testSecureHttpsOnRandomPortWithoutHostHeaderUsesSocketUri()
217217
return Stream\buffer($conn);
218218
});
219219

220-
$response = Block\await($result, null, 1.0);
220+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
221221

222222
$this->assertContainsString("HTTP/1.0 200 OK", $response);
223223
$this->assertContainsString('https://' . noScheme($socket->getAddress()) . '/', $response);
@@ -246,7 +246,7 @@ public function testPlainHttpOnStandardPortReturnsUriWithNoPort()
246246
return Stream\buffer($conn);
247247
});
248248

249-
$response = Block\await($result, null, 1.0);
249+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
250250

251251
$this->assertContainsString("HTTP/1.0 200 OK", $response);
252252
$this->assertContainsString('http://127.0.0.1/', $response);
@@ -275,7 +275,7 @@ public function testPlainHttpOnStandardPortWithoutHostHeaderReturnsUriWithNoPort
275275
return Stream\buffer($conn);
276276
});
277277

278-
$response = Block\await($result, null, 1.0);
278+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
279279

280280
$this->assertContainsString("HTTP/1.0 200 OK", $response);
281281
$this->assertContainsString('http://127.0.0.1/', $response);
@@ -313,7 +313,7 @@ public function testSecureHttpsOnStandardPortReturnsUriWithNoPort()
313313
return Stream\buffer($conn);
314314
});
315315

316-
$response = Block\await($result, null, 1.0);
316+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
317317

318318
$this->assertContainsString("HTTP/1.0 200 OK", $response);
319319
$this->assertContainsString('https://127.0.0.1/', $response);
@@ -351,7 +351,7 @@ public function testSecureHttpsOnStandardPortWithoutHostHeaderUsesSocketUri()
351351
return Stream\buffer($conn);
352352
});
353353

354-
$response = Block\await($result, null, 1.0);
354+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
355355

356356
$this->assertContainsString("HTTP/1.0 200 OK", $response);
357357
$this->assertContainsString('https://127.0.0.1/', $response);
@@ -380,7 +380,7 @@ public function testPlainHttpOnHttpsStandardPortReturnsUriWithPort()
380380
return Stream\buffer($conn);
381381
});
382382

383-
$response = Block\await($result, null, 1.0);
383+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
384384

385385
$this->assertContainsString("HTTP/1.0 200 OK", $response);
386386
$this->assertContainsString('http://127.0.0.1:443/', $response);
@@ -418,7 +418,7 @@ public function testSecureHttpsOnHttpStandardPortReturnsUriWithPort()
418418
return Stream\buffer($conn);
419419
});
420420

421-
$response = Block\await($result, null, 1.0);
421+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
422422

423423
$this->assertContainsString("HTTP/1.0 200 OK", $response);
424424
$this->assertContainsString('https://127.0.0.1:80/', $response);
@@ -446,7 +446,7 @@ public function testClosedStreamFromRequestHandlerWillSendEmptyBody()
446446
return Stream\buffer($conn);
447447
});
448448

449-
$response = Block\await($result, null, 1.0);
449+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
450450

451451
$this->assertStringStartsWith("HTTP/1.0 200 OK", $response);
452452
$this->assertStringEndsWith("\r\n\r\n", $response);
@@ -477,7 +477,7 @@ function (RequestInterface $request) use ($once) {
477477
});
478478
});
479479

480-
Block\sleep(0.1);
480+
\Clue\React\Block\await(\React\Promise\Timer\sleep(0.1));
481481

482482
$socket->close();
483483
}
@@ -507,7 +507,7 @@ function (RequestInterface $request) use ($stream) {
507507
});
508508

509509
// stream will be closed within 0.1s
510-
$ret = Block\await(Stream\first($stream, 'close'), null, 0.1);
510+
$ret = Block\await(\React\Promise\Timer\timeout(Stream\first($stream, 'close'), 0.1));
511511

512512
$socket->close();
513513

@@ -536,7 +536,7 @@ public function testStreamFromRequestHandlerWillBeClosedIfConnectionCloses()
536536
});
537537

538538
// await response stream to be closed
539-
$ret = Block\await(Stream\first($stream, 'close'), null, 1.0);
539+
$ret = Block\await(\React\Promise\Timer\timeout(Stream\first($stream, 'close'), 1.0));
540540

541541
$socket->close();
542542

@@ -571,7 +571,7 @@ public function testUpgradeWithThroughStreamReturnsDataAsGiven()
571571
return Stream\buffer($conn);
572572
});
573573

574-
$response = Block\await($result, null, 1.0);
574+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
575575

576576
$this->assertStringStartsWith("HTTP/1.1 101 Switching Protocols\r\n", $response);
577577
$this->assertStringEndsWith("\r\n\r\nhelloworld", $response);
@@ -608,7 +608,7 @@ public function testUpgradeWithRequestBodyAndThroughStreamReturnsDataAsGiven()
608608
return Stream\buffer($conn);
609609
});
610610

611-
$response = Block\await($result, null, 1.0);
611+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
612612

613613
$this->assertStringStartsWith("HTTP/1.1 101 Switching Protocols\r\n", $response);
614614
$this->assertStringEndsWith("\r\n\r\nhelloworld", $response);
@@ -644,7 +644,7 @@ public function testConnectWithThroughStreamReturnsDataAsGiven()
644644
return Stream\buffer($conn);
645645
});
646646

647-
$response = Block\await($result, null, 1.0);
647+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
648648

649649
$this->assertStringStartsWith("HTTP/1.1 200 OK\r\n", $response);
650650
$this->assertStringEndsWith("\r\n\r\nhelloworld", $response);
@@ -684,7 +684,7 @@ public function testConnectWithThroughStreamReturnedFromPromiseReturnsDataAsGive
684684
return Stream\buffer($conn);
685685
});
686686

687-
$response = Block\await($result, null, 1.0);
687+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
688688

689689
$this->assertStringStartsWith("HTTP/1.1 200 OK\r\n", $response);
690690
$this->assertStringEndsWith("\r\n\r\nhelloworld", $response);
@@ -717,7 +717,7 @@ public function testConnectWithClosedThroughStreamReturnsNoData()
717717
return Stream\buffer($conn);
718718
});
719719

720-
$response = Block\await($result, null, 1.0);
720+
$response = Block\await(\React\Promise\Timer\timeout($result, 1.0));
721721

722722
$this->assertStringStartsWith("HTTP/1.1 200 OK\r\n", $response);
723723
$this->assertStringEndsWith("\r\n\r\n", $response);
@@ -760,7 +760,7 @@ function (ServerRequestInterface $request) {
760760
});
761761
}
762762

763-
$responses = Block\await(Promise\all($result), null, 1.0);
763+
$responses = Block\await(\React\Promise\Timer\timeout(Promise\all($result), 1.0));
764764

765765
foreach ($responses as $response) {
766766
$this->assertContainsString("HTTP/1.0 200 OK", $response, $response);

tests/Io/TransactionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public function testReceivingStreamingBodyWithSizeExceedingMaximumResponseBuffer
424424
$promise = $transaction->send($request);
425425

426426
$this->setExpectedException('OverflowException');
427-
Block\await($promise, null, 0.001);
427+
Block\await(\React\Promise\Timer\timeout($promise, 0.001));
428428
}
429429

430430
public function testCancelBufferingResponseWillCloseStreamAndReject()
@@ -445,7 +445,7 @@ public function testCancelBufferingResponseWillCloseStreamAndReject()
445445
$promise->cancel();
446446

447447
$this->setExpectedException('RuntimeException');
448-
Block\await($promise, null, 0.001);
448+
Block\await(\React\Promise\Timer\timeout($promise, 0.001));
449449
}
450450

451451
public function testReceivingStreamingBodyWillResolveWithStreamingResponseIfStreamingIsEnabled()

0 commit comments

Comments
 (0)