Fix PHPUnit warning for mocks without expectation, use stubs instead#488
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a new PHPUnit 12.5.0 notice by replacing createMock() with createStub() for test doubles that don't require expectation configuration. The changes eliminate warnings about mock objects created without expectations, following PHPUnit's best practice of using stubs for simple return values and mocks only when verifying behavior.
Key changes:
- Replaced
createMock()withcreateStub()for objects used as simple return values or dependencies without behavior expectations - Added
atLeast(0)expectations inFileDriverTestfor methods that need to be called but don't require strict verification - Added a
never()expectation inManagerRegistryTestto properly configure a mock that should not have a specific method called
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/ObjectManagerDecoratorTest.php | Converted repository, class metadata, and metadata factory mocks to stubs as they serve as return values |
| tests/Mapping/FileDriverTest.php | Converted class metadata mocks to stubs; added atLeast(0) expectations to file locator for methods that act as stubs |
| tests/Mapping/DriverChainTest.php | Converted class metadata and mapping driver mocks to stubs for test fixtures |
| tests/Mapping/ClassMetadataFactoryTest.php | Converted driver and metadata mocks to stubs in setup and test methods |
| tests/Mapping/AbstractClassMetadataFactoryTest.php | Converted driver and metadata mocks to stubs for simple return values |
| tests/ManagerRegistryTest.php | Converted repository and metadata mocks to stubs; added never() expectation to object manager mock |
| tests/Event/PreUpdateEventArgsTest.php | Converted object manager mock to stub in test setup |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1) Doctrine\Tests\Persistence\Mapping\AbstractClassMetadataFactoryTest::testItGetsTheSameMetadataForBackslashedClassName No expectations were configured for the mock object for Doctrine\Persistence\Mapping\Driver\MappingDriver. You should refactor your test code and use a test stub instead.
IonBazan
approved these changes
Dec 7, 2025
greg0ire
approved these changes
Dec 7, 2025
Member
|
Thanks @GromNaN ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix the new notice of PHPUnit 12.5.0.
Example of PHPUnit notice when running
./vendor/bin/phpunit --display-all-issues: