Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward compatibility with upcoming Promise v3 #188

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"php": ">=7.1",
"nikic/fast-route": "^1.3",
"react/async": "^4 || ^3",
"react/http": "^1.7",
"react/promise": "^2.7"
"react/http": "^1.8",
"react/promise": "^3 || ^2.7"
},
"require-dev": {
"phpunit/phpunit": "^9.5 || ^7.5",
Expand Down
5 changes: 4 additions & 1 deletion src/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ public function __invoke(ServerRequestInterface $request, callable $next)
return $this->errorInvalidResponse($response);
}
}, function ($e) {
// Promise rejected, always a `\Throwable` as of Promise v3
assert($e instanceof \Throwable || !\method_exists(PromiseInterface::class, 'catch'));

if ($e instanceof \Throwable) {
return $this->errorInvalidException($e);
} else {
return $this->errorInvalidResponse(\React\Promise\reject($e));
return $this->errorInvalidResponse(\React\Promise\reject($e)); // @codeCoverageIgnore
}
});
} elseif ($response instanceof \Generator) {
Expand Down
4 changes: 4 additions & 0 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,10 @@ public function testHandleRequestWithMatchingRouteReturnsPromiseWhichFulfillsWit

public function testHandleRequestWithMatchingRouteReturnsPromiseWhichFulfillsWithInternalServerErrorResponseWhenHandlerReturnsPromiseWhichRejectsWithNull()
{
if (method_exists(PromiseInterface::class, 'catch')) {
$this->markTestSkipped('Only supported for legacy Promise v2, Promise v3 always rejects with Throwable');
}

$app = $this->createAppWithoutLogger();

$app->get('/users', function () {
Expand Down
4 changes: 4 additions & 0 deletions tests/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ public function testInvokeWithHandlerReturningPromiseResolvingWithNullReturnsPro

public function testInvokeWithHandlerReturningPromiseRejectingWithNullReturnsPromiseResolvingWithError500Response()
{
if (method_exists(PromiseInterface::class, 'catch')) {
$this->markTestSkipped('Only supported for legacy Promise v2, Promise v3 always rejects with Throwable');
}

$handler = new ErrorHandler();

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