Skip to content
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

Infection reports mutations on impossible to cover parts: PHP Attributes #1910

Open
niconoe- opened this issue Jan 17, 2024 · 5 comments
Open
Labels

Comments

@niconoe-
Copy link
Contributor

Question Answer
Infection version 0.27.8
Test Framework version PHPUnit 10.5.7
PHP CodeCoverage version 10.1.11
PHP version 8.2.8
XDebug version 3.2.2
Platform Ubuntu

Hello people!

I don't know if that's already detected in another issue, but I'm having a trouble with mutants tagged "Not covered", on PHP Attributes definitions, even if I actually have PHP Unit tests about it.

You can have a example here: https://infection-php.dev/r/0544

I think that the problem is PHP CodeCoverage is not taking care about PHP Attributes, so PHP Infection considers this part not being covered. I don't know how this could be solved, but it's clearly an issue because all of these mutations should have been killed by the unit tests, therefore the MSI score is lowered for no valid reasons.

Thanks a lot!

@theofidry
Copy link
Member

If you execute it with --only-covered do you still encounter the problem?

@maks-rafalko
Copy link
Member

Please see this workaround #1894 (comment) - you can disable mutation of attributes for now.

@niconoe-
Copy link
Contributor Author

Thanks for your answers.

@maks-rafalko Thank you for the proposal to ignore via RegExp, but I'm using a forced global configuration file for PHP Infection across multiple projects to ensure they have the exact same standards quality, and I don't want to have some specific project ignorance here, I'm looking for a solution I can use globally. Nevertheless, that's good to know, and if I need that, I'll keep in mind!

@theofidry Using --only-covered works like a charm! I'll add this to ignore all uncovered snippets on all my projects as I'm already checking the code coverage directly via PHPUnit's reports. I'll use your solution then.

I don't know if you guys want to get further on this, as the proposed solutions are only about ignoring PHP Attributes, but IMO, it makes perfect sense to mutate them and give it a try, as they have a direct impact on runtime. Is there any ideas or actions you got to make them declared as covered or something? or do you think it should be on PHP's CodeCoverage to stop ignoring them?

Thanks a lot again and have a good day!

@maks-rafalko
Copy link
Member

maks-rafalko commented Jan 18, 2024

We didn't think a lot through it and didn't discuss it yet, but I agree - it would be very nice to mutate attributes properly, with coverage supported.

I had an idea to create symfony/doctrine related mutators to

  • change validation rules
  • remove validation rules
  • change doctrine mappings
  • etc.

Regarding where the issue is - on CodeCoverage or Infection side - I don't know, needs to be investigated. So any help would be appreciated :)


If it won't be supported on CodeCoverage side, the only one way I see is to do the same as we do for parameters: as soon as the method is executed - its attributes are "executed" as well, so are treated as covered. And we can get this information from the phpunit's reports we are using.

@niconoe-
Copy link
Contributor Author

Symfony/Doctrine mutators are a good idea for a good usage of them, I definitly agree about it, but the mutations on PHP Attributes are more global than just them: in my example, I used a custom PHP Attribute, not a Symfony/Doctrine or whatever library's from.

I'm not sure I'm valuable in front of Sebastian Bergmann to tell him that PHP Attributes must be covered 😅 but I really do think it should be on coverage side: like I said, PHP Attributes are impacting runtime behaviors, they're not just definitions. And I guess that as soon as coverage will tell you PHP Attributes are (or not) covered instead of being ignored, PHP Infection will automatically be ready to handle them. That's why I'm convinced it should be an enhancement on CodeCoverage's side.

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

3 participants