CallTimesPredictionSpec.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace spec\Prophecy\Prediction;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. use Prophecy\Argument\ArgumentsWildcard;
  6. use Prophecy\Call\Call;
  7. use Prophecy\Prophecy\MethodProphecy;
  8. use Prophecy\Prophecy\ObjectProphecy;
  9. class CallTimesPredictionSpec extends ObjectBehavior
  10. {
  11. function let()
  12. {
  13. $this->beConstructedWith(2);
  14. }
  15. function it_is_prediction()
  16. {
  17. $this->shouldHaveType('Prophecy\Prediction\PredictionInterface');
  18. }
  19. function it_does_nothing_if_there_were_exact_amount_of_calls_being_made(
  20. ObjectProphecy $object,
  21. MethodProphecy $method,
  22. Call $call1,
  23. Call $call2
  24. ) {
  25. $this->check(array($call1, $call2), $object, $method)->shouldReturn(null);
  26. }
  27. function it_throws_UnexpectedCallsCountException_if_calls_found(
  28. ObjectProphecy $object,
  29. MethodProphecy $method,
  30. Call $call,
  31. ArgumentsWildcard $arguments
  32. ) {
  33. $object->reveal()->willReturn(new \stdClass());
  34. $object->findProphecyMethodCalls('getName', Argument::any())->willReturn(array());
  35. $method->getObjectProphecy()->willReturn($object);
  36. $method->getMethodName()->willReturn('getName');
  37. $method->getArgumentsWildcard()->willReturn($arguments);
  38. $arguments->__toString()->willReturn('123');
  39. $call->getMethodName()->willReturn('getName');
  40. $call->getArguments()->willReturn(array(5, 4, 'three'));
  41. $call->getCallPlace()->willReturn('unknown');
  42. $this->shouldThrow('Prophecy\Exception\Prediction\UnexpectedCallsCountException')
  43. ->duringCheck(array($call), $object, $method);
  44. }
  45. }