/** * Run test scenario as simulation. * * @param callable(TestCase) $simulation * @return PromiseInterface */ public function simulate(callable $simulation) { $data = $simulation($this); $promise = new Promise(); $loop = $this->loop(); $loop->addTimer(15, function () use($loop) { $loop->stop(); $this->fail('Timeout for test has been reached.'); }); $loop->start(); return $promise->resolve($data); }
/** * @return PromiseInterface */ public function create() { $state = $this->getState(); if ($state !== Runtime::STATE_DESTROYED) { return Promise::doReject(new RejectionException("It is not possible to create runtime from state [{$state}].")); } $promise = new Promise(); $this->loop()->afterTick(function () use($promise) { $this->start()->then(function () use($promise) { return $promise->resolve('Runtime has been created.'); }); }); $this->setState(Runtime::STATE_CREATED); $emitter = $this->eventEmitter(); $emitter->emit('beforeCreate'); $emitter->emit('create'); $emitter->emit('afterCreate'); $this->setLoopState(self::LOOP_STATE_STARTED); $this->startLoop(); return $promise; }