1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<?php
namespace spec\Prophecy\Promise;
use PhpSpec\Exception\Example\SkippingException;
use PhpSpec\ObjectBehavior;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
class ThrowPromiseSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith('RuntimeException');
}
function it_is_promise()
{
$this->shouldBeAnInstanceOf('Prophecy\Promise\PromiseInterface');
}
function it_instantiates_and_throws_exception_from_provided_classname(ObjectProphecy $object, MethodProphecy $method)
{
$this->beConstructedWith('InvalidArgumentException');
$this->shouldThrow('InvalidArgumentException')
->duringExecute(array(), $object, $method);
}
function it_instantiates_exceptions_with_required_arguments(ObjectProphecy $object, MethodProphecy $method)
{
$this->beConstructedWith('spec\Prophecy\Promise\RequiredArgumentException');
$this->shouldThrow('spec\Prophecy\Promise\RequiredArgumentException')
->duringExecute(array(), $object, $method);
}
function it_throws_provided_exception(ObjectProphecy $object, MethodProphecy $method)
{
$this->beConstructedWith($exc = new \RuntimeException('Some exception'));
$this->shouldThrow($exc)->duringExecute(array(), $object, $method);
}
function it_throws_error_instances(ObjectProphecy $object, MethodProphecy $method)
{
if (!class_exists('\Error')) {
throw new SkippingException('The class Error, introduced in PHP 7, does not exist');
}
$this->beConstructedWith($exc = new \Error('Error exception'));
$this->shouldThrow($exc)->duringExecute(array(), $object, $method);
}
function it_throws_errors_by_class_name()
{
if (!class_exists('\Error')) {
throw new SkippingException('The class Error, introduced in PHP 7, does not exist');
}
$this->beConstructedWith('\Error');
$this->shouldNotThrow('Prophecy\Exception\InvalidArgumentException')->duringInstantiation();
}
function it_does_not_throw_something_that_is_not_throwable_by_class_name()
{
$this->beConstructedWith('\stdClass');
$this->shouldThrow('Prophecy\Exception\InvalidArgumentException')->duringInstantiation();
}
function it_does_not_throw_something_that_is_not_throwable_by_instance()
{
$this->beConstructedWith(new \stdClass());
$this->shouldThrow('Prophecy\Exception\InvalidArgumentException')->duringInstantiation();
}
function it_throws_an_exception_by_class_name()
{
$this->beConstructedWith('\Exception');
$this->shouldNotThrow('Prophecy\Exception\InvalidArgumentException')->duringInstantiation();
}
function it_throws_an_extension_of_throwable_by_class_name()
{
if (!interface_exists('\Throwable')) {
throw new SkippingException('The interface Throwable, introduced in PHP 7, does not exist');
}
$this->beConstructedWith('\Fixtures\Prophecy\ThrowableInterface');
$this->shouldNotThrow('Prophecy\Exception\InvalidArgumentException')->duringInstantiation();
}
function it_throws_a_throwable_by_class_name()
{
if (!interface_exists('\Throwable')) {
throw new SkippingException('The interface Throwable, introduced in PHP 7, does not exist');
}
$this->beConstructedWith('\Throwable');
$this->shouldNotThrow('Prophecy\Exception\InvalidArgumentException')->duringInstantiation();
}
}
class RequiredArgumentException extends \Exception
{
final public function __construct($message, $code) {}
}
|