No Description

LazyDoubleSpec.php 2.7KB

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