/** @test */ public function shouldReturnAPromiseForAPromisedRejectionValue() { $d = new Deferred(); $mock = $this->createCallableMock(); $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(1)); // Both the returned promise, and the deferred's own promise should // be rejected with the same value $d->resolver()->resolve(When::reject(1))->then($this->expectCallableNever(), $mock); }
/** @test */ public function shouldRejectARejectedPromise() { $expected = 123; $d = new Deferred(); $d->reject($expected); $mock = $this->createCallableMock(); $mock->expects($this->once())->method('__invoke')->with($this->identicalTo($expected)); When::reject($d->promise())->then($this->expectCallableNever(), $mock); }
/** @test */ public function shouldRejectIfAnyInputPromiseRejectsBeforeDesiredNumberOfInputsAreResolved() { $mock = $this->createCallableMock(); $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(array(1 => 2, 2 => 3))); When::some(array(When::resolve(1), When::reject(2), When::reject(3)), 2, $this->expectCallableNever(), $mock); }
/** @test */ public function shouldRejectWhenInputContainsRejection() { $mock = $this->createCallableMock(); $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(2)); When::reduce(array(When::resolve(1), When::reject(2), When::resolve(3)), $this->plus(), When::resolve(1))->then($this->expectCallableNever(), $mock); }
/** @test */ public function shouldResolveWhenFirstInputPromiseResolves() { $mock = $this->createCallableMock(); $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(1)); When::any(array(When::resolve(1), When::reject(2), When::reject(3)), $mock); }
/** @test */ public function shouldRejectIfAnyInputPromiseRejects() { $mock = $this->createCallableMock(); $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(2)); When::all(array(When::resolve(1), When::reject(2), When::resolve(3)), $this->expectCallableNever(), $mock); }