ProphetSpec.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace spec\Prophecy;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. use Prophecy\Argument\ArgumentsWildcard;
  6. use Prophecy\Doubler\Doubler;
  7. use Prophecy\Prophecy\MethodProphecy;
  8. use Prophecy\Prophecy\ProphecySubjectInterface;
  9. class ProphetSpec extends ObjectBehavior
  10. {
  11. function let(Doubler $doubler, ProphecySubjectInterface $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. function it_constructs_new_prophecy_with_parent_class_if_specified($doubler, ProphecySubjectInterface $newDouble)
  22. {
  23. $doubler->double(Argument::any(), array())->willReturn($newDouble);
  24. $this->prophesize('Prophecy\Prophet')->reveal()->shouldReturn($newDouble);
  25. }
  26. function it_constructs_new_prophecy_with_interface_if_specified($doubler, ProphecySubjectInterface $newDouble)
  27. {
  28. $doubler->double(null, Argument::any())->willReturn($newDouble);
  29. $this->prophesize('ArrayAccess')->reveal()->shouldReturn($newDouble);
  30. }
  31. function it_exposes_all_created_prophecies_through_getter()
  32. {
  33. $prophecy1 = $this->prophesize();
  34. $prophecy2 = $this->prophesize();
  35. $this->getProphecies()->shouldReturn(array($prophecy1, $prophecy2));
  36. }
  37. function it_does_nothing_during_checkPredictions_call_if_no_predictions_defined()
  38. {
  39. $this->checkPredictions()->shouldReturn(null);
  40. }
  41. function it_throws_AggregateException_if_defined_predictions_fail(
  42. MethodProphecy $method1,
  43. MethodProphecy $method2,
  44. ArgumentsWildcard $arguments1,
  45. ArgumentsWildcard $arguments2
  46. ) {
  47. $method1->getMethodName()->willReturn('getName');
  48. $method1->getArgumentsWildcard()->willReturn($arguments1);
  49. $method1->checkPrediction()->willReturn(null);
  50. $method2->getMethodName()->willReturn('isSet');
  51. $method2->getArgumentsWildcard()->willReturn($arguments2);
  52. $method2->checkPrediction()->willThrow(
  53. 'Prophecy\Exception\Prediction\AggregateException'
  54. );
  55. $this->prophesize()->addMethodProphecy($method1);
  56. $this->prophesize()->addMethodProphecy($method2);
  57. $this->shouldThrow('Prophecy\Exception\Prediction\AggregateException')
  58. ->duringCheckPredictions();
  59. }
  60. function it_exposes_doubler_through_getter($doubler)
  61. {
  62. $this->getDoubler()->shouldReturn($doubler);
  63. }
  64. }