Sonarcloud not picking up line coverage from coverage.xml

Template for a good new topic, formatted with Markdown:

  • CI system used Circle CI
  • Scanner command used when applicable: sonarcloud/scan
  • Languages of the repository: PHP

sonarCloudLogs.txt (19.5 KB)

  • Error observed : no error
    Workflow:
 units-tests:
    <<: *test
    working_directory: ~/project
    steps:
      - checkout
      - run:
          name: Install dependencies
          command: composer install --no-scripts --no-interaction
          working_directory: symfony

      - save_cache:
          paths:
            - ./symfony/vendor
          key: v1-dependencies-{{ checksum "symfony/composer.json" }}-{{ checksum "symfony/composer.lock" }}

      - run:
          name: launch unit-tests
          command: |
            ./vendor/bin/phpunit ./tests --coverage-clover=coverage/coverage.xml --log-junit=reports/test-report.xml
          working_directory: symfony

      - run:
          name: fix coverage files
          command: |
              sed -i 's@/root/project@/home/circleci/project@g' coverage/coverage.xml
              sed -i 's@/root/project@/home/circleci/project@g' reports/test-report.xml
          working_directory: symfony

      - run:
          name: Copy reports to project directory
          command: |
            mkdir -p ~/project/coverage
            mkdir -p ~/project/reports
            cp symfony/coverage/coverage.xml ~/project/coverage/
            cp symfony/reports/test-report.xml ~/project/reports/

      - persist_to_workspace:
          root: ~/project
          paths:
            - coverage/coverage.xml
            - reports/test-report.xml

  sonarcloud:
    executor: ubuntu-22-04
    steps:
      - checkout
      - attach_workspace:
          at: ~/project
      - run:
          name: Prepare and Copy Reports
          command: |
            mkdir -p ~/project/symfony/coverage
            mkdir -p ~/project/symfony/reports
            mv ~/project/coverage/coverage.xml ~/project/symfony/coverage/
            mv ~/project/reports/test-report.xml ~/project/symfony/reports/

      - sonarcloud/scan

Steps to reproduce:
We have set up a project using PHPUnit to display code coverage in SonarCloud via GitHub Actions, and it works fine. However, after migrating the workflow to CircleCI, the code coverage percentage is not being displayed.

Potential workaround;
No workaround found

Hey there.

INFO: Importing /home/circleci/project/symfony/coverage/coverage-report.xml
ERROR: An error occurred when reading report file '/home/circleci/project/symfony/coverage/coverage-report.xml', nothing will be imported from this report. IOException: /home/circleci/project/symfony/coverage/coverage-report.xml (No such file or directory)

It looks like the coverage file doesn’t exist where the scanner is expecting it.

If you run a cat /home/circleci/project/symfony/coverage/coverage-report.xml right before the SonarCloud scan, does the file appear?

covergae.txt (659.7 KB)
sonarCloudLogs.txt (19.6 KB)
hey,
Report not found because i forget to modify path in file sonar.properties
there is the new logs of sonar and file coverage.xml

I merged my branch into the main branch, where the coverage file had a .clover extension. In another branch, I modified the extension of this file to .xml. Could file extension be the cause of the problem?

The expected format is an XML file, and the file name should be whatever value you’ve passed to sonar.php.test.reportPaths

Based on the logs you’ve shared, the coverage report is importing correctly and the only file paths not resolved are the ones you excluded from analysis.

INFO: Importing /home/circleci/project/symfony/reports/test-report.xml
WARN: Failed to resolve 1 file path(s) in PHPUnit tests test-report.xml report. Nothing is imported related to file(s): /home/circleci/project/symfony/tests/Unit/Application/Facade/EventPayloadDenormalizer/DeliverectMenuPushPayloadDenormalizerTest.php
INFO: Importing /home/circleci/project/symfony/coverage/coverage.xml
WARN: Failed to resolve 2 file path(s) in PHPUnit coverage coverage.xml report. Nothing is imported related to file(s): /home/circleci/project/symfony/src/Infrastructure/Repository/Transfer/TransferStatRepository.php;/home/circleci/project/symfony/src/Kernel.php
INFO: Sensor PHPUnit report sensor [php] (done) | time=249ms

Are things in working order now?

Should I merge my branch into the main branch? the results on my branch are reported in .xml format and coverage is always not displayed

Hey there.

I really don’t know enough about your project to tell you what to do here.

In one build, your coverage report appears to not be read (the file isn’t found)
In another build, the file is found and read inappropriately, although information about 2 excluded files isn’t read in.

You probably want to make sure that all your branches fall into that second case.