Skip to content

Commit

Permalink
Forward compatibility with upcoming Promise v3
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Jun 22, 2022
1 parent 55ec42a commit 079da38
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -28,6 +28,8 @@ jobs:
with:
php-version: ${{ matrix.php }}
coverage: xdebug
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: composer install
- run: vendor/bin/phpunit --coverage-text
if: ${{ matrix.php >= 7.3 }}
Expand All @@ -38,6 +40,7 @@ jobs:
name: PHPUnit (HHVM)
runs-on: ubuntu-18.04
continue-on-error: true
if: false # temporarily skipped until https://github.com/azjezz/setup-hhvm/issues/3 is addressed
steps:
- uses: actions/checkout@v2
- uses: azjezz/setup-hhvm@v1
Expand Down
32 changes: 25 additions & 7 deletions composer.json
Expand Up @@ -31,23 +31,41 @@
"fig/http-message-util": "^1.1",
"psr/http-message": "^1.0",
"react/event-loop": "^1.2",
"react/promise": "^2.3 || ^1.2.1",
"react/promise-stream": "^1.1",
"react/socket": "^1.9",
"react/promise": "^3@dev || ^2.1 || ^1.2.1",
"react/promise-stream": "^1.4",
"react/socket": "dev-promise-3 as 1.12.0",
"react/stream": "^1.2",
"ringcentral/psr7": "^1.2"
},
"require-dev": {
"clue/block-react": "^1.5",
"clue/http-proxy-react": "^1.7",
"clue/reactphp-ssh-proxy": "^1.3",
"clue/socks-react": "^1.3",
"clue/http-proxy-react": "dev-promise-v3 as 1.8.0",
"clue/reactphp-ssh-proxy": "dev-promise-v3 as 1.4.0",
"clue/socks-react": "dev-promise-v3 as 1.4.0",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
},
"autoload": {
"psr-4": { "React\\Http\\": "src" }
},
"autoload-dev": {
"psr-4": { "React\\Tests\\Http\\": "tests" }
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/WyriHaximus-labs/socket"
},
{
"type": "vcs",
"url": "https://github.com/clue-labs/reactphp-http-proxy"
},
{
"type": "vcs",
"url": "https://github.com/clue-labs/reactphp-socks"
},
{
"type": "vcs",
"url": "https://github.com/clue-labs/reactphp-ssh-proxy"
}
]
}
3 changes: 1 addition & 2 deletions src/Io/StreamingServer.php
Expand Up @@ -9,7 +9,6 @@
use React\Http\Message\Response;
use React\Http\Message\ServerRequest;
use React\Promise;
use React\Promise\CancellablePromiseInterface;
use React\Promise\PromiseInterface;
use React\Socket\ConnectionInterface;
use React\Socket\ServerInterface;
Expand Down Expand Up @@ -158,7 +157,7 @@ public function handleRequest(ConnectionInterface $conn, ServerRequestInterface
}

// cancel pending promise once connection closes
if ($response instanceof CancellablePromiseInterface) {
if ($response instanceof PromiseInterface && \method_exists($response, 'cancel')) {
$conn->on('close', function () use ($response) {
$response->cancel();
});
Expand Down
3 changes: 1 addition & 2 deletions tests/Io/MiddlewareRunnerTest.php
Expand Up @@ -9,7 +9,6 @@
use React\Http\Io\MiddlewareRunner;
use React\Http\Message\ServerRequest;
use React\Promise;
use React\Promise\CancellablePromiseInterface;
use React\Promise\PromiseInterface;
use React\Tests\Http\Middleware\ProcessStack;
use React\Tests\Http\TestCase;
Expand Down Expand Up @@ -480,7 +479,7 @@ function (RequestInterface $request) use ($once) {

$promise = $middleware($request);

$this->assertTrue($promise instanceof CancellablePromiseInterface);
$this->assertTrue($promise instanceof PromiseInterface && \method_exists($promise, 'cancel'));
$promise->cancel();
}
}
8 changes: 4 additions & 4 deletions tests/Middleware/LimitConcurrentRequestsMiddlewareTest.php
Expand Up @@ -79,7 +79,7 @@ public function testLimitOneRequestConcurrently()
/**
* Ensure resolve frees up a slot
*/
$deferredA->resolve();
$deferredA->resolve(null);

$this->assertTrue($calledA);
$this->assertTrue($calledB);
Expand All @@ -88,7 +88,7 @@ public function testLimitOneRequestConcurrently()
/**
* Ensure reject also frees up a slot
*/
$deferredB->reject();
$deferredB->reject(new \RuntimeException());

$this->assertTrue($calledA);
$this->assertTrue($calledB);
Expand Down Expand Up @@ -194,7 +194,7 @@ public function testStreamDoesPauseAndThenResumeWhenDequeued()

$limitHandlers(new ServerRequest('GET', 'https://example.com/', array(), $body), function () {});

$deferred->reject();
$deferred->reject(new \RuntimeException());
}

public function testReceivesBufferedRequestSameInstance()
Expand Down Expand Up @@ -452,7 +452,7 @@ public function testReceivesStreamingBodyChangesInstanceWithCustomBodyButSameDat
$req = $request;
});

$deferred->reject();
$deferred->reject(new \RuntimeException());

$this->assertNotSame($request, $req);
$this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $req);
Expand Down

0 comments on commit 079da38

Please sign in to comment.