SonarQube is a code coverage tool that provides reasonable insight into the reports generated by your test suite and test cases. I have been planning on applying the DDL concept on my next PHP projects.
For that I needed a mainstream testing suite and I found that in PHPUnit. It is a remarkable tool if you want to write tests for PHP.
I will not go into details about PHPUnit since it will be off topic but we will need coverage and test reports for our PHP project to work with SonarQube. You can generate coverage reports through the –coverage-clover flag and test log/report using –log-junit. Both will be in xml format.
Next wherever these reports are generated we will need a sonar-project.properties file which will contain following elements:
sonar.projectName=PHP project analyzed with the SonarQube Runner reusing PHPUnit reports
# Reusing PHPUnit reports
All the attributes are easily understood and those which need explaining are:
sonar.sources=src : This is the path of the actual PHP source code files for which the coverage is to be estimated.
sonar.tests=tests : The directory where PHPUnit tests are located.
sonar.php.coverage.reportPath=reports/phpunit.coverage.xml : Path where coverage reports generated through PHPUnit are located
sonar.php.tests.reportPath=reports/phpunit.xml : Path where logs generated through PHPUnit are located
Next we have to download SonarQube and SonarQube Runner from this location:
Unzip both of them at some location like :
Next you will have to start the Sonar Server from the command line. So in windows you navigate to C:\sonarqube\bin\windows-xxx-xx and run SonarStart like so:
After the server has started, do not close the console screen since the server will shut down with it too. Now go to http://localhost:9000 to see if sonar server is running (although you can check it is console too). If it is, you will see the GUI. If it’s not then one of the reasons might be that the port 9000 is being used by some other application and in that case you will have to change the default port from C:\sonarqube\conf]sonar.properties to some other and start the server again.
If it all worked out for you then the only step that remains is analyzing the project through SonarQube Runner. For that open up another console and navigate to project that has sonar-project.properties, tests directory, report.xml and coverage.xml. Run command sonar-runner and it will analyze the project and show execution results on console. Now, to see the analysis results, refresh http://localhost:9000 and you will see you project appearing there.
Latest posts by alexey (see all)
- Zend Soap NULL Reponse - August 29, 2018
- Quick Facts About WooCommerce - April 25, 2018
- WordPress stuck on a “Too many redirects” error loop when using SSL - January 17, 2018