/** * */ public function testCasePromise_RejectsPromise_IfResolverThrowsException() { $exception = new Exception('foo'); $promise = new Promise(function () use($exception) { throw $exception; }); $mock = $this->createCallableMock(); $mock->expects($this->once())->method('__invoke')->with($this->identicalTo($exception)); $promise->then($this->expectCallableNever(), $mock); }
/** * @override * @inheritDoc */ public function destroy() { $state = $this->getState(); if ($state === Runtime::STATE_DESTROYED) { return Promise::doResolve('Runtime has been already destroyed.'); } $controller = $this; return $controller->stop()->then(function () { return Promise::doResolve()->then(function () { return $this->getRuntimeManager()->getRuntimes(); })->then(function ($runtimes) { return $this->getRuntimeManager()->destroyRuntimes($runtimes, Runtime::DESTROY_FORCE); }); })->then(function () use($controller) { $promise = new Promise(); $emitter = $controller->getEventEmitter(); $emitter->emit('beforeDestroy'); $emitter->emit('destroy'); $controller->getLoop()->onTick(function () use($controller, $promise) { $controller->setState(Runtime::STATE_DESTROYED); $controller->setLoopState(self::LOOP_STATE_STOPPED); $controller->stopLoop(); $emitter = $controller->getEventEmitter(); $emitter->emit('afterDestroy'); $promise->resolve(); }); return $promise->then(function () { return 'Runtime has been destroyed.'; }); }); }
/** * */ public function testApiRetryOrReset_RejectsPromiseInRetry_WhenRetriesLimitIsReached() { $req = $this->createRequest($name = 'name', $mssg = 'secret', ['retriesLimit' => 0]); $ex = new Exception(); $promise = new Promise(); $callable = $this->createCallableMock(); $callable->expects($this->once())->method('__invoke')->with($this->isInstanceOf(TimeoutException::class)); $promise->then(null, $callable); $this->callProtectedMethod($req, 'retryOrReset', [$promise, $ex]); }