Skip to content

Use createStub() for test doubles without expectations - #277

Merged
GaryJones merged 1 commit into
2.xfrom
refactor/use-createStub-for-test-doubles-without-expectations
Feb 11, 2026
Merged

GaryJones merged 1 commit into
2.xfrom
refactor/use-createStub-for-test-doubles-without-expectations

Conversation

@GaryJones

Copy link
Copy Markdown
Contributor

Summary

PHPUnit provides two factory methods for test doubles: createMock() for mocks that verify interactions via expects(), and createStub() for stubs that simply return canned values. The test suite was using createMock() universally, regardless of whether the test double actually had expectations configured.

This replaces 73 of the 74 createMock() calls with createStub(), leaving only the single instance in CoreIntegrationTest that genuinely verifies add_provider is called exactly three times. The change is purely semantic today (both return MockObject in 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

  • Integration tests pass — the change is a like-for-like replacement with no behavioural difference under PHPUnit 9

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
GaryJones requested a review from a team as a code owner February 11, 2026 16:39
@GaryJones GaryJones added this to the 2.0.0 milestone Feb 11, 2026
@GaryJones GaryJones added the type: maintenance Routine maintenance and code quality improvements label Feb 11, 2026
@GaryJones GaryJones self-assigned this Feb 11, 2026
@GaryJones
GaryJones merged commit 015379a into 2.x Feb 11, 2026
7 checks passed
@GaryJones
GaryJones deleted the refactor/use-createStub-for-test-doubles-without-expectations branch February 11, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: maintenance Routine maintenance and code quality improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant