Skip to content

Commit ba35f85

Browse files
davidcole1340SimonFrings
authored andcommitted
Added support for react/promise v3
1 parent 4c6a2ea commit ba35f85

5 files changed

Lines changed: 22 additions & 6 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"require": {
2020
"php": ">=5.3",
2121
"react/event-loop": "^1.2",
22-
"react/promise": "^2.7 || ^1.2.1",
22+
"react/promise": "^3.0 || ^2.7 || ^1.2.1",
2323
"react/promise-timer": "^1.5"
2424
},
2525
"require-dev": {

src/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ function awaitAll(array $promises, LoopInterface $loop = null, $timeout = null)
322322
function _cancelAllPromises(array $promises)
323323
{
324324
foreach ($promises as $promise) {
325-
if ($promise instanceof CancellablePromiseInterface) {
325+
if ($promise instanceof CancellablePromiseInterface || (! \interface_exists('React\Promise\CancellablePromiseInterface') && \method_exists($promise, 'cancel'))) {
326326
$promise->cancel();
327327
}
328328
}

tests/FunctionAwaitAllTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function testAwaitAllRejected()
4343

4444
public function testAwaitAllRejectedWithFalseWillWrapInUnexpectedValueException()
4545
{
46+
if (!interface_exists('React\Promise\CancellablePromiseInterface')) {
47+
$this->markTestSkipped('Promises must be rejected with a \Throwable instance since Promise v3');
48+
}
49+
4650
$all = array(
4751
$this->createPromiseResolved(1),
4852
Promise\reject(false)

tests/FunctionAwaitAnyTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testAwaitAnyEmpty()
1818
public function testAwaitAnyFirstResolved()
1919
{
2020
$all = array(
21-
$this->createPromiseRejected(1),
21+
$this->createPromiseRejected(new \Exception('1')),
2222
$this->createPromiseResolved(2, 0.01),
2323
$this->createPromiseResolved(3, 0.02)
2424
);
@@ -40,7 +40,7 @@ public function testAwaitAnyFirstResolvedConcurrently()
4040
$d3 = new Deferred();
4141

4242
$this->loop->addTimer(0.01, function() use ($d1, $d2, $d3) {
43-
$d1->reject(1);
43+
$d1->reject(new \Exception('1'));
4444
$d2->resolve(2);
4545
$d3->resolve(3);
4646
});
@@ -57,8 +57,8 @@ public function testAwaitAnyFirstResolvedConcurrently()
5757
public function testAwaitAnyAllRejected()
5858
{
5959
$all = array(
60-
$this->createPromiseRejected(1),
61-
$this->createPromiseRejected(2)
60+
$this->createPromiseRejected(new \Exception('1')),
61+
$this->createPromiseRejected(new \Exception('2'))
6262
);
6363

6464
$this->setExpectedException('UnderflowException');

tests/FunctionAwaitTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public function testAwaitOneRejected()
1818

1919
public function testAwaitOneRejectedWithFalseWillWrapInUnexpectedValueException()
2020
{
21+
if (!interface_exists('React\Promise\CancellablePromiseInterface')) {
22+
$this->markTestSkipped('Promises must be rejected with a \Throwable instance since Promise v3');
23+
}
24+
2125
$promise = Promise\reject(false);
2226

2327
$this->setExpectedException('UnexpectedValueException', 'Promise rejected with unexpected value of type bool');
@@ -26,6 +30,10 @@ public function testAwaitOneRejectedWithFalseWillWrapInUnexpectedValueException(
2630

2731
public function testAwaitOneRejectedWithNullWillWrapInUnexpectedValueException()
2832
{
33+
if (!interface_exists('React\Promise\CancellablePromiseInterface')) {
34+
$this->markTestSkipped('Promises must be rejected with a \Throwable instance since Promise v3');
35+
}
36+
2937
$promise = Promise\reject(null);
3038

3139
$this->setExpectedException('UnexpectedValueException', 'Promise rejected with unexpected value of type NULL');
@@ -162,6 +170,10 @@ public function testAwaitOneRejectedWithTimeoutShouldNotCreateAnyGarbageReferenc
162170

163171
public function testAwaitNullValueShouldNotCreateAnyGarbageReferences()
164172
{
173+
if (!interface_exists('React\Promise\CancellablePromiseInterface')) {
174+
$this->markTestSkipped('Promises must be rejected with a \Throwable instance since Promise v3');
175+
}
176+
165177
if (class_exists('React\Promise\When') && PHP_VERSION_ID >= 50400) {
166178
$this->markTestSkipped('Not supported on legacy Promise v1 API with PHP 5.4+');
167179
}

0 commit comments

Comments
 (0)