/** * 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())); } }
function let(Item $item, EntityId $entityId, Workflow $workflow, EntityRepository $entityRepository, StateRepository $stateRepository, TransactionHandler $transactionHandler, Step $step, Transition $transition, State $state, Listener $listener) { $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))->willReturn($state); $item->isWorkflowStarted()->willReturn(true); $item->getCurrentStepName()->willReturn(static::STEP_NAME); $item->getEntity()->willReturn(static::$entity); $entityId->__toString()->willReturn('entity::2'); $this->beConstructedWith($item, $workflow, static::TRANSITION_NAME, $entityRepository, $stateRepository, $transactionHandler, $listener); }
/** * 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); } }
/** * Add permission roles to the workflow. * * @param Workflow $workflow The workflow being created. * * @return void */ private function addRoles(Workflow $workflow) { /** @var User $user */ $user = $this->getServiceContainer()->getService('workflow.security.user'); foreach ($user->getRoles() as $role) { if ($role->getWorkflowName() == $workflow->getName()) { $workflow->addRole($role); } } }
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'); }