This is a fork from https://github.com/php-pm/php-pm modified to demonstrate the usage of SonarQube in the context of a PHP project.
Modifications compared to the original project:
sonar-project.properties
was added, which is the configuration file for Sonar scanner, the command line tool performing the static code analysisphpunit.xml.dist
was modified to produce log files that can be picked ob by the Sonar scanner to report test coverage metricsVagrantfile
was added to have a clean test environmenttravis.yml
was modified to run the Sonar scanner Docker container
To manually perform an analysis, you can do the following:
- Launch the vagrant box with
vagrant up
- Log into the box
vagrant ssh
- Go to
/project-root
- Run
composer install
- Install Xdebug following these instructions
- Run PHPunit
./vendor/bin/phpunit --verbose -c phpunit.xml.dist
As a result, you should get the files clover.xml
and junit-logfile.xml
in your project root. Note that the Vagrant box is only necessary for testing.
Next, exit the Vagrant box and run the Docker container with the Sonar scanner.
export DOCKERWORKDIR='/project-root';
docker run --rm \
--mount type=bind,source="$(pwd)",target=$DOCKERWORKDIR \
-w=$DOCKERWORKDIR --network=sonar \
sonar-scanner:latest sonar-scanner
Note: setting DOCKERWORKDIR
to /project-root
is important because this is the base directory in which PHPUnit was executed, i.e. file references in clover.xml
use this as the base directory.
Note that the Vagrant box is only necessary for testing the analysis process. Ideally, the analysis is triggered by the CI pipeline. It has been integrated into Travis in this repository, however, it does currently NOT work because there is no running SonarQube instance where to upload the results.