Skip to content

Commit

Permalink
Merge pull request clue#270 from clue-labs/no-timer
Browse files Browse the repository at this point in the history
Update tests to avoid legacy reactphp/promise-timer dependency
  • Loading branch information
PaulRotmann authored Dec 12, 2024
2 parents ee6e5e9 + 7389409 commit 39fac5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
"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"
},
"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": {
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"require": {
"clue/framework-x": "*@dev",
"react/promise-timer": "^1.10"
"clue/framework-x": "*@dev"
},
"repositories": [
{
Expand Down
24 changes: 21 additions & 3 deletions tests/integration/public/index.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
<?php

use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Loop;
use React\Promise\Promise;
use React\Promise\PromiseInterface;
use React\Stream\ThroughStream;

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

/**
* basic "async sleep" to test deferred responses
*
* @return PromiseInterface<void>
* @link https://github.com/reactphp/async#delay
* @link https://github.com/reactphp/promise-timer#sleep
*/
function asleep(float $s): PromiseInterface
{
/** @var PromiseInterface<void> */
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 () {
Expand All @@ -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");
});
});
Expand Down

0 comments on commit 39fac5e

Please sign in to comment.