Skip to content

Commit 78cfb44

Browse files
committed
Forward compatibility with upcoming Promise v3
1 parent 4a1e853 commit 78cfb44

File tree

8 files changed

+45
-20
lines changed

8 files changed

+45
-20
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
with:
3030
php-version: ${{ matrix.php }}
3131
coverage: xdebug
32+
env:
33+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3234
- run: composer install
3335
- run: vendor/bin/phpunit --coverage-text
3436
if: ${{ matrix.php >= 7.3 }}
@@ -39,6 +41,7 @@ jobs:
3941
name: PHPUnit (HHVM)
4042
runs-on: ubuntu-18.04
4143
continue-on-error: true
44+
if: false # temporarily skipped until https://github.com/azjezz/setup-hhvm/issues/3 is addressed
4245
steps:
4346
- uses: actions/checkout@v2
4447
- uses: azjezz/setup-hhvm@v1

composer.json

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131
"fig/http-message-util": "^1.1",
3232
"psr/http-message": "^1.0",
3333
"react/event-loop": "^1.2",
34-
"react/promise": "^2.3 || ^1.2.1",
35-
"react/promise-stream": "^1.1",
36-
"react/socket": "^1.9",
34+
"react/promise": "^3@dev || ^2.3 || ^1.2.1",
35+
"react/promise-stream": "^1.4",
36+
"react/socket": "^1.12",
3737
"react/stream": "^1.2",
3838
"ringcentral/psr7": "^1.2"
3939
},
4040
"require-dev": {
41-
"clue/http-proxy-react": "^1.7",
42-
"clue/reactphp-ssh-proxy": "^1.3",
43-
"clue/socks-react": "^1.3",
41+
"clue/http-proxy-react": "dev-promise-v3 as 1.8.0",
42+
"clue/reactphp-ssh-proxy": "dev-promise-v3 as 1.4.0",
43+
"clue/socks-react": "dev-promise-v3 as 1.4.0",
4444
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
4545
"react/async": "^4 || ^3 || ^2",
4646
"react/promise-timer": "^1.9"
@@ -50,5 +50,19 @@
5050
},
5151
"autoload-dev": {
5252
"psr-4": { "React\\Tests\\Http\\": "tests" }
53-
}
53+
},
54+
"repositories": [
55+
{
56+
"type": "vcs",
57+
"url": "https://github.com/clue-labs/reactphp-http-proxy"
58+
},
59+
{
60+
"type": "vcs",
61+
"url": "https://github.com/clue-labs/reactphp-socks"
62+
},
63+
{
64+
"type": "vcs",
65+
"url": "https://github.com/clue-labs/reactphp-ssh-proxy"
66+
}
67+
]
5468
}

src/Io/StreamingServer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use React\Http\Message\Response;
1010
use React\Http\Message\ServerRequest;
1111
use React\Promise;
12-
use React\Promise\CancellablePromiseInterface;
1312
use React\Promise\PromiseInterface;
1413
use React\Socket\ConnectionInterface;
1514
use React\Socket\ServerInterface;
@@ -158,7 +157,7 @@ public function handleRequest(ConnectionInterface $conn, ServerRequestInterface
158157
}
159158

160159
// cancel pending promise once connection closes
161-
if ($response instanceof CancellablePromiseInterface) {
160+
if ($response instanceof PromiseInterface && \method_exists($response, 'cancel')) {
162161
$conn->on('close', function () use ($response) {
163162
$response->cancel();
164163
});

src/Middleware/LimitConcurrentRequestsMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,6 @@ public function processQueue()
206206
$first = \reset($this->queue);
207207
unset($this->queue[key($this->queue)]);
208208

209-
$first->resolve();
209+
$first->resolve(null);
210210
}
211211
}

tests/FunctionalHttpServerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,10 @@ public function testConnectWithClosedThroughStreamReturnsNoData()
726726

727727
public function testLimitConcurrentRequestsMiddlewareRequestStreamPausing()
728728
{
729+
if (defined('HHVM_VERSION') && !interface_exists('React\Promise\PromisorInterface')) {
730+
$this->markTestSkipped('Not supported on legacy HHVM with Promise v3');
731+
}
732+
729733
$connector = new Connector();
730734

731735
$http = new HttpServer(

tests/Io/MiddlewareRunnerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use React\Http\Io\MiddlewareRunner;
99
use React\Http\Message\ServerRequest;
1010
use React\Promise;
11-
use React\Promise\CancellablePromiseInterface;
1211
use React\Promise\PromiseInterface;
1312
use React\Tests\Http\Middleware\ProcessStack;
1413
use React\Tests\Http\TestCase;
@@ -479,7 +478,7 @@ function (RequestInterface $request) use ($once) {
479478

480479
$promise = $middleware($request);
481480

482-
$this->assertTrue($promise instanceof CancellablePromiseInterface);
481+
$this->assertTrue($promise instanceof PromiseInterface && \method_exists($promise, 'cancel'));
483482
$promise->cancel();
484483
}
485484
}

tests/Io/TransactionTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,14 @@ public function testCancelBufferingResponseWillCloseStreamAndReject()
436436
$response = new Response(200, array(), new ReadableBodyStream($stream));
437437

438438
// mock sender to resolve promise with the given $response in response to the given $request
439+
$deferred = new Deferred();
439440
$sender = $this->makeSenderMock();
440-
$sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(Promise\resolve($response));
441+
$sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn($deferred->promise());
441442

442443
$transaction = new Transaction($sender, Loop::get());
443444
$promise = $transaction->send($request);
445+
446+
$deferred->resolve($response);
444447
$promise->cancel();
445448

446449
$this->setExpectedException('RuntimeException');
@@ -778,13 +781,16 @@ public function testCancelTransactionWillCloseBufferingStream()
778781
$body = new ThroughStream();
779782
$body->on('close', $this->expectCallableOnce());
780783

781-
// mock sender to resolve promise with the given $redirectResponse in
782-
$redirectResponse = new Response(301, array('Location' => 'http://example.com/new'), new ReadableBodyStream($body));
783-
$sender->expects($this->once())->method('send')->willReturn(Promise\resolve($redirectResponse));
784+
// mock sender to resolve promise with the given $redirectResponse
785+
$deferred = new Deferred();
786+
$sender->expects($this->once())->method('send')->willReturn($deferred->promise());
784787

785788
$transaction = new Transaction($sender, $loop);
786789
$promise = $transaction->send($request);
787790

791+
$redirectResponse = new Response(301, array('Location' => 'http://example.com/new'), new ReadableBodyStream($body));
792+
$deferred->resolve($redirectResponse);
793+
788794
$promise->cancel();
789795
}
790796

tests/Middleware/LimitConcurrentRequestsMiddlewareTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function testLimitOneRequestConcurrently()
7979
/**
8080
* Ensure resolve frees up a slot
8181
*/
82-
$deferredA->resolve();
82+
$deferredA->resolve(null);
8383

8484
$this->assertTrue($calledA);
8585
$this->assertTrue($calledB);
@@ -88,7 +88,7 @@ public function testLimitOneRequestConcurrently()
8888
/**
8989
* Ensure reject also frees up a slot
9090
*/
91-
$deferredB->reject();
91+
$deferredB->reject(new \RuntimeException());
9292

9393
$this->assertTrue($calledA);
9494
$this->assertTrue($calledB);
@@ -194,7 +194,7 @@ public function testStreamDoesPauseAndThenResumeWhenDequeued()
194194

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

197-
$deferred->reject();
197+
$deferred->reject(new \RuntimeException());
198198
}
199199

200200
public function testReceivesBufferedRequestSameInstance()
@@ -452,7 +452,7 @@ public function testReceivesStreamingBodyChangesInstanceWithCustomBodyButSameDat
452452
$req = $request;
453453
});
454454

455-
$deferred->reject();
455+
$deferred->reject(new \RuntimeException());
456456

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

0 commit comments

Comments
 (0)