ProphetSpec.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace spec\Prophecy;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. class ProphetSpec extends ObjectBehavior
  6. {
  7. /**
  8. * @param \Prophecy\Doubler\Doubler $doubler
  9. * @param \Prophecy\Prophecy\ProphecySubjectInterface $double
  10. */
  11. function let($doubler, $double)
  12. {
  13. $doubler->double(null, array())->willReturn($double);
  14. $this->beConstructedWith($doubler);
  15. }
  16. function it_constructs_new_prophecy_on_prophesize_call()
  17. {
  18. $prophecy = $this->prophesize();
  19. $prophecy->shouldBeAnInstanceOf('Prophecy\Prophecy\ObjectProphecy');
  20. }
  21. /**
  22. * @param \Prophecy\Prophecy\ProphecySubjectInterface $newDouble
  23. */
  24. function it_constructs_new_prophecy_with_parent_class_if_specified($doubler, $newDouble)
  25. {
  26. $doubler->double(Argument::any(), array())->willReturn($newDouble);
  27. $this->prophesize('Prophecy\Prophet')->reveal()->shouldReturn($newDouble);
  28. }
  29. /**
  30. * @param \Prophecy\Prophecy\ProphecySubjectInterface $newDouble
  31. */
  32. function it_constructs_new_prophecy_with_interface_if_specified($doubler, $newDouble)
  33. {
  34. $doubler->double(null, Argument::any())->willReturn($newDouble);
  35. $this->prophesize('ArrayAccess')->reveal()->shouldReturn($newDouble);
  36. }
  37. function it_exposes_all_created_prophecies_through_getter()
  38. {
  39. $prophecy1 = $this->prophesize();
  40. $prophecy2 = $this->prophesize();
  41. $this->getProphecies()->shouldReturn(array($prophecy1, $prophecy2));
  42. }
  43. function it_does_nothing_during_checkPredictions_call_if_no_predictions_defined()
  44. {
  45. $this->checkPredictions()->shouldReturn(null);
  46. }
  47. /**
  48. * @param \Prophecy\Prophecy\MethodProphecy $method1
  49. * @param \Prophecy\Prophecy\MethodProphecy $method2
  50. * @param \Prophecy\Argument\ArgumentsWildcard $arguments1
  51. * @param \Prophecy\Argument\ArgumentsWildcard $arguments2
  52. */
  53. function it_throws_AggregateException_if_defined_predictions_fail(
  54. $method1, $method2, $arguments1, $arguments2
  55. )
  56. {
  57. $method1->getMethodName()->willReturn('getName');
  58. $method1->getArgumentsWildcard()->willReturn($arguments1);
  59. $method1->checkPrediction()->willReturn(null);
  60. $method2->getMethodName()->willReturn('isSet');
  61. $method2->getArgumentsWildcard()->willReturn($arguments2);
  62. $method2->checkPrediction()->willThrow(
  63. 'Prophecy\Exception\Prediction\AggregateException'
  64. );
  65. $this->prophesize()->addMethodProphecy($method1);
  66. $this->prophesize()->addMethodProphecy($method2);
  67. $this->shouldThrow('Prophecy\Exception\Prediction\AggregateException')
  68. ->duringCheckPredictions();
  69. }
  70. function it_exposes_doubler_through_getter($doubler)
  71. {
  72. $this->getDoubler()->shouldReturn($doubler);
  73. }
  74. }