Skip to content

Enumerations cannot be targeted for code coverage #1061

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

Closed
doppynl opened this issue Feb 7, 2025 · 5 comments
Closed

Enumerations cannot be targeted for code coverage #1061

doppynl opened this issue Feb 7, 2025 · 5 comments
Assignees
Labels

Comments

@doppynl
Copy link

doppynl commented Feb 7, 2025

Q A
PHPUnit version 12.0.1
PHP version 8.4.2
Installation Method Composer
Code coverage XDebug 3.4.0

Summary

Unable to configure code coverage for Enums.

Current behavior

When configuring coverage or usage using coversClass or usesClass attributes it gives me the following error:
Class ..... is not a valid target for code coverage

I tried configuring coverage using coversNamespace but got a similar error.

How to reproduce

Create an Enum and try to configure coverage in a TestCase.

Expected behavior

I can configure coverage for an Enum on my TestCases.

Maybe with specific attributes like coversEnum and usesEnum, but the ...Class attributes might work just fine if they accept enums.

@sebastianbergmann sebastianbergmann self-assigned this Feb 7, 2025
@sebastianbergmann sebastianbergmann changed the title Unable to configure coverage for Enums in 12.0 Support targetting enumerations for code coverage Feb 7, 2025
@sebastianbergmann
Copy link
Owner

I keep forgetting that enumerations in PHP are more than just enumerations, sorry. Are you telling me that enumerations could be targetted with CoversClass and UsesClass in PHPUnit 10 and PHPUnit 11? If so, this would indeed be a regression in PHPUnit 12.

@doppynl
Copy link
Author

doppynl commented Feb 7, 2025

No need to be sorry, it happens. PHPUnit 12 already found a couple of minor issues in my testcode that are now fixed.

I used coversClass and usesClass for a couple of Enums in PHPUnit 11 without any problems. (not sure about 10, but I guess the same).

I've no problem with changing the configuration to something new/different, but right now it appears it isn't possible to configure coverage for enums at all in PHPUnit 12.

@sebastianbergmann
Copy link
Owner

Okay, this is a regression then.

@sebastianbergmann sebastianbergmann transferred this issue from sebastianbergmann/phpunit Feb 7, 2025
@sebastianbergmann sebastianbergmann changed the title Support targetting enumerations for code coverage Enumerations cannot be targeted for code coverage Feb 7, 2025
@sebastianbergmann
Copy link
Owner

Should have been fixed by 68403fa. I have released version 12.0.1 of this library with that change.

@doppynl
Copy link
Author

doppynl commented Feb 7, 2025

Confirmed it is now working fine for me.
Thnx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants