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

Disable certain mutators for certain lines #79

Closed
GaryJones opened this issue Nov 18, 2017 · 2 comments
Closed

Disable certain mutators for certain lines #79

GaryJones opened this issue Nov 18, 2017 · 2 comments

Comments

@GaryJones
Copy link

Question Answer
Infection version 0.6.1
Test Framework version PHPUnit 6.4.4
PHP version 7.1.7
Platform MacOS
Github Repo -

For WordPress, callback methods hooked into the actions or filters need to be public.

The Function Signature mutator naturally tries to change the callback from public to protected, and flags it as a "not covered mutant".

Is there any way (to reduce known false positives) to specify that a method really should stay public, either by adding a line comment (e.g. // infection:disable FunctionSignature) or by adding an exclusion (file and line number? class and method name?) to infection.json.dist?

@GaryJones
Copy link
Author

Perhaps an obvious workaround - make sure you have a unit test that calls the public method. When this mutates to protected, the test will no longer be reported as "not covered".

@maks-rafalko
Copy link
Member

maks-rafalko commented Nov 18, 2017

Hello,

Disable certain mutators

This is really my one of the most wanted feature. Let's start discussing a possible implementation.

The first thought was the same - add something like other tools add in PHP and JS world:

// tslint: disable-next-line
...
// infection:disable FunctionSignature

but now I don't like this idea because

  1. it pollutes the code with 3rd-party tools related comments
  2. these comments can be outdated if a tool has been removed from particular project/not used anymore.

I like the idea of PHPStan -https://github.com/phpstan/phpstan#ignore-error-messages-with-regular-expresions.

They use patterns/regular expressions on the config level to skip/ignore some issues during analyzing.

We can use this idea and implement something similar, for example:

Ignore mutators for some class

// infection.json
{
    "mutators": {
        "ignore": {
             "PublicVisibility": [
                  "Ignore\For\Particular\Class",
                  "Ignore\For\Another\Class::method",
                  //  ...
                  "Ignore\For\**\*\Glob\Pattern\Or\Namespace"
             ]
        }
    }
}

Also, I think keeping the exact line number in the "ignore config" is a bad idea because line numbers change quite often

What I also like and want to have from PHPStan is the behaviour of notifying users when some of the ignored classes/methods for mutants are no longer exist (see https://github.com/phpstan/phpstan#ignore-error-messages-with-regular-expresions): for example if the Some\Class::method is ignored for a set of Mutation Operators and after some time is removed - Infection should notify developer that this method is no longer exist and the config should be updated

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

No branches or pull requests

3 participants