prophecy: Cannot prophesize and interface extending \Throwable
If an exception interface extends \Throwable (now a recommended best practice, enforced by phpstan), it’s not possible to prophesize it.
Reproducer:
interface MyException extends \Throwable {}
$e = $this->prophesize(MyException::class);
$e->willExtend(\Exception::class);
$e->reveal();
(moved from https://github.com/symfony/symfony/issues/27419)
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 17 (9 by maintainers)
It’s not 1:1 replacement, but workaround. Goal is to be able to pass typehints for both
interface MyException implements ThrowableandException. Prophecy should generate something likeclass MockClass extends Exception implements MyException, not sure why does it give up as soon as it sees there is one final method inException.Smallest possible reproducer is to just use
Throwableinstead ofMyExceptionthough, prophecy chokes up even with that one.No that is excluding concrete Exceptions or Errors (which don’t need patching)
Yes and included test does not use same thing code posted here does. It does not extend Exception but stdClass. So once again, you have failing test case in this issue, which was never fixed.
Should be closed @ciaranmcnulty, as you fixed it in #412