Problem/Motivation
In #3306554: InvocationMocker::withConsecutive() is deprecated in PHPUnit 9.6 and removed from PHPUnit 10 Drupal created a workaround that mimics the behavior or InvocationMocker::withConsecutive() to facilitate the upgrade to PHPUnit 10 but the method was removed because it was complicated and was code smell for tests that where generally over complicated and mocking too much.
https://thephp.cc/articles/do-not-mock-what-you-do-not-own
This replacement is just a stop gap though and each use should be reviewed and refactored to use a different mechanism of mocking or stubbing to improve the test.
Proposed resolution
- Replace uses of MockTrait::consecutiveCalls
- Deprecate MockTrait::consecutiveCalls
Comments
Comment #2
catchIs this done?
Comment #3
spokjeNope, still four suppressed warnings
Call to deprecated method withConsecutive() of class PHPUnitFrameworkMockObjectBuilderInvocationMocker.in the PHPStan baseline.Comment #4
catchYeah I should have grepped instead of asking:
Comment #5
andypostWith applied patch from #3419288: Remove withConsecutive() in RouteBuilderTest
Comment #6
longwavePHPStan hasn't flagged MigrateExecutableMemoryExceededTest for some reason.
Comment #8
longwaveAll child issues are in. Also crediting @mondrake here for discussions and the techniques learned in #3306554: InvocationMocker::withConsecutive() is deprecated in PHPUnit 9.6 and removed from PHPUnit 10
Comment #9
longwaveSaving credits.
Comment #10
neclimdulMoving parent since we dropped the deprecation path.
Thought this had stalled but looks like a lot of great work was happening I just wasn't watching the right issues! Thanks!
Comment #11
smustgrave commentedWith the 2 RTBC tickets applied and searching for withConsecutive seems all have been replaced.
Comment #12
catchCommitted the last two RTBC. But https://www.drupal.org/node/3365413 needs an update. I think it might be a good idea to link to core issues with examples and show a couple of diffs on the MR for different approaches like using callbacks.
Comment #13
joachim commented> Instead, prophecies should be instantiated from the prophet factory directly
Does this mean using it like how it's explained here?
https://github.com/phpspec/prophecy?tab=readme-ov-file#how-to-use-it
Comment #14
catchI updated https://www.drupal.org/node/3365413 to point to more examples in core and remove the reference to the shim that we ended up not needing, I think that's enough to close this issue but the CR could use more help in general - however it's going to be very hard to provide example before/after since it all depends on what people are doing.
Comment #15
quietone commented@catch, thanks for updating the change records