Open mieszkomalawski opened 6 years ago
The process is not under prophecy's control. Mock verification is triggered in PHPUnit's TestCase.
Alternative solution here would be for prophecy to only extend \Exception to avoid possible clashes. That would fix the problem. I just spent 10minutes trying to figure out why my code was dying mid-test until I realized the problem and removed the expectedException annotation to find "Prophecy\Exception\Call\UnexpectedCallException: Unexpected method call". Easy to fix now.. but makes me not so confident about this test's robustness going forward if any new call can trigger weird unrelated errors due to the exception mismatch. I can try/catch myself and assert the exact exception class as a workaround, but still would be nice to see this fixed here.
Consider this situation:
TestCase expects \RuntimeException to be thrown (we are testing some case where tested class throws \RuntimeException - expected behavior)
TestCase also expects that some mock will be called eg. logging service will be called before throwing exception
Mock expectation faile (eg. method is called with wrong args on logging service ), but test passes because it received UnexpectedCallException which extends \RuntimeException so the first expectation is met.
Possible solution: mock expectations should be verified before exception make to the part where phpunit verifies exception expectations