-
-
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::getObjectForTrait()
#5244
Labels
Milestone
Comments
sebastianbergmann
added a commit
that referenced
this issue
Feb 24, 2023
TestCase::getObjectForTrait()
sebastianbergmann
added a commit
that referenced
this issue
Aug 18, 2023
moiikana
added a commit
to wmde/fun-validators
that referenced
this issue
Jan 9, 2025
- it's not advised to test traits isolated from the code that actually uses the trait sebastianbergmann/phpunit#5958 sebastianbergmann/phpunit#5244 - lots of code around mocking traits for that matter got deprecated in phpunit because of that - that's why we try to use a stub class that uses the trait artificially to test its private method
moiikana
added a commit
to wmde/fun-validators
that referenced
this issue
Jan 9, 2025
- it's not advised to test traits isolated from the code that actually uses the trait sebastianbergmann/phpunit#5958 sebastianbergmann/phpunit#5244 - lots of code around mocking traits for that matter got deprecated in phpunit because of that - that's why we try to use a stub class that uses the trait artificially to test its private method
paulholden
added a commit
to paulholden/moodle
that referenced
this issue
Feb 25, 2025
"getObjectForTrait() is deprecated and will be removed in PHPUnit 12 without replacement." See: sebastianbergmann/phpunit#5244
paulholden
added a commit
to paulholden/moodle
that referenced
this issue
Feb 25, 2025
"getObjectForTrait() is deprecated and will be removed in PHPUnit 12 without replacement." See: sebastianbergmann/phpunit#5244
HuongNV13
pushed a commit
to moodlehq/qbank
that referenced
this issue
Feb 27, 2025
"getObjectForTrait() is deprecated and will be removed in PHPUnit 12 without replacement." See: sebastianbergmann/phpunit#5244
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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: