Skip to content

Commit 2971cb0

Browse files
committed
Update tests to avoid legacy reactphp/promise-timer dependency
1 parent 8b40d8c commit 2971cb0

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

composer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
"require": {
1414
"php": ">=7.1",
1515
"nikic/fast-route": "^1.3",
16-
"react/async": "^4.3 || ^3",
16+
"react/async": "^4.3 || ^3.1",
1717
"react/http": "^1.11",
1818
"react/promise": "^3.2",
1919
"react/socket": "^1.15"
2020
},
2121
"require-dev": {
2222
"phpstan/phpstan": "1.12.11 || 1.4.10",
2323
"phpunit/phpunit": "^9.6 || ^7.5",
24-
"psr/container": "^2 || ^1",
25-
"react/promise-timer": "^1.11"
24+
"psr/container": "^2 || ^1"
2625
},
2726
"autoload": {
2827
"psr-4": {

tests/integration/composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"require": {
3-
"clue/framework-x": "*@dev",
4-
"react/promise-timer": "^1.10"
3+
"clue/framework-x": "*@dev"
54
},
65
"repositories": [
76
{

tests/integration/public/index.php

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
<?php
22

33
use Psr\Http\Message\ServerRequestInterface;
4+
use React\EventLoop\Loop;
5+
use React\Promise\Promise;
6+
use React\Promise\PromiseInterface;
47
use React\Stream\ThroughStream;
58

69
// example uses `@include` for test suite only, real-world examples should use `require` instead
710
if(!@include __DIR__ . '/../vendor/autoload.php') {
811
require __DIR__ . '/../../../vendor/autoload.php';
912
}
1013

14+
/**
15+
* basic "async sleep" to test deferred responses
16+
*
17+
* @return PromiseInterface<void>
18+
* @link https://github.com/reactphp/async#delay
19+
* @link https://github.com/reactphp/promise-timer#sleep
20+
*/
21+
function asleep(float $s): PromiseInterface
22+
{
23+
/** @var PromiseInterface<void> */
24+
return new Promise(function (callable $resolve) use ($s): void {
25+
Loop::addTimer($s, function () use ($resolve): void { $resolve(null); });
26+
});
27+
}
28+
1129
$app = new FrameworkX\App();
1230

1331
$app->get('/', function () {
@@ -31,15 +49,15 @@
3149
});
3250

3351
$app->get('/sleep/fiber', function () {
34-
React\Async\await(React\Promise\Timer\sleep(0.1));
52+
React\Async\delay(0.1); // React\Async\await(asleep(0.1));
3553
return React\Http\Message\Response::plaintext("OK\n");
3654
});
3755
$app->get('/sleep/coroutine', function () {
38-
yield React\Promise\Timer\sleep(0.1);
56+
yield asleep(0.1);
3957
return React\Http\Message\Response::plaintext("OK\n");
4058
});
4159
$app->get('/sleep/promise', function () {
42-
return React\Promise\Timer\sleep(0.1)->then(function () {
60+
return asleep(0.1)->then(function () {
4361
return React\Http\Message\Response::plaintext("OK\n");
4462
});
4563
});

0 commit comments

Comments
 (0)