getMock('React\\Stub\CallableStub'); $mock ->expects($this->once()) ->method('__invoke') ->with($this->identicalTo($expected)); $promise->done($mock); } public function testPromiseRejectionsAreThrownIntoGenerator() { $deferred = new Deferred(); $deferred2 = new Deferred(); $gen = function () use ($deferred, $deferred2) { yield $deferred->promise(); $a = (yield 21); $b = 1; try { yield $deferred2->promise(); $this->fail('Code path should not be reached'); } catch (\Exception $e) { $this->assertSame('test', $e->getMessage()); $b = 2; } yield ($a * $b); }; $expected = 42; $promise = coroutine($gen()); $mock = $this->getMock('React\\Stub\CallableStub'); $mock ->expects($this->once()) ->method('__invoke') ->with($this->identicalTo($expected)); $promise->done($mock); $deferred2->reject(new \Exception('test')); $deferred->resolve(); } /** * @expectedException \Exception * @expectedExceptionMessage When in the chronicle of wasted time */ public function testUncaughtGeneratorExceptionRejectsPromise() { $gen = function () { yield; throw new \Exception('When in the chronicle of wasted time'); yield; }; $promise = coroutine($gen()); $promise->done(); } }