phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 241 forks source link

[DX] Mocks should fail immediately #508

Open Jean85 opened 3 years ago

Jean85 commented 3 years ago

I was having some attrition while using Prophecy in my PHPUnit tests, and I track it down to mocks going further with unexpected calls.

I've opened https://github.com/phpspec/prophecy-phpunit/issues/27 thinking that the root issue was the migration from the old, deprecated PHPUnit integration to the new trait one, but I discovered that it wasn't, and instead it was https://github.com/phpspec/prophecy/issues/457 that, in 1.10, made this change.

That issue was closed by @ciaranmcnulty with:

Yes, I think if faulty tests were wrongly passing before we don't need to consider it a break.

... but I'm here to ask for a revert, or at least a switch to enable the old behavior back.

Why do I need this?

I would like to go back to mock failing hard and fast because writing (or altering) tests with this new behavior is extremely frustrating:

In both those cases, it's often the case of getting the mock's expectation slightly wrong, but I have no way of discovering it: I always have to widen it up until it matches and I get a green test, and then go back, making the expectation narrower as desired.

Is it possible to get the old behaviour back? Or to have a way to opt-out from this new behaviour? I understand that #441 was not considered a BC break because code as is had to be correct anyway, but while changing code this is really frustrating!

Jean85 commented 3 years ago

I drafted a solution in #509