Skip to content

Commit 2294f9c

Browse files
committed
Forward compatibility with upcoming Promise v3
1 parent 092fbfe commit 2294f9c

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"php": ">=7.1",
1515
"nikic/fast-route": "^1.3",
1616
"react/async": "^4 || ^3",
17-
"react/http": "^1.7",
18-
"react/promise": "^2.7"
17+
"react/http": "^1.8@dev || ^1.7",
18+
"react/promise": "^3@dev || ^2.7"
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^9.5 || ^7.5",

src/ErrorHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ public function __invoke(ServerRequestInterface $request, callable $next)
4848
return $this->errorInvalidResponse($response);
4949
}
5050
}, function ($e) {
51+
// Promise rejected, always a `\Throwable` as of Promise v3
52+
assert($e instanceof \Throwable || !\method_exists(PromiseInterface::class, 'catch'));
53+
5154
if ($e instanceof \Throwable) {
5255
return $this->errorInvalidException($e);
5356
} else {
54-
return $this->errorInvalidResponse(\React\Promise\reject($e));
57+
return $this->errorInvalidResponse(\React\Promise\reject($e)); // @codeCoverageIgnore
5558
}
5659
});
5760
} elseif ($response instanceof \Generator) {

tests/AppTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,10 @@ public function testHandleRequestWithMatchingRouteReturnsPromiseWhichFulfillsWit
15341534

15351535
public function testHandleRequestWithMatchingRouteReturnsPromiseWhichFulfillsWithInternalServerErrorResponseWhenHandlerReturnsPromiseWhichRejectsWithNull()
15361536
{
1537+
if (method_exists(PromiseInterface::class, 'catch')) {
1538+
$this->markTestSkipped('Only supported for legacy Promise v2, Promise v3 already rejects with Throwable');
1539+
}
1540+
15371541
$app = $this->createAppWithoutLogger();
15381542

15391543
$app->get('/users', function () {

tests/ErrorHandlerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ public function testInvokeWithHandlerReturningPromiseResolvingWithNullReturnsPro
273273

274274
public function testInvokeWithHandlerReturningPromiseRejectingWithNullReturnsPromiseResolvingWithError500Response()
275275
{
276+
if (method_exists(PromiseInterface::class, 'catch')) {
277+
$this->markTestSkipped('Only supported for legacy Promise v2, Promise v3 already rejects with Throwable');
278+
}
279+
276280
$handler = new ErrorHandler();
277281

278282
$request = new ServerRequest('GET', 'http://example.com/');

0 commit comments

Comments
 (0)