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(); }
/** * 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()); }