You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
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.
The text was updated successfully, but these errors were encountered:
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".
The API of PHPUnit's built-in test doubles functionality for creating test doubles -- originally
getMock()
, thengetMockBuilder()
, and nowcreateMock()
etc. -- creates a stub. If, and only if, theexpects()
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 theexpects()
method and therefore are stubs that cannot become mocks.The text was updated successfully, but these errors were encountered: