function it_resolves_order_states_with_state_machine_event(StateResolverInterface $stateResolver, TransitionEvent $event, OrderInterface $order, StateMachineInterface $sm) { $event->getStateMachine()->willReturn($sm); $sm->getObject()->willReturn($order); $stateResolver->resolveShippingState($order)->shouldBeCalled(); $stateResolver->resolvePaymentState($order)->shouldBeCalled(); $this->resolveOrderStatesOnTransition($event); }
/** * @param TransitionEvent $event */ public function resolveOrderStatesOnTransition(TransitionEvent $event) { $resource = $event->getStateMachine()->getObject(); if ($resource instanceof OrderInterface) { $this->resolve($resource); } elseif ($resource instanceof OrderAwareInterface && null !== $resource->getOrder()) { $this->resolve($resource->getOrder()); } }
function it_applies_with_default_graph_and_default_transition($factory, TransitionEvent $event, DummyObject $object, StateMachineInterface $sm1, StateMachineInterface $sm2) { $event->getStateMachine()->willReturn($sm2); $event->getTransition()->willReturn('transition'); $sm2->getGraph()->willReturn('graph'); $factory->get($object, 'graph')->willReturn($sm1); $sm1->can('transition')->willReturn(true); $sm1->apply('transition', true)->shouldBeCalled(); $this->apply($object, $event); }
/** * Apply a transition to the object that has just undergone a transition * * @param \Traversable|array $objects Object or array|traversable of objects to apply the transition on * @param TransitionEvent $event Transition event * @param string|null $transition Transition that is to be applied (if null, same as the trigger) * @param string|null $graph Graph on which the new transition will apply (if null, same as the trigger) * @param bool $soft If true, check if it can apply the transition first (no Exception thrown) */ public function apply($objects, TransitionEvent $event, $transition = null, $graph = null, $soft = true) { if (!is_array($objects) && !$objects instanceof \Traversable) { $objects = array($objects); } if (null === $transition) { $transition = $event->getTransition(); } if (null === $graph) { $graph = $event->getStateMachine()->getGraph(); } foreach ($objects as $object) { $this->factory->get($object, $graph)->apply($transition, $soft); } }
/** * {@inheritDoc} */ public function isSatisfiedBy(TransitionEvent $event) { $config = $event->getConfig(); return $this->isSatisfiedByClause('on', $event->getTransition()) && $this->isSatisfiedByClause('from', $event->getState()) && $this->isSatisfiedByClause('to', $config['to']); }
function it_doesnt_satisfies_excluded_from(TransitionEvent $event) { $specs = array('to' => 'tested-state-to', 'excluded_from' => 'tested-state-from'); $this->beConstructedWith($specs, $this->callable); $event->getConfig()->willReturn($this->getConfig(array('tested-state-from'), 'tested-state-to')); $event->getTransition()->willReturn('dummy'); $event->getState()->willReturn('tested-state-from'); $this->isSatisfiedBy($event)->shouldReturn(false); }
/** * @param callable|array $callable A callable or array with index 0 starting with "object" that will evaluated as a property path with "object" being the object undergoing the transition * @param TransitionEvent $event * * @return callable */ protected function filterCallable($callable, TransitionEvent $event) { if (is_array($callable) && isset($callable[0]) && is_string($callable[0]) && 'object' === substr($callable[0], 0, 6)) { $object = $event->getStateMachine()->getObject(); // callable could be "object.property" and not just "object", so we evaluate the "property" path if ('object' !== $callable[0]) { $accessor = new PropertyAccessor(); $object = $accessor->getValue($object, substr($callable[0], 7)); } return array($object, $callable[1]); } return $callable; }