No code coverage with phpUnit

Hi,

I Use Sonar(Cloud) with PHPUnit for a OSS project.

I build my code coverage in ./build/reports/phpunit.coverage.xml but when Sonar read the XML file, he said :

2020-06-16T06:20:03.5434083Z INFO: Analyzing PHPUnit test report: ./build/reports/phpunit.xml
2020-06-16T06:20:03.5565845Z INFO: Analyzing PHPUnit coverage report: ./build/reports/phpunit.coverage.xml
2020-06-16T06:20:03.5624504Z WARN: Could not resolve 5 file paths in phpunit.coverage.xml, first unresolved path: /home/runner/work/JunitXml/JunitXml/src/JunitXmlTestCase.php

But the path is correct and availaible on GitHub Actions.

Any ideas ?

Best regards.

Perhaps a relatif VS absolute path issue ? All my path are absolute.

Hey Guillaume,

Sorry for the late reply here.

The problem is that the sonar scanner is run in an environment where the project lies in β€œ/github/workspace/”.
The sonarcloud-github-action action starts the scanner in a docker container and the Github worker mounts the project to β€œ/github/workspace/” in the started docker containers.
On the contrary, the tests are run in an environment where β€œ/home/runner/work/{repo-name}/{repo-name}” is the project path. This is the default ubuntu working directory the Github worker runs in and the checkout action loads the files to. When the worker starts a container it mounts that workspace directory to β€œ/github/workspace/”.

One possible solution is to adapt the paths in the generated coverage file before the SonarCloud action is run. Example: Code coverage doesn't work with GitHub action

I hope that helps!

Best,
Karim.

4 Likes

Thx ! It’s work fine now !!! I have a 100% coverage :slight_smile:

Thanks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.