Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

createStub(), createConfiguredStub(), createPartialStub() #411

Closed
sebastianbergmann opened this issue Feb 21, 2018 · 1 comment
Closed

Comments

@sebastianbergmann
Copy link
Owner

PHPUnit's built-in test doubles functionality pre-dates the de-facto standard classification for test doubles established by Gerard Meszaros in his book "xUnit Test Patterns".

  • A stub is used to "replace a real component on which the [system under test] depends so that the test has a control point for the indirect inputs of the [system under test]. This allows the test to force the [system under test] down paths it might not otherwise execute."

  • A mock is used "as an observation point that is used to verify the indirect outputs of the [system under test] as it is exercised. Typically, the [mock] also includes the functionality of a [stub] in that it must return values to the [system under test] if it hasn't already failed the tests but the emphasis is on the verification of the indirect outputs. Therefore, a [mock] is lot more than just a [stub] plus assertions; it is used a fundamentally different way."

The API of PHPUnit's built-in test doubles functionality for creating test doubles -- originally getMock(), then getMockBuilder(), and now createMock() etc. -- creates a stub. If, and only if, the expects() method is called on this stub to set up expectations then that stub becomes a mock.

The fact that the test double returned by createMock() is initially "just" a stub can be confusing, especially for developers new to PHPUnit in particular and/or unit testing and test doubles in general.

It should be explored whether the addition of createStub(), createConfiguredStub(), createPartialStub() methods is feasible. These methods should create test double objects that do not have the expects() method and therefore are stubs that cannot become mocks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant