Skip to content

Commit a0b0158

Browse files
committed
Update to require Promise v3
1 parent cd7bb12 commit a0b0158

6 files changed

+4
-71
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"nikic/fast-route": "^1.3",
1616
"react/async": "^4 || ^3",
1717
"react/http": "^1.10",
18-
"react/promise": "^3 || ^2.10",
19-
"react/socket": "^1.13"
18+
"react/promise": "^3",
19+
"react/socket": "^1.14"
2020
},
2121
"require-dev": {
2222
"phpstan/phpstan": "1.10.47 || 1.4.10",

phpstan.neon.dist

-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,3 @@ parameters:
66
- tests/
77

88
reportUnmatchedIgnoredErrors: false
9-
ignoreErrors:
10-
# ignore generic usage like `PromiseInterface<ResponseInterface>` until fixed upstream
11-
- '/^PHPDoc tag @return contains generic type React\\Promise\\PromiseInterface<Psr\\Http\\Message\\ResponseInterface> but interface React\\Promise\\PromiseInterface is not generic\.$/'

src/ErrorHandler.php

+2-10
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,8 @@ public function __invoke(ServerRequestInterface $request, callable $next)
4747
} else {
4848
return $this->errorInvalidResponse($response);
4949
}
50-
}, function ($e) {
51-
// Promise rejected, always a `\Throwable` as of Promise v3
52-
assert($e instanceof \Throwable || !\method_exists(PromiseInterface::class, 'catch')); // @phpstan-ignore-line
53-
54-
if ($e instanceof \Throwable) {
55-
return $this->errorInvalidException($e);
56-
} else { // @phpstan-ignore-line
57-
// @phpstan-ignore-next-line
58-
return $this->errorInvalidResponse(\React\Promise\reject($e)); // @codeCoverageIgnore
59-
}
50+
}, function (\Throwable $e) {
51+
return $this->errorInvalidException($e);
6052
});
6153
} elseif ($response instanceof \Generator) {
6254
return $this->coroutine($response);

tests/AppTest.php

-26
Original file line numberDiff line numberDiff line change
@@ -1272,32 +1272,6 @@ public function testInvokeWithMatchingRouteReturnsInternalServerErrorResponseWhe
12721272
$this->assertStringContainsString("<p>Expected request handler to return <code>Psr\Http\Message\ResponseInterface</code> but got uncaught <code>RuntimeException</code> with message <code>Foo</code> in <code title=\"See " . __FILE__ . " line $line\">AppTest.php:$line</code>.</p>\n", (string) $response->getBody());
12731273
}
12741274

1275-
public function testInvokeWithMatchingRouteReturnsInternalServerErrorResponseWhenHandlerReturnsPromiseWhichRejectsWithNull(): void
1276-
{
1277-
if (method_exists(PromiseInterface::class, 'catch')) {
1278-
$this->markTestSkipped('Only supported for legacy Promise v2, Promise v3 always rejects with Throwable');
1279-
}
1280-
1281-
$app = $this->createAppWithoutLogger();
1282-
1283-
$app->get('/users', function () {
1284-
return reject(null); // @phpstan-ignore-line
1285-
});
1286-
1287-
$request = new ServerRequest('GET', 'http://localhost/users');
1288-
1289-
$response = $app($request);
1290-
assert($response instanceof ResponseInterface);
1291-
1292-
$this->assertEquals(500, $response->getStatusCode());
1293-
$this->assertEquals('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
1294-
$this->assertStringMatchesFormat("<!DOCTYPE html>\n<html>%a</html>\n", (string) $response->getBody());
1295-
1296-
$this->assertStringContainsString("<title>Error 500: Internal Server Error</title>\n", (string) $response->getBody());
1297-
$this->assertStringContainsString("<p>The requested page failed to load, please try again later.</p>\n", (string) $response->getBody());
1298-
$this->assertStringContainsString("<p>Expected request handler to return <code>Psr\Http\Message\ResponseInterface</code> but got <code>React\Promise\RejectedPromise</code>.</p>\n", (string) $response->getBody());
1299-
}
1300-
13011275
public function testInvokeWithMatchingRouteReturnsInternalServerErrorResponseWhenHandlerReturnsCoroutineWhichYieldsRejectedPromise(): void
13021276
{
13031277
$app = $this->createAppWithoutLogger();

tests/ErrorHandlerTest.php

-27
Original file line numberDiff line numberDiff line change
@@ -271,33 +271,6 @@ public function testInvokeWithHandlerReturningPromiseResolvingWithNullReturnsPro
271271
$this->assertEquals(500, $response->getStatusCode());
272272
}
273273

274-
public function testInvokeWithHandlerReturningPromiseRejectingWithNullReturnsPromiseResolvingWithError500Response(): void
275-
{
276-
if (method_exists(PromiseInterface::class, 'catch')) {
277-
$this->markTestSkipped('Only supported for legacy Promise v2, Promise v3 always rejects with Throwable');
278-
}
279-
280-
$handler = new ErrorHandler();
281-
282-
$request = new ServerRequest('GET', 'http://example.com/');
283-
284-
$promise = $handler($request, function () {
285-
return reject(null); // @phpstan-ignore-line
286-
});
287-
288-
/** @var PromiseInterface<ResponseInterface> $promise */
289-
$this->assertInstanceOf(PromiseInterface::class, $promise);
290-
291-
$response = null;
292-
$promise->then(function ($value) use (&$response) {
293-
$response = $value;
294-
});
295-
296-
/** @var ResponseInterface $response */
297-
$this->assertInstanceOf(ResponseInterface::class, $response);
298-
$this->assertEquals(500, $response->getStatusCode());
299-
}
300-
301274
public function testInvokeWithHandlerReturningGeneratorYieldingNullReturnsGeneratorYieldingError500Response(): void
302275
{
303276
$handler = new ErrorHandler();

tests/Io/ReactiveHandlerTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ public function testRunWillListenForHttpRequestAndSendBackHttpResponseOverSocket
160160
$connector = new Connector();
161161
$promise = $connector->connect($addr);
162162

163-
/** @var \React\Promise\PromiseInterface<ConnectionInterface> $promise */
164163
$promise->then(function (ConnectionInterface $connection): void {
165164
$connection->on('data', function (string $data): void {
166165
$this->assertEquals("HTTP/1.0 200 OK\r\nContent-Length: 3\r\n\r\nOK\n", $data);
@@ -217,7 +216,6 @@ public function testRunWillOnlyRestartLoopAfterAwaitingWhenFibersAreNotAvailable
217216
$logger->expects($this->never())->method('log');
218217
}
219218

220-
/** @var \React\Promise\PromiseInterface<ConnectionInterface> $promise */
221219
$promise->then(function (ConnectionInterface $connection): void {
222220
$connection->on('data', function (string $data): void {
223221
$this->assertEquals("HTTP/1.0 200 OK\r\nContent-Length: 3\r\n\r\nOK\n", $data);
@@ -279,7 +277,6 @@ public function testRunWillReportHttpErrorForInvalidClientRequest(): void
279277
$connector = new Connector();
280278
$promise = $connector->connect($addr);
281279

282-
/** @var \React\Promise\PromiseInterface<ConnectionInterface> $promise */
283280
$promise->then(function (ConnectionInterface $connection) use ($logger): void {
284281
$logger->expects($this->once())->method('log')->with($this->matchesRegularExpression('/^HTTP error: .*$/'));
285282
$connection->write("not a valid HTTP request\r\n\r\n");

0 commit comments

Comments
 (0)