FactorySpec.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace spec\SM\Factory;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. use SM\Callback\CallbackFactoryInterface;
  6. use spec\SM\DummyObject;
  7. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  8. class FactorySpec extends ObjectBehavior
  9. {
  10. protected $configs = array(
  11. 'graph1' => array('state_machine_class' => 'SM\\StateMachine\\StateMachine', 'class' => 'spec\\SM\\DummyObject'),
  12. 'graph2' => array('class' => 'spec\\SM\\DummyObject'),
  13. );
  14. function let(EventDispatcherInterface $dispatcher, CallbackFactoryInterface $callbackFactory)
  15. {
  16. $this->beConstructedWith($this->configs, $dispatcher, $callbackFactory);
  17. }
  18. function it_is_initializable()
  19. {
  20. $this->shouldHaveType('SM\Factory\Factory');
  21. }
  22. function it_creates_statemachine(DummyObject $object)
  23. {
  24. $graph = 'graph1';
  25. $this->get($object, $graph)->shouldReturnAnInstanceOf($this->configs[$graph]['state_machine_class']);
  26. }
  27. function it_creates_statemachine_with_default_class(DummyObject $object)
  28. {
  29. $this->get($object, 'graph2')->shouldReturnAnInstanceOf('SM\\StateMachine\\StateMachine');
  30. }
  31. function it_throws_exception_when_configuration_doesnt_exist(DummyObject $object)
  32. {
  33. $this->shouldThrow('SM\\SMException')->during('get', array($object, 'non-existing-graph'));
  34. }
  35. }