/** * {@inheritdoc} */ public function match(Workflow $workflow, EntityId $entityId, $entity) { if ($this->providerName) { return $entityId->getProviderName() == $this->providerName; } return $entityId->getProviderName() == $workflow->getProviderName(); }
function let(Item $item, Workflow $workflow, StateRepository $stateRepository, EntityRepository $entityRepository, TransactionHandler $transactionHandler, SymfonyEventDispatcher $eventDispatcher, Transition $transition, State $state, EntityId $entityId, Step $step) { $workflow->getStep(static::STEP_NAME)->willReturn($step); $workflow->getStartTransition()->willReturn($transition); $workflow->getName()->willReturn(static::WORKFLOW_NAME); $step->isTransitionAllowed(static::TRANSITION_NAME)->willReturn(true); $workflow->getTransition(static::TRANSITION_NAME)->willReturn($transition); $transition->getName()->willReturn(static::TRANSITION_NAME); $transition->isInputRequired($item)->willReturn(false); $item->transit($transition, Argument::type(static::CONTEXT_CLASS), Argument::type(static::ERROR_COLLECTION_CLASS), true)->willReturn($state); $item->isWorkflowStarted()->willReturn(true); $item->getCurrentStepName()->willReturn(static::STEP_NAME); $item->getEntity()->willReturn(static::$entity); $entityId->__toString()->willReturn('entity::2'); $this->beConstructedWith($eventDispatcher); }
/** * Guard that requested transition is allowed. * * @param string $transitionName Transition to be processed. * * @throws WorkflowException If Transition is not allowed. * * @return void */ private function guardAllowedTransition($transitionName) { if (!$this->isWorkflowStarted()) { if (!$transitionName || $transitionName === $this->getWorkflow()->getStartTransition()->getName()) { return; } throw new WorkflowException(sprintf('Not allowed to process transition "%s". Workflow "%s" not started for item "%s"', $transitionName, $this->workflow->getName(), $this->item->getEntityId())); } $step = $this->getCurrentStep(); if (!$step->isTransitionAllowed($transitionName)) { throw new WorkflowException(sprintf('Not allowed to process transition "%s". Transition is not allowed in step "%s"', $transitionName, $step->getName())); } }
/** * 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); } }
/** * Create Workflow process. * * @param Workflow $workflow The current workflow. * * @return void */ private function createProcess(Workflow $workflow) { $process = deserialize($workflow->getConfigValue('process'), true); foreach ($process as $definition) { // pass not created transitions. useful to avoid errors when a transition got disabled if (!isset($this->transitions[$definition['transition']])) { continue; } if ($definition['step'] == 'start') { $workflow->setStartTransition($this->transitions[$definition['transition']]->getName()); } else { $step = $this->steps[$definition['step']]; $transition = $this->transitions[$definition['transition']]; $step->allowTransition($transition->getName()); } } }
function it_matches_against_workflow_provider_name(Workflow $workflow, EntityId $entityId) { $workflow->getProviderName()->willReturn('test'); $entityId->getProviderName()->willReturn('test'); $this->match($workflow, $entityId, static::$entity)->shouldReturn(true); }
function it_throws_during_transits_if_not_validated(Workflow $workflow, Transition $transition) { $workflow->getStartTransition()->willReturn($transition); $this->shouldThrow('Netzmacht\\Workflow\\Flow\\Exception\\WorkflowException')->duringTransit(); }
function let(Workflow $workflow) { $workflow->getName()->willReturn('workflow'); $this->beConstructedThrough('forWorkflow', array($workflow, 'perm')); }
/** * Create a permission for a workflow. * * @param Workflow $workflow Workflow to which the permission belongs to. * @param string $permissionId The permission id. * * @return static */ public static function forWorkflow(Workflow $workflow, $permissionId) { return static::forWorkflowName($workflow->getName(), $permissionId); }
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'); }