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's --only-covering-test-cases
flag does not work correctly on PHPUnit 10
#1825
Comments
Same here shlinkio/shlink-config#25. This one is a farely smaller project, but the score has dropped from around 90% to 70% and they are also false positives. |
I could not reproduce the problem. On PHPUnit 9.6.3 I'm looking at:
After running
There is no difference whatsoever. If not like this, how can we reproduce the issue? |
What I'm doing in order to avoid running the tests twice is first run phpunit like this:
And then run infection like this:
The code coverage is generated with |
Well that's peculiar indeed. If I do this after checking out https://github.com/shlinkio/shlink-config:
I get:
And if I do this afterwards:
I get:
|
@sanmai how did you run infection in the first try, when you were getting the same results both with PHPUnit 9 and 10? |
I run the following script:
In both cases I got the same result. Infections makes a bunch of configuration tweaks to make PHPUnit work best (for example), and I suspect some of them changed the default values between PHPUnit 9 and 10. I'd say you can fix this issue if you can figure what was changed. |
Ok, I found the reason. If I remove the |
Sound like it's a bug after all. |
Script to reproduce: git clone git@github.com:shlinkio/shlink-config.git && cd shlink-config
composer require -W --dev phpunit/phpunit:^9
./vendor/bin/infection -j4 --only-covering-test-cases
composer require -W --dev phpunit/phpunit:^10
php vendor/bin/phpunit --migrate-configuration
./vendor/bin/infection -j4 --only-covering-test-cases --- PHPUnit 9
+++ PHPUnit 10
@@ -1,14 +1,14 @@
27 mutations were generated:
- 23 mutants were killed
+ 19 mutants were killed
0 mutants were configured to be ignored
0 mutants were not covered by tests
- 4 covered mutants were not detected
+ 8 covered mutants were not detected
0 errors were encountered
0 syntax errors were encountered
0 time outs were encountered
0 mutants required more time than configured
Metrics:
- Mutation Score Indicator (MSI): 85%
+ Mutation Score Indicator (MSI): 70%
Mutation Code Coverage: 100%
- Covered Code MSI: 85%
+ Covered Code MSI: 70% This flag was added in #1539 @maks-rafalko, can you see if you can make sense of this problem? |
Unfortunately, I can look into it not earlier than the end of the week, so if it's urgent, feel free to help ;) I'm pretty sure something has changed in PHPUnit 10 in the way how it treats infection/src/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilder.php Lines 84 to 111 in aaae66a
I would (or will) start debugging from this place. What we can do is to generate |
There's no such thing as "urgent" in the open source world. I'm not expecting this to be done quickly just because I reported it. Now that I know what it is, the workaround is very easy. I can afford the performance impact of removing that flag for now, and I could also stick with PHPUnit 9 for a bit longer. In any case, running the debug command is something I can definitely do to provide a bit more clarity. |
I have run infection with both PHPUnit 9 and 10, in https://github.com/shlinkio/shlink-config, including These are the generated logs: |
for the provided logs, we can see that for the ecaped mutant: 1) /app/src/Factory/DottedAccessConfigAbstractFactory.php:44 [M] InstanceOf_
- if (!is_array($array) && !$array instanceof ArrayAccess) {
+ if (!is_array($array) && !false) { there are different number of tests executed. PHPUnit 9:
and PHPUnit 10
From what I see, it happens because I assume that the command line, generated for PHPUnit 10 is not recognized by PHPUnit 10, that's why it executes less tests (and as a result kill less mutants). We generate this |
<coverage>
<line nr="9">
<covered by="ExampleTest\Test\SourceClassTest::test_hello#First"/>
<covered by="ExampleTest\Test\SourceClassTest::test_hello#Second"/>
</line>
</coverage> I can confirm PHPUnit 10 is now differently generates PHPUnit 10 itself does not work with this format, so this doesn't work
while the following old format works
Or, it can be a bug of PHPUnit 10? As I can see |
--only-covering-test-cases
flag does not work correctly on PHPUnit 10
@acelaya please use |
Thanks! |
I have just tried it, and even thought it's not as bad as it was, I'm afraid there's still a drop in percentage of killed mutants when using that flag. On the project I have first tried:
I can share reports this afternoon if needed. |
yes please, probably there is another bug |
@acelaya is it in https://github.com/shlinkio/shlink-installer repository? |
No, sorry. I was testing it on https://github.com/shlinkio/shlink, which is a larger repository. These are the logs when running infection with |
@acelaya is this issue still relevant with the latest Infection? |
I'm updating a project to PHPUnit 10, and with that version, infection reports 42% of killed mutants, while it reports 90% with PHPUnit 9.6
I have even manually applied some of the mutants reported as "not killed", and then the tests no longer pass, so these are false positives.
The text was updated successfully, but these errors were encountered: