Example #1
0
 function let(Step $transitionStep, Transition $transition)
 {
     $transitionStep->getName()->willReturn(static::START_STEP);
     $transition->getName()->willReturn('start');
     $transition->setStepTo($transitionStep);
     $this->beConstructedWith(static::NAME, static::PROVIDER);
     $transition->setWorkflow($this)->shouldBeCalled();
     $this->addStep($transitionStep);
     $this->addTransition($transition, true);
 }
 /**
  * Create transitions from database.
  *
  * @param Workflow $workflow The current workflow.
  *
  * @throws DefinitionException If a target step is defined which does not exiss.
  *
  * @return void
  */
 private function createTransitions(Workflow $workflow)
 {
     $collection = TransitionModel::findByWorkflow($workflow->getConfigValue('id'));
     if (!$collection) {
         return;
     }
     while ($collection->next()) {
         /** @var TransitionModel $model */
         $model = $collection->current();
         $transition = new Transition($model->name, $model->label, array_merge($collection->row(), array(Definition::SOURCE => Definition::SOURCE_DATABASE)));
         if (!isset($this->steps[$model->stepTo])) {
             throw new DefinitionException(sprintf('Transition "%s" refers to step "%s" which does not exists.', $transition->getName(), $model->stepTo));
         }
         $transition->setStepTo($this->steps[$model->stepTo]);
         if ($model->limitPermission) {
             $transition->setPermission(Permission::fromString($model->permission));
         }
         $workflow->addTransition($transition);
         $event = new CreateTransitionEvent($transition);
         $this->getServiceContainer()->getEventDispatcher()->dispatch($event::NAME, $event);
         $this->transitions[$model->id] = $transition;
     }
 }