-
-
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 support for #[CoversTrait]
and #[UsesTrait]
attributes
#5958
Comments
- 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
- 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
@sebastianbergmann I'd like to re-visit this change. It may be my miss-understanding, but I think there is value in this feature as it previously worked. Specifically, I want to limit coverage counting to the code in a specific trait, to ensure I'm not accidentally marking other code in the class as covered when executing it without any assertions on its behavior (e.g. during the arrange part of the test). It is a common pattern to group a feature into a single trait, and then have a test file for just that feature. I believe the use of |
I reverted the deprecation in |
The
#[CoversTrait]
and#[UsesTrait]
attributes were introduced in PHPUnit 11.2 while/after working on #5798.Had I been aware at the time that
#[CoversClass]
and#[UsesClass]
also target the traits used by the targeted classes, I would not have implemented the#[CoversTrait]
and#[UsesTrait]
attributes. As of 17bbefa, this behaviour is now documented in tests.The
#[CoversTrait]
and#[UsesTrait]
attributes are therefore not needed and will be deprecated in PHPUnit 11.4 and removed in PHPUnit 12.If you currently use
#[CoversClass]
or#[UsesClass]
to target traits: don't. Testing traits in isolation from their embedding classes is not useful.If you currently use
#[CoversTrait]
or#[UsesTrait]
to target traits: don't. The traits used by the class(es) you target with#[CoversClass]
or#[UsesClass]
will be targeted as well.The text was updated successfully, but these errors were encountered: