No Description

ProphetSpec.php 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. }