How to link a php-unit artifact report to SonarQube's coverage scan?

Must-share information (formatted with Markdown):

  • Enterprise Edition - Version 9.7.1 (build 62043)
  • I’m trying to get SonarQube to display my code coverage for my laravel project thanks to the to-be-continuous/php php-unit job that creates artifacts with the test results and the coverage results
  • I have tried multiple paths for the sonar.php.tests.reportPath and sonar.php.coverage.reportPaths parameters

In the gitlab-ci job, if before launching the sonar-scanner job I do a “ls /src” I get my reports :

  • $ ( # collapsed multi-line command
  • $ ls src/reports
  • php-coverage.clover.xml
  • php-coverage.cobertura.xml
  • php-test.xunit.xml
  • $ sonar-scanner

However no matter what I do, Sonar can’t seem able to find them since I always get this result :

  • ERROR: An error occurred when reading report file ‘/src/php-coverage.clover.xml’, nothing will be imported from this report. IOException: /src/php-coverage.clover.xml (No such file or directory)

(replace /src/php-coverage.clover.xml by a lot of options as said before such as /php-coverage.clover.xml, src/php-coverage.clover.xml etc…)

to-be-continuous/php does have a SonarQube analysis section however, this doesn’t seem to work for me (to be continuous... / PHP · GitLab)

Would anyone happen to know what I overlooked to fix that issue please ?

PS : I have a coverage of 100% on the php-unit test so that proves that the issue isn’t php-unit related

Hey there.

It loosk like your report isn’t under src, but src/reports, so you should make sure you’re pointing to the subdirectory.

:warning: Make sure you upgrade to SonarQube v9.9 LTS soon, not only to benefit from our Best LTS Ever™, but because soon we will stop answering questions for lower versions of SonarQube, which are now considered unsupported.

Hello Colin,

Indeed I don’t know why I didn’t see that while I litterally typed the “pwd” and “ls” commands, thanks a lot for your help.
I’ll also ask if the people handling Sonar and its version if they can upgrade it as you said.

Best regards.

1 Like