SonarQube PHP no code coverage

2.2k views Asked by At

We're using jenkins with SonarQube to perform code analysis on our php projects. We now generate the phpunit coverage files on different server and want to load these coverage files into SonarQube. The problem is that the coverage files are there and seem to be loaded in SonarQube but the code coverage in SonarQube is still empty. Interesting is the line after the code coverage files are loaded:

INFO  - Project: null

Pretty much the same error was described on the old sonar mailinglist in this post: http://sonarqube.15.x6.nabble.com/PHPUnit-test-coverage-from-PHPUnit-not-being-picked-up-with-Giving-Project-null-error-tc5028771.html#none

Full runner log:

INFO: Runner configuration file: /opt/sonar-runner/conf/sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: /var/lib/jenkins/jobs/FooBarJob-Dev/workspace/.sonar
INFO: SonarQube Server 5.0
INFO  - Load global referentials...
INFO  - Load global referentials done: 297 ms
INFO  - User cache: /var/lib/jenkins/.sonar/cache
INFO  - Install plugins
INFO  - Install JDBC driver
INFO  - Create JDBC datasource for jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
INFO  - Initializing Hibernate
INFO  - Load project referentials...
INFO  - Load project referentials done: 1514 ms
INFO  - Load project settings
INFO  - Loading technical debt model...
INFO  - Loading technical debt model done: 30 ms
INFO  - Apply project exclusions
INFO  - -------------  Scan FooBarJob
INFO  - Load module settings
INFO  - Language is forced to php
INFO  - Loading rules...
INFO  - Loading rules done: 1442 ms
INFO  - Configure Maven plugins
INFO  - Compare to previous analysis (2015-06-18)
INFO  - Compare over 30 days (2015-05-19, analysis of 2015-06-18 08:18:26.0)
INFO  - No quality gate is configured.
INFO  - Base dir: /var/lib/jenkins/jobs/FooBarJobDev/workspace
INFO  - Working dir: /var/lib/jenkins/jobs/FooBarJob-Dev/workspace/.sonar
INFO  - Source paths: src/main
INFO  - Test paths: src/main/php/FooBarJob/Tests
INFO  - Source encoding: UTF-8, default locale: en_US
INFO  - Index files
INFO  - Excluded sources: 
INFO  -   **/Tests/**
INFO  -   **/Tests/**
INFO  - Included tests: 
INFO  -   **/Tests/**
INFO  - 48 files indexed
INFO  - Quality profile for php: Sonar way
INFO  - Sensor NoSonar and Commented out LOC Sensor...
INFO  - Sensor NoSonar and Commented out LOC Sensor done: 156 ms
INFO  - Sensor QProfileSensor...
INFO  - Sensor QProfileSensor done: 6 ms
INFO  - Sensor org.sonar.plugins.php.PHPSquidSensor@118b47dc...
INFO  - Sensor org.sonar.plugins.php.PHPSquidSensor@118b47dc done: 1984 ms
INFO  - Sensor PHPUnit Sensor...
INFO  - Analyzing PHPUnit tests report: var/phpunit.xml
INFO  - Analyzing PHPUnit coverage report: var/coverage.xml
INFO  - Project: null
INFO  - Sensor PHPUnit Sensor done: 1507 ms
INFO  - Sensor InitialOpenIssuesSensor...
INFO  - Sensor InitialOpenIssuesSensor done: 127 ms
INFO  - Sensor ProjectLinksSensor...
INFO  - Sensor ProjectLinksSensor done: 15 ms
INFO  - Sensor VersionEventsSensor...
INFO  - Sensor VersionEventsSensor done: 40 ms
INFO  - Sensor FileHashSensor...
INFO  - Sensor FileHashSensor done: 114 ms
INFO  - Sensor SCM Sensor...
INFO  - Sensor SCM Sensor done: 125 ms
INFO  - Sensor CPD Sensor...
INFO  - DefaultCpdEngine is used for php
INFO  - Cross-project analysis disabled
INFO  - Sensor CPD Sensor done: 373 ms
INFO  - Execute decorators...
INFO  - Store results in database
INFO  - ANALYSIS SUCCESSFUL, you can browse https://localhost/sonar/dashboard/index/com.barComp:FooBarJob
INFO  - Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report.
INFO  - Executing post-job class org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob
1

There are 1 answers

2
Pierre-Yves On

A coverage file contain paths to source files and these paths should be absolute. If you generate the phpunit coverage files on one server and launch the SonarQube analysis on another server, the absolute paths are quite likely to be different. Paths which cannot be resolved when loading a coverage file are ignored.

One more thing: the last version of the SonarQube PHP plugin (2.6) gives you logs which are a bit more helpful for this kind of issue.