ThrowPromiseSpec.php 1.4 KB

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