8000 Ignore switch(bool) statements in TrueValue and FalseValue mutators. by shanept · Pull Request #1986 · infection/infection · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ignore switch(bool) statements in TrueValue and FalseValue mutators. #1986

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

Merged
merged 1 commit into from
Jun 21, 2024

Conversation

shanept
Copy link
Contributor
@shanept shanept commented Jun 20, 2024

This PR:

Fixes #819

This will stop false positives related to boolean values in switch conditions, where no code coverage has been detected.

@shanept
Copy link
Contributor Author
shanept commented Jun 20, 2024

NOTE: The test cases could probably use particular attention. My test cases are asserting that switch statements are NOT mutated. I am not familiar with the Infection codebase, and could not find equivalent test cases or assertions to base mine upon, so it may or may not need massaging. All test cases behave as I would expect, otherwise.

Here, specifically, is how I have accomplished this assertion:

final protected function assertInputNotMutated(string $inputCode, array $settings = []): void
{
$inputCode = StringNormalizer::normalizeString($inputCode);
$mutants = $this->mutate($inputCode, $settings);
$this->assertCount(0, $mutants);
}

PHP;

$this->assertInputNotMutated($inputCode);
}
Copy link
Member
@maks-rafalko maks-rafalko Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, you don't need to create separate method to test the case when no mutation is happening.

Please, look here to get an example:

yield 'It does not mutate the string false to true' => [
<<<'PHP'
<?php
return 'false';
PHP
,
];

so you basically need to create the same yield with switch (false). Thus, new created method assertInputNotMutated can also be removed

Copy link
Member
@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks. After tests are fixed, happy to merge it

@maks-rafalko maks-rafalko enabled auto-merge (squash) June 20, 2024 21:05
auto-merge was automatically disabled June 21, 2024 00:15

Head branch was pushed to by a user without write access

@shanept
Copy link
Contributor Author
shanept commented Jun 21, 2024

Thanks for the feedback @maks-rafalko. I had a feeling there was a better way...
Tests modified as per your instructions, and all the extra test code was removed.

Copy link
Member
@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @shanept

@maks-rafalko maks-rafalko merged commit a8510c1 into infection:master Jun 21, 2024
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive uncovered mutant with switch(true) and switch(false)
2 participants
0