예제 #1
0
파일: TestCase.php 프로젝트: khelle/surume
 /**
  * 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);
 }
예제 #2
0
 /**
  * @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;
 }