-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate TestCase::createPartialMock()
#5239
Comments
TestCase::createPartialMock()
@sebastianbergmann this is not yet soft deprecated. Is there any change of plans? |
|
How do I marry the superpowers of |
@sebastianbergmann , sorry, I didn't get the whole point,
So is it deprecated/removed or not? Somewhat confusing to me |
PHPUnit can automatically generate test stubs and mock objects (test doubles) based on interfaces and classes.
When it comes to doubling classes, there are limitations:
final
,private
, andstatic
methods cannot be doubled; they retain their original behavior except for static methods which will be replaced by a method throwing an exceptionenum
) arefinal
classes and therefore cannot be doubledreadonly
classes cannot be extended by classes that are notreadonly
and therefore cannot be doubledNot only because of the limitations mentioned above, but also to improve your software design, PHPUnit's documentation recommends to favour the doubling of interfaces over the doubling of classes.
For quite a while, PHPUnit has offered the
createStub()
andcreateMock()
methods for creating test stubs and mock objects with best practice defaults. Furthermore, alternatives such ascreatePartialMock()
exist, but not all of them offer the same clear separation between test double and mock object. For instance, no method namedcreatePartialStub()
exists. Such an inconsistency can lead to confusion.As its name suggests, the
createPartialMock()
method can be used to create a so-called partial mock object: a mock object where not all methods of the original class are replaced with an implementation that can be configured to return a specified value, for instance, or to expect an invocation.Partial mocking is considered a code smell as it makes it not obvious to determine whether you are calling a method that has been doubled or whether you are calling an original method.
To promote better software design, improve the readability of test code, and to reduce complexity inside PHPUnit's test double functionality,
TestCase::createPartialMock()
will be deprecated and then removed:@deprecated
annotation to the method declaration)The text was updated successfully, but these errors were encountered: