LazyDoubleSpec.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace spec\Prophecy\Doubler;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Doubler\Doubler;
  5. use Prophecy\Prophecy\ProphecySubjectInterface;
  6. class LazyDoubleSpec extends ObjectBehavior
  7. {
  8. function let(Doubler $doubler)
  9. {
  10. $this->beConstructedWith($doubler);
  11. }
  12. function it_returns_anonymous_double_instance_by_default($doubler, ProphecySubjectInterface $double)
  13. {
  14. $doubler->double(null, array())->willReturn($double);
  15. $this->getInstance()->shouldReturn($double);
  16. }
  17. function it_returns_class_double_instance_if_set($doubler, ProphecySubjectInterface $double, \ReflectionClass $class)
  18. {
  19. $doubler->double($class, array())->willReturn($double);
  20. $this->setParentClass($class);
  21. $this->getInstance()->shouldReturn($double);
  22. }
  23. function it_returns_same_double_instance_if_called_2_times(
  24. $doubler,
  25. ProphecySubjectInterface $double1,
  26. ProphecySubjectInterface $double2
  27. ) {
  28. $doubler->double(null, array())->willReturn($double1);
  29. $doubler->double(null, array())->willReturn($double2);
  30. $this->getInstance()->shouldReturn($double2);
  31. $this->getInstance()->shouldReturn($double2);
  32. }
  33. function its_setParentClass_throws_ClassNotFoundException_if_class_not_found()
  34. {
  35. $this->shouldThrow('Prophecy\Exception\Doubler\ClassNotFoundException')
  36. ->duringSetParentClass('SomeUnexistingClass');
  37. }
  38. function its_setParentClass_throws_exception_if_prophecy_is_already_created(
  39. $doubler,
  40. ProphecySubjectInterface $double
  41. ) {
  42. $doubler->double(null, array())->willReturn($double);
  43. $this->getInstance();
  44. $this->shouldThrow('Prophecy\Exception\Doubler\DoubleException')
  45. ->duringSetParentClass('stdClass');
  46. }
  47. function its_addInterface_throws_InterfaceNotFoundException_if_no_interface_found()
  48. {
  49. $this->shouldThrow('Prophecy\Exception\Doubler\InterfaceNotFoundException')
  50. ->duringAddInterface('SomeUnexistingInterface');
  51. }
  52. function its_addInterface_throws_exception_if_prophecy_is_already_created(
  53. $doubler,
  54. ProphecySubjectInterface $double
  55. ) {
  56. $doubler->double(null, array())->willReturn($double);
  57. $this->getInstance();
  58. $this->shouldThrow('Prophecy\Exception\Doubler\DoubleException')
  59. ->duringAddInterface('ArrayAccess');
  60. }
  61. }