function it_starts_a_new_workflow_state(EntityId $entityId, State $state, EntityId $entityId, Transition $transition, Workflow $workflow, Step $step, Context $context, ErrorCollection $errorCollection) { $transition->getWorkflow()->willReturn($workflow); $transition->getName()->willReturn('transition_name'); $transition->getStepTo()->willReturn($step); $context->getProperties()->willReturn(array()); $errorCollection->toArray()->willReturn(array()); $this->beConstructedThrough('initialize', array($entityId, static::$entity)); $this->start($transition, $context, $errorCollection, true)->shouldHaveType('Netzmacht\\Workflow\\Flow\\State'); }
/** * Prepare data for the notification. * * @param Transition $transition Current transition. * @param Item $item Workflow item. * @param Context $context Transition context. * * @return array */ private function prepareData(Transition $transition, Item $item, Context $context) { $entity = $this->getEntity($item); $step = $transition->getStepTo(); $tokens = array(); $tokens['entity'] = $entity->getPropertiesAsArray(); $tokens['context'] = $context->getProperties(); $tokens['entityId'] = (string) $item->getEntityId(); $tokens['transition'] = $transition->getConfig(); $tokens['transition']['name'] = $transition->getName(); $tokens['transition']['label'] = $transition->getLabel(); $tokens['step'] = $step->getConfig(); $tokens['step']['name'] = $step->getName(); $tokens['step']['label'] = $step->getLabel(); $event = new PrepareNotificationTokensEvent(new \ArrayObject($tokens), $transition, $item); $this->eventDispatcher->dispatch($event::NAME, $event); return $event->getTokens()->getArrayCopy(); }
/** * 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; } }
function it_checks_if_transition_is_available(Form $form, Transition $transition, Item $item) { $transition->getName()->willReturn(static::TRANSITION_NAME); $transition->isAvailable($item, Argument::type(self::CONTEXT_CLASS), Argument::type(self::ERROR_COLLECTION_CLASS))->willReturn(true); $this->isAvailable()->shouldReturn(true); }
/** * Transit to a new state. * * @param Transition $transition The transition being performed. * @param Context $context The transition context. * @param ErrorCollection $errorCollection The error collection. * @param bool $success The success state. * * @return State */ public function transit(Transition $transition, Context $context, ErrorCollection $errorCollection, $success = true) { $dateTime = new DateTime(); $stepName = $success ? $transition->getStepTo()->getName() : $this->stepName; return new static($this->entityId, $this->workflowName, $transition->getName(), $stepName, $success, $context->getProperties(), $dateTime, $errorCollection->getErrors()); }
function it_knows_if_transition_is_available_for_an_item(Item $item, Step $step, Context $context, Transition $transition, ErrorCollection $errorCollection) { $item->isWorkflowStarted()->willReturn(true); $item->getCurrentStepName()->willReturn('started'); $transition->getName()->willReturn('next'); $transition->isAvailable($item, $context, $errorCollection)->shouldBeCalled()->willReturn(true); $this->addTransition($transition); $step->getName()->willReturn('started'); $step->isTransitionAllowed('next')->willReturn(true); $this->addStep($step); $this->isTransitionAvailable($item, $context, $errorCollection, 'next')->shouldReturn(true); }