/** * Checks whether transition is valid in context of workflow item state. * * Transition is considered invalid when workflow item is new and transition is not "start". * Also transition is considered invalid when current step doesn't contain such allowed transition. * * @param Transition $transition * @param WorkflowItem $workflowItem * @param bool $fireExceptions * @return bool * @throws InvalidTransitionException */ protected function checkTransitionValid(Transition $transition, WorkflowItem $workflowItem, $fireExceptions) { // get current step $currentStep = null; if ($workflowItem->getCurrentStep() && ($currentStepName = $workflowItem->getCurrentStep()->getName())) { $currentStep = $this->stepManager->getStep($currentStepName); } // if there is no current step - consider transition as a start transition if (!$currentStep) { if (!$transition->isStart()) { if ($fireExceptions) { throw InvalidTransitionException::notStartTransition($workflowItem->getWorkflowName(), $transition->getName()); } return false; } } elseif (!$currentStep->isAllowedTransition($transition->getName())) { // if transition is not allowed for current step if ($fireExceptions) { throw InvalidTransitionException::stepHasNoAllowedTransition($workflowItem->getWorkflowName(), $currentStep->getName(), $transition->getName()); } return false; } return true; }
public function testStart() { $obj = new Transition(); $this->assertFalse($obj->isStart()); $obj->setStart(true); $this->assertTrue($obj->isStart()); }