-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
CoversMethod
looks bugged when trait is used
#1066
Comments
I can confirm that PHPUnit 11.5 (with php-code-coverage 11.0.9) and PHPUnit 12.0 (with phpunit/php-code-coverage 12.1.0) behave differently and will investigate this further. |
This might be related or a separate bug, but how PHPUnit 12 reports the "code that is not listed as code to be covered or used" is wrong:
In the output shown above, |
This is odd: my first attempt to reproduce this through unit tests failed (see dabbb4f). |
Good day, @sebastianbergmann Thank you for looking into this. Unfortunately I do not know internals, but if you think I can help with some manual testing, please let me know. Just a wild guess about why it may pass during unit testing based on your code dabbb4f
Please ignore me if this makes no sense. Regards |
Summary
It looks like
CoversMethod
is bugged when trait is used by class.Test coverage that is reported is not complete and is very strange.
I have created repository that recreates the issue https://github.com/yurii-stickee-2023/bugged-phpunit-covers-method-with-trait
p.s.
When tests are run while trait is used, PHPUnit outputs
Maybe this can be useful
Current behavior
It has very weird behavior. It makes

Dummy
class with test coverage while other 2 classes are left without test coverage for some unknown reasonHow to reproduce
Here https://github.com/yurii-stickee-2023/bugged-phpunit-covers-method-with-trait/blob/73a82437acf414ea08422982dd68afd564c69032/src/DummyWithTrait.php#L6 in dummy class
DummyWithTrait
uncomment trait so it becomesRun tests (I did it with xDebug)
Expected behavior
It should report 50% test coverage for all 3 classes -
Dummy
,Dummy2
andDummyWithTrait
If you downgrade to PHPUnit 11 like
composer require --dev phpunit/phpunit:^11.0 -W
you will see that it works as expected in both cases now.The text was updated successfully, but these errors were encountered: