CascadeTransitionCallbackSpec.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace spec\SM\Callback;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. use SM\Event\TransitionEvent;
  6. use SM\Factory\FactoryInterface;
  7. use SM\StateMachine\StateMachineInterface;
  8. use spec\SM\DummyObject;
  9. class CascadeTransitionCallbackSpec extends ObjectBehavior
  10. {
  11. function let(FactoryInterface $factory)
  12. {
  13. $this->beConstructedWith($factory);
  14. }
  15. function it_is_initializable()
  16. {
  17. $this->shouldHaveType('SM\Callback\CascadeTransitionCallback');
  18. }
  19. function it_applies($factory, TransitionEvent $event, DummyObject $object, StateMachineInterface $sm)
  20. {
  21. $factory->get($object, 'graph')->willReturn($sm);
  22. $sm->can('transition')->willReturn(true);
  23. $sm->apply('transition', true)->shouldBeCalled();
  24. $this->apply($object, $event, 'transition', 'graph');
  25. }
  26. function it_applies_with_default_graph(
  27. $factory,
  28. TransitionEvent $event,
  29. DummyObject $object,
  30. StateMachineInterface $sm1,
  31. StateMachineInterface $sm2
  32. ) {
  33. $event->getStateMachine()->willReturn($sm2);
  34. $sm2->getGraph()->willReturn('graph');
  35. $factory->get($object, 'graph')->willReturn($sm1);
  36. $sm1->can('transition')->willReturn(true);
  37. $sm1->apply('transition', true)->shouldBeCalled();
  38. $this->apply($object, $event, 'transition');
  39. }
  40. function it_applies_with_default_graph_and_default_transition(
  41. $factory,
  42. TransitionEvent $event,
  43. DummyObject $object,
  44. StateMachineInterface $sm1,
  45. StateMachineInterface $sm2
  46. ) {
  47. $event->getStateMachine()->willReturn($sm2);
  48. $event->getTransition()->willReturn('transition');
  49. $sm2->getGraph()->willReturn('graph');
  50. $factory->get($object, 'graph')->willReturn($sm1);
  51. $sm1->can('transition')->willReturn(true);
  52. $sm1->apply('transition', true)->shouldBeCalled();
  53. $this->apply($object, $event);
  54. }
  55. }