[phpunit 12] Add AllowMockObjectsWithoutExpectationsAttributeRector #619
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHPUnit 12 introduced requirement for mocks to be used or be stubs. There is quite common use case that breaks this assumption. Mock object defined in in
setUp()method, used in multiple test methods, but not defining expectations in all of them. Often these mocks are passed as arguments into anewservice defined insetUp()method as well.This will turn your PHPUnit run into list of NNNNNNs and make test hard to read and impossible to turn off. It seem something is broken, and it forces you to rewrite a lot of tests manually.
Since PHPUnit 12.5.2 you can add special attribute per tests to ignore this notice. More manual dumb work.
This rule automates this process by looking at:
MockObjectproperty? ✔️setUp()method? ✔️setUp()method or at least in 2 tests methods? - TODOThen adds the attribute there, as we obviously want to use the mock this way.
Any further checks we can automate? Keep them coming.