From 7389409b69d0e62d9fa4b55d3c22d89d3d75c9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 23 Jun 2023 12:43:23 +0200 Subject: [PATCH] Update tests to avoid legacy reactphp/promise-timer dependency --- composer.json | 5 ++--- tests/integration/composer.json | 3 +-- tests/integration/public/index.php | 24 +++++++++++++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 51e2dbf..378bc0c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": ">=7.1", "nikic/fast-route": "^1.3", - "react/async": "^4.3 || ^3", + "react/async": "^4.3 || ^3.1", "react/http": "^1.11", "react/promise": "^3.2", "react/socket": "^1.15" @@ -21,8 +21,7 @@ "require-dev": { "phpstan/phpstan": "1.12.11 || 1.4.10", "phpunit/phpunit": "^9.6 || ^7.5", - "psr/container": "^2 || ^1", - "react/promise-timer": "^1.11" + "psr/container": "^2 || ^1" }, "autoload": { "psr-4": { diff --git a/tests/integration/composer.json b/tests/integration/composer.json index 45c2243..a47dac7 100644 --- a/tests/integration/composer.json +++ b/tests/integration/composer.json @@ -1,7 +1,6 @@ { "require": { - "clue/framework-x": "*@dev", - "react/promise-timer": "^1.10" + "clue/framework-x": "*@dev" }, "repositories": [ { diff --git a/tests/integration/public/index.php b/tests/integration/public/index.php index 1f091a0..8bca0ce 100644 --- a/tests/integration/public/index.php +++ b/tests/integration/public/index.php @@ -1,6 +1,9 @@ + * @link https://github.com/reactphp/async#delay + * @link https://github.com/reactphp/promise-timer#sleep + */ +function asleep(float $s): PromiseInterface +{ + /** @var PromiseInterface */ + return new Promise(function (callable $resolve) use ($s): void { // @phpstan-ignore-line for legacy PHP 7.1 + Loop::addTimer($s, function () use ($resolve): void { $resolve(null); }); + }); +} + $app = new FrameworkX\App(); $app->get('/', function () { @@ -31,15 +49,15 @@ }); $app->get('/sleep/fiber', function () { - React\Async\await(React\Promise\Timer\sleep(0.1)); + React\Async\delay(0.1); // React\Async\await(asleep(0.1)); return React\Http\Message\Response::plaintext("OK\n"); }); $app->get('/sleep/coroutine', function () { - yield React\Promise\Timer\sleep(0.1); + yield asleep(0.1); return React\Http\Message\Response::plaintext("OK\n"); }); $app->get('/sleep/promise', function () { - return React\Promise\Timer\sleep(0.1)->then(function () { + return asleep(0.1)->then(function () { return React\Http\Message\Response::plaintext("OK\n"); }); });