function it_creates_the_repository_based_transition_handler(Item $item, Workflow $workflow, StateRepository $stateRepository, EntityManager $entityManager, EntityRepository $entityRepository, Listener $listener) { $entityManager->getRepository('test')->willReturn($entityRepository); $item->isWorkflowStarted()->willReturn(false); $item->getEntity()->willReturn(static::$entity); $this->setListener($listener); $this->createTransitionHandler($item, $workflow, null, 'test', $stateRepository)->shouldHaveType('Netzmacht\\Workflow\\Handler\\RepositoryBasedTransitionHandler'); }
/** * {@inheritdoc} */ public function getWorkflowByItem(Item $item) { return $this->getWorkflow($item->getEntityId(), $item->getEntity()); }
/** * Get entity. * * @return Entity */ public function getEntity() { return $this->item->getEntity(); }
/** * Get the entity of the item and protect entity type. * * @param Item $item Workflow item. * * @return Entity * * @hrows AssertionException If entity is not an Instance of */ protected function getEntity(Item $item) { $entity = $item->getEntity(); Assertion::isInstanceOf($entity, 'ContaoCommunityAlliance\\DcGeneral\\Data\\ModelInterface', 'Invalid entity given'); return $entity; }
/** * {@inheritdoc} * * @SuppressWarnings(PHPMD.UnusedLocalVariable) * @SuppressWarnings(PHPMD.EvalExpression) */ public function match(Transition $transition, Item $item, Context $context, ErrorCollection $errorCollection) { if (!$this->compiled) { return false; } // Vars are created so that eval can access them. $entity = $item->getEntity(); $entityId = $item->getEntityId(); // @codingStandardsIgnoreStart if (eval($this->compiled)) { // @codingStandardsIgnoreEnd return true; } $errorCollection->addError($this->message, array($this->expression)); return false; }
/** * {@inheritdoc} */ public function match(Transition $transition, Item $item, Context $context, ErrorCollection $errorCollection) { $value = $this->getEntityValue($item->getEntity()); if (Comparison::compare($value, $this->value, $this->operator)) { return true; } $errorCollection->addError('transition.condition.property.failed', array($this->property, $value, $this->operator, $this->value)); return false; }
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'); }