function testAllRejectThenResolve() { $promise1 = new Promise(); $promise2 = new Promise(); $finalValue = 0; Promise::all([$promise1, $promise2])->then(function ($value) use(&$finalValue) { $finalValue = 'foo'; return 'test'; }, function ($value) use(&$finalValue) { $finalValue = $value; }); $promise1->reject(1); Loop\run(); $this->assertEquals(1, $finalValue); $promise2->fulfill(2); Loop\run(); $this->assertEquals(1, $finalValue); }
function testReject() { $finalValue = 0; $promise = reject(1); $promise->then(function ($value) use(&$finalValue) { $finalValue = 'im broken'; }, function ($reason) use(&$finalValue) { $finalValue = $reason; }); $this->assertEquals(0, $finalValue); Loop\run(); $this->assertEquals(1, $finalValue); }