public function testApiDone_ThrowsException_WithDeepNestingPromiseChains()
{
$test = $this->getTest();
$test->setExpectedException(Exception::class, 'UnhandledRejectionException');
$exception = new Exception('UnhandledRejectionException');
$d = new Deferred();
$result = Promise::doResolve(Promise::doResolve($d->getPromise()->then(function () use($exception) {
$d = new Deferred();
$d->resolve();
return Promise::doResolve($d->getPromise()->then(function () {
}))->then(function () use($exception) {
throw $exception;
});
})));
$result->done();
$d->resolve();
}