示例#1
0
 /**
  * Guard that already started workflow is the same which is tried to be ran now.
  *
  * @param Item     $item     Current workflow item.
  * @param Workflow $workflow Selected workflow.
  *
  * @throws WorkflowException If item workflow is not the same as current workflow.
  *
  * @return void
  */
 private function guardSameWorkflow(Item $item, Workflow $workflow)
 {
     if ($item->isWorkflowStarted() && $item->getWorkflowName() != $workflow->getName()) {
         $message = sprintf('Item "%s" already process workflow "%s" and cannot be handled by "%s"', $item->getEntityId(), $item->getWorkflowName(), $workflow->getName());
         throw new WorkflowException($message);
     }
 }
 function it_throws_than_matches_workflow_is_not_same_as_current(Workflow $workflow, Item $item, EntityId $entityId, Transition $transition, Step $step)
 {
     $step->getName()->willReturn('start');
     $step->isTransitionAllowed('next')->willReturn(true);
     $item->getEntityId()->willReturn($entityId);
     $item->getEntity()->willReturn(static::$entity);
     $item->isWorkflowStarted()->willReturn(true);
     $item->getCurrentStepName()->willReturn('start');
     $item->getWorkflowName()->willReturn('workflow_a');
     $workflow->match($entityId, static::$entity)->willReturn(true);
     $workflow->getStep('start')->willReturn($step);
     $workflow->getTransition('next')->willReturn($transition);
     $workflow->getName()->willReturn('workflow_b');
     $entityId->getProviderName()->willReturn(static::ENTITY_PROVIDER_NAME);
     $entityId->__toString()->willReturn(static::ENTITY_PROVIDER_NAME . '::' . static::ENTITY_ID);
     $this->shouldThrow('Netzmacht\\Workflow\\Flow\\Exception\\WorkflowException')->duringHandle($item, 'next');
 }