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
PHPUnit can automatically generate test stubs and mock objects (test doubles) based on interfaces and classes.
For quite a while, PHPUnit has offered the createStub() and createMock() methods for creating test stubs and mock objects with best practice defaults. Furthermore, alternatives such as getMockForTrait() exist, but not all of them offer the same clear separation between test double and mock object. For instance, no method named getStubForTrait() exists. Such an inconsistency can lead to confusion.
The getObjectForTrait() method returns a mock object for an otherwise empty class that uses a specified trait. This allows for testing the concrete methods of a trait.
Having to use getObjectForTrait() to test something is almost always a code smell: something is not quite right with the software design of the system-under-test.
To promote better software design, improve the readability of test code, and to reduce complexity inside PHPUnit's test double functionality, TestCase::getObjectForTrait() will be deprecated and then removed:
soft deprecation in PHPUnit 10.1 (add @deprecated annotation to the method declaration)
deprecation in PHPUnit 11 (using the method will trigger a deprecation)
removal in PHPUnit 12
The text was updated successfully, but these errors were encountered:
PHPUnit can automatically generate test stubs and mock objects (test doubles) based on interfaces and 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 asgetMockForTrait()
exist, but not all of them offer the same clear separation between test double and mock object. For instance, no method namedgetStubForTrait()
exists. Such an inconsistency can lead to confusion.The
getObjectForTrait()
method returns a mock object for an otherwise empty class that uses a specified trait. This allows for testing the concrete methods of a trait.Having to use
getObjectForTrait()
to test something is almost always a code smell: something is not quite right with the software design of the system-under-test.To promote better software design, improve the readability of test code, and to reduce complexity inside PHPUnit's test double functionality,
TestCase::getObjectForTrait()
will be deprecated and then removed:@deprecated
annotation to the method declaration)The text was updated successfully, but these errors were encountered: