Exemplo n.º 1
0
 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();
 }
Exemplo n.º 3
0
 /**
  * Log multiple changes.
  *
  * @param array   $values  Changes propertys as associated array['name' => 'val'].
  * @param Context $context Transition context.
  *
  * @return $this
  */
 protected function logMultipleChanges(array $values, Context $context)
 {
     if ($this->isLogChanges()) {
         $namespace = $this->getLogNamespace();
         foreach ($values as $name => $value) {
             $context->setProperty($name, $value, $namespace);
         }
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Get value for the property from the context.
  *
  * If value is given, it is used. If input is required then value from the context is extracted.
  *
  * @param Item    $item    The workflow item.
  * @param Context $context The transition contaext.
  *
  * @return mixed
  */
 private function getValueForProperty(Item $item, Context $context)
 {
     if ($this->value !== null) {
         return $this->value;
     } elseif ($this->isInputRequired($item)) {
         return $context->getParam($this->property);
     }
     return null;
 }
Exemplo n.º 5
0
 /**
  * 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());
 }
Exemplo n.º 6
0
 function it_catches_action_failed_exceptions_during_post_action_execution(Item $item, Context $context, ErrorCollection $errorCollection)
 {
     $this->addPostAction(new ThrowingAction());
     $errorCollection->addError(Argument::type('string'), Argument::type('array'))->shouldBeCalled();
     $context->getProperties()->willReturn(array());
     $this->executePostActions($item, $context, $errorCollection);
 }
Exemplo n.º 7
0
 function it_transits_to_next_state(Transition $transition, Context $context, ErrorCollection $errorCollection)
 {
     $context->getProperties()->willReturn(array());
     $errorCollection->getErrors()->willReturn(array());
     $this->transit($transition, $context, $errorCollection, false)->shouldBeAnInstanceOf('Netzmacht\\Workflow\\Flow\\State');
 }