Skip to content
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require": {
"php": ">=5.3",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5",
"react/promise": "^2.7 || ^1.2.1",
"react/promise": "^3.0 || ^2.7 || ^1.2.1",
"react/promise-timer": "^1.5"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function awaitAll(array $promises, LoopInterface $loop, $timeout = null)
function _cancelAllPromises(array $promises)
{
foreach ($promises as $promise) {
if ($promise instanceof CancellablePromiseInterface) {
if ($promise instanceof CancellablePromiseInterface || (! \interface_exists('React\\Promise\\CancellablePromiseInterface') && \method_exists($promise, 'cancel'))) {
$promise->cancel();
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/FunctionAwaitAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function testAwaitAllRejected()

public function testAwaitAllRejectedWithFalseWillWrapInUnexpectedValueException()
{
$this->skipForPromise3('Promises must reject with an exception, so this case cannot happen.');

$all = array(
$this->createPromiseResolved(1),
Promise\reject(false)
Expand Down
8 changes: 4 additions & 4 deletions tests/FunctionAwaitAnyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testAwaitAnyEmpty()
public function testAwaitAnyFirstResolved()
{
$all = array(
$this->createPromiseRejected(1),
$this->createPromiseRejected(new \Exception('1')),
$this->createPromiseResolved(2, 0.01),
$this->createPromiseResolved(3, 0.02)
);
Expand All @@ -33,7 +33,7 @@ public function testAwaitAnyFirstResolvedConcurrently()
$d3 = new Deferred();

$this->loop->addTimer(0.01, function() use ($d1, $d2, $d3) {
$d1->reject(1);
$d1->reject(new \Exception('1'));
$d2->resolve(2);
$d3->resolve(3);
});
Expand All @@ -50,8 +50,8 @@ public function testAwaitAnyFirstResolvedConcurrently()
public function testAwaitAnyAllRejected()
{
$all = array(
$this->createPromiseRejected(1),
$this->createPromiseRejected(2)
$this->createPromiseRejected(new \Exception('1')),
$this->createPromiseRejected(new \Exception('2'))
);

$this->setExpectedException('UnderflowException');
Expand Down
3 changes: 3 additions & 0 deletions tests/FunctionAwaitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function testAwaitOneRejected()

public function testAwaitOneRejectedWithFalseWillWrapInUnexpectedValueException()
{
$this->skipForPromise3('Promises must reject with an exception, so this case cannot happen.');
$promise = Promise\reject(false);

$this->setExpectedException('UnexpectedValueException', 'Promise rejected with unexpected value of type bool');
Expand All @@ -26,6 +27,7 @@ public function testAwaitOneRejectedWithFalseWillWrapInUnexpectedValueException(

public function testAwaitOneRejectedWithNullWillWrapInUnexpectedValueException()
{
$this->skipForPromise3('Promises must reject with an exception, so this case cannot happen.');
$promise = Promise\reject(null);

$this->setExpectedException('UnexpectedValueException', 'Promise rejected with unexpected value of type NULL');
Expand Down Expand Up @@ -153,6 +155,7 @@ public function testAwaitOneRejectedWithTimeoutShouldNotCreateAnyGarbageReferenc

public function testAwaitNullValueShouldNotCreateAnyGarbageReferences()
{
$this->skipForPromise3('Promises must reject with an exception, so this case cannot happen.');
if (class_exists('React\Promise\When') && PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Not supported on legacy Promise v1 API with PHP 5.4+');
}
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ public function setUpLoop()
$this->loop = \React\EventLoop\Factory::create();
}

/**
* Skips a test if the test suite is running with react/promise version
* 3.0 or later.
*
* @param string $reason
*
* @return void
*/
protected function skipForPromise3($reason)
{
if (! interface_exists('React\Promise\CancellablePromiseInterface')) {
$this->markTestSkipped('Test is not supported/required by the Promise v3 API: '.$reason);
}
}

protected function createPromiseResolved($value = null, $delay = 0.01)
{
$deferred = new Deferred();
Expand Down