Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow MethodProphecy::willThrow() to accept Throwable as string #429

Merged
merged 1 commit into from
Oct 3, 2019

Conversation

timoschinkel
Copy link
Contributor

  • add additional check for existence of interface in contructor
  • change is_subclass_of to is_a to allow for Throwable and subclasses of Throwable
  • add specs for cases of Throwable and extensions of Throwable

To maintain support for php 5.3 the new specs are only applicable for PHP 7.0 and higher and ThrowPromise::isValidThrowable() checks for both Exception and Throwable.

fixes #428

- add additional check for existence of interface in contructor
- change `is_subclass_of` to `is_a` to allow for `Throwable` and subclasses of `Throwable`
- add specs for cases of `Throwable` and extensions of `Throwable`

To maintain support for php 5.3 the new specs are only applicable for PHP 7.0 and higher and `ThrowPromise::isValidThrowable()` checks for both `Exception` and `Throwable`.

fixes phpspec#428
@ciaranmcnulty
Copy link
Member

Thanks for the fix!

@ciaranmcnulty ciaranmcnulty merged commit 9687f4e into phpspec:master Oct 3, 2019
@timoschinkel timoschinkel deleted the issue-428 branch October 3, 2019 11:06
@@ -84,6 +84,28 @@ function it_throws_an_exception_by_class_name()

$this->shouldNotThrow('Prophecy\Exception\InvalidArgumentException')->duringInstantiation();
}

function it_throws_an_extension_of_throwable_by_class_name()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: s/extension/exception

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I filed this PR - and it's merged already - but I think I do mean "extension" here. Before you could do willThrow(\Throwable::class), but not with interfaces that extend \Throwable. Hence the usage of \Fixtures\Prophecy\ThrowableInterface; that fixture extends \Throwable. The explanation is in the linked issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MethodProphecy::willThrow() doesn't accept (an extension of) Throwable
3 participants