Coverage is not always correctly updated

I use SonarQube Community Version 8.9 and sonar-scanner 4.3.0.2102.
The project I am testing is mainly in PHP.
The coverage data is not always correctly updated. Sometimes it works, sometimes it does not.
Not sure how to reproduce it as it seems to work sometimes.
I put an image to show the abnormal huge differences between scans via sonar-scanner.
Here we pass from 59,7% to 2,5% at the end of this graphic …

The only “workaround” I use currently is …relaunch sonar-scanner (sometimes relaunching my tests suites also via PHPStorm, not knowing why it does not work).

Does someone have already experienced that problem ?
(I precise that the coverage is correctly indicated in PHPStorm)

Edit
In fact, I have some problems to reproduce it as I have now problems that removes my coverage.xml report to send. Maybe I will remove that post (if possible) if this bug goes away when I will solve the other problem.

1 Like

Today, for example, the ̀sonar-scanner` command reports this :

WARN: Could not resolve 48 file paths in coverage.xml, first unresolved path: […]

The mentioned file exists so I do not understand what is wrong, but it surely is related to this problem.

Hi,

Those log messages indicate that the paths in your coverage report don’t match up with the paths in the project as SonarQube sees them.

Since this is intermittent, I’m wondering if it’s traceable to one (or more) specific build agents. Perhaps the process runs slightly differently on agentC than it does on agentA & agentB?

 
Ann

In fact, it has been a long time that I have such problems so I begin to think that it is not intermittent now.
No clue why SonarQube sees those paths differently.
sonar-scanner only uses configuration on my computer or it uses configuration from the server UI too? Maybe it is a conflict between to the two configurations?

Hi,

Is the coverage report generated in the same place analysis runs from or is it created and then moved around?

Care to share your analysis logs (starting from/including the analysis command) and some paths in your report?

 
Ann

The reports are generated via PHPStorm in [myProjectPath]/tests/coverage.xml and [myProjectPath]/tests/report.xml. The scanner is launch from [myProjectPath]/. I do not move reports files.

I’m on another topic right now, but I will put the logs of sonar-scanner soon.

Hi @lperamo,

I would agree with Ann that it is probably because the reports are created differently. I would recommend to create the test report and coverage reports directly with PHPUnit and not via the IDE. This way you can make sure that they provide a reproducible result.

Best,
Nils

My command /usr/bin/php -dpcov.enabled=1 /var/www/html/lib/phpunit.phar --coverage-clover /home/lionel/.cache/JetBrains/PhpStorm2021.2/coverage/otra@Tests___All_tests_suites.xml --bootstrap /var/www/html/perso/otra/tests/testBootstrap.php --configuration /var/www/html/perso/otra/tests/phpunitAll.xml --teamcity for tests.
My command for sonar sonar-scanner.
Those commands are executed from the root path of the project.
sonar-log.txt (7.6 KB)
I can put the PHPUnit log if needed.

It seems it has worked this time (do not know if it works “completely”) but it is close to what I have.
Not sure exactly what the difference is comparing to PHPStorm calculations but PHPStorm indicates 80% for files and 64% lines for the src folder and SonarQube indicates only 55.1%.

Hi @lperamo ,

thank you for this information.
PHPStorm runs PHPUnit with the --teamcity argument to be able to process the output. This format differs from the default output processed by SonarQube. Here it can come to the problems that lines are indicated, which do not occur in the file itself. Example: “Line with number 165 does not belong to file routesTask.php”.

To your other question about the differences in the coverage specification:
Do you run the coverage checks in PHPStorm with tracing?
That means that for example it is checked if every combination of conditions can be true or false. In the SonarQube evaluation this is taken into account. This can lead to this difference. You also have to consider where you take the coverage information from. Is the 55.1% for new code or for the whole project?

Best,
Nils

When I want to have test coverage, I always launch PHPStorm with the “coverage button” even if I have xdebug.mode=debug,coverage in my php.ini file to ensure at 100% that I will really have that coverage ^^.
When I talked about 55.1%, I talked about the overall code.