ThrowPromiseSpec.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace spec\Prophecy\Promise;
  3. use PhpSpec\ObjectBehavior;
  4. class ThrowPromiseSpec extends ObjectBehavior
  5. {
  6. function let()
  7. {
  8. $this->beConstructedWith('RuntimeException');
  9. }
  10. function it_is_promise()
  11. {
  12. $this->shouldBeAnInstanceOf('Prophecy\Promise\PromiseInterface');
  13. }
  14. /**
  15. * @param \Prophecy\Prophecy\ObjectProphecy $object
  16. * @param \Prophecy\Prophecy\MethodProphecy $method
  17. */
  18. function it_instantiates_and_throws_exception_from_provided_classname($object, $method)
  19. {
  20. $this->beConstructedWith('InvalidArgumentException');
  21. $this->shouldThrow('InvalidArgumentException')
  22. ->duringExecute(array(), $object, $method);
  23. }
  24. /**
  25. * @param \Prophecy\Prophecy\ObjectProphecy $object
  26. * @param \Prophecy\Prophecy\MethodProphecy $method
  27. */
  28. function it_instantiates_exceptions_with_required_arguments($object, $method)
  29. {
  30. $this->beConstructedWith('spec\Prophecy\Promise\RequiredArgumentException');
  31. $this->shouldThrow('spec\Prophecy\Promise\RequiredArgumentException')
  32. ->duringExecute(array(), $object, $method);
  33. }
  34. /**
  35. * @param \Prophecy\Prophecy\ObjectProphecy $object
  36. * @param \Prophecy\Prophecy\MethodProphecy $method
  37. */
  38. function it_throws_provided_exception($object, $method)
  39. {
  40. $this->beConstructedWith($exc = new \RuntimeException('Some exception'));
  41. $this->shouldThrow($exc)->duringExecute(array(), $object, $method);
  42. }
  43. }
  44. class RequiredArgumentException extends \Exception
  45. {
  46. final public function __construct($message, $code) {}
  47. }