Use createStub() for test doubles without expectations - #277
Merged
GaryJones merged 1 commit intoFeb 11, 2026
Merged
Conversation
PHPUnit distinguishes between mocks (which verify interactions via expects()) and stubs (which simply return canned values). 73 of 74 createMock() calls across the test suite never set expectations, making createStub() the semantically correct choice. This aligns with PHPUnit 12's enforcement of this distinction and clarifies the intent of each test double. The single remaining createMock() in CoreIntegrationTest correctly verifies that add_provider is called exactly three times.
GaryJones
deleted the
refactor/use-createStub-for-test-doubles-without-expectations
branch
February 11, 2026 16:49
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.
Summary
PHPUnit provides two factory methods for test doubles:
createMock()for mocks that verify interactions viaexpects(), andcreateStub()for stubs that simply return canned values. The test suite was usingcreateMock()universally, regardless of whether the test double actually had expectations configured.This replaces 73 of the 74
createMock()calls withcreateStub(), leaving only the single instance inCoreIntegrationTestthat genuinely verifiesadd_provideris called exactly three times. The change is purely semantic today (both returnMockObjectin PHPUnit 9), but it communicates intent more clearly and prepares for PHPUnit 12, which enforces this distinction at runtime — configuring expectations on a stub will fail, and creating a mock without expectations will trigger a warning.No
createStub()calls existed previously, so there were no instances of the reverse problem (stubs with expectations).Test plan