PHP sonar.php.tests.reportPath

I proceed with documentation: https://docs.sonarqube.org/latest/analysis/coverage/ and pass that settings in sonar-project.properties file

php.sonar.php.tests.reportPath=coverage-result.xml
php.sonar.php.coverage.reportPaths=execution-result.xml

When I run scanner I get:

INFO: Analyzing PHPUnit test report: execution-result.xml
INFO: Analyzing PHPUnit coverage report: coverage-result.xml

so I don’t have any warnings. But on main page of SonarQube I don’t have something similar like here:


on right bottom corner: Failures, Errors, Tests, Execution Time.
Did I doing something wrong, or I have to search those results something else place?

EDIT:
I used that PHPUnit documentation: https://phpunit.readthedocs.io/en/9.3/textui.html

vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage-result.xml --log-junit=execution-result.xml

Hi @LocalHeroPro,

Thanks for getting in touch with us.
Which SonarQube version do you use?
The picture you use as an example here shows an older SonarQube version.

Cheers,
Nils

  • Community Edition
  • Version 8.4.2 (build 36762)
    brand new install.

So, how to fill up selected - by blue color - Unit Tests?

Hi @LocalHeroPro ,

I have tried to reconstruct the problem. Can you check if you have explicitly specified where your test files are located using sonar.tests? I admit that this is not additionally written in the documentation.

Here is my example file:

sonar.sources=src
sonar.php.tests.reportPath=execution-result.xml
sonar.php.coverage.reportPaths=coverage-result.xml
sonar.tests=tests

Cheers,
Nils

Hi,
Thanks for replay.
In sonar=project.properties I have (among others):

sonar.sources=./app
sonar.php.coverage.reportPaths=phpunit-coverage-result.xml
sonar.php.tests.reportPath=phpunit-execution-result.xml

So I don’t have last line from your replay. Can you explain what sonar.tests that means?

I’m trying to point sonar.tests to folder with tests by pointing to ./tests or tests, but after running some tests, nothing changed with count of Unit tests on Overall Code tab.
In bash log I have:

INFO: Analyzing PHPUnit test report: phpunit-execution-result.xml
INFO: Analyzing PHPUnit coverage report: phpunit-coverage-result.xml

So I guess, files are imported successfully and Sonar understood them ;]

As mentioned in the documentation, sonar.tests should be set with “comma-separated paths to directories containing test source files”. With this property, your test files can be imported in SonarQube and treated as such. In particular, they can be scanned by test-related rules. SonarQube only displays test execution results for files which are imported as test files.

If you still don’t see test execution results, try running the analysis with debug logs:

sonar-scanner -X

You may then see logs such as:

DEBUG: Following file is not located in the test folder specified in the Sonar configuration: /home/user1/myproject/tests/MyTest.php. The test results won't be reported in Sonar.

Nope, I can’t see anything interesting in that debug output:

// ...
23:00:24.439 INFO: 235/235 source files have been analyzed
23:00:24.440 INFO: Analyzing PHPUnit test report: phpunit-execution-result.xml
23:00:24.490 INFO: Analyzing PHPUnit coverage report: phpunit-coverage-result.xml
23:00:24.490 DEBUG: Parsing file: /var/www/cpt.local/html/phpunit-coverage-result.xml
23:00:24.554 INFO: Sensor PHP sensor [php] (done) | time=7089ms
23:00:24.554 INFO: Sensor Analyzer for "php.ini" files [php]
23:00:24.558 INFO: Sensor Analyzer for "php.ini" files [php] (done) | time=4ms
// ...

I’m still looking what is going wrong.

Right now with:

  1. SonarQube 9.1 (build 47736)
  2. SonarScanner 4.6.2.2472
  3. PHP 8.0.14
  4. PHPUnit 9.5.10
    XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover=phpunit-coverage-result.xml --log-junit=phpunit-execution-result.xml
  5. File sonar-project.properties
    sonar.projectBaseDir=.
    sonar.sources=app
    sonar.tests=tests
    sonar.php.coverage.reportPaths=phpunit-coverage-result.xml
    sonar.php.tests.reportPath=phpunit-execution-result.xml

it’s works! I can see for example: execution time results in main branch, not in PR.

Great. Glad to hear it’s finally working. Thanks for sharing the update and your settings.
This might help other users now as well.

Best,
Nils

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