The plugin enables analysis of PHP projects within SonarSonarQubeTM.
It is compatible with the Issues Report plugin to run pre-commit local analysis.
- Install the PHP Environment
- Install the Sonar PHP plugin through the Update Center or download it into the SONAR SONARQUBE_HOME/extensions/plugins directory
- Restart the Sonar SonarQubeTM server
SonarQubeTM Analysis with the Sonar Runner (Recommended Way)
To launch a Sonar run an analysis of your PHP project, use the Sonar Runner.
You can also have a look at the Sonar Runner documentation page to define a multi-module PHP project.
SonarQubeTM Analysis with the other Analyzers
sonar.phpPmd.skip=true sonar.phpCodesniffer.skip=true sonar.phpDepend.skip=true # Deactiving the PHP Depend plugin is highly discouraged since all the basic metrics rely on it. sonar.phpUnit.skip=true sonar.phpUnit.coverage.skip=true
Configuring PHPUnit to be run by
To configure the execution of PHPUnit, it is recommended to create a configuration file and set the path to this file with the
If a configuration file is not used, the following property can be set to configure the execution of PHPUnit:
If true, PHPUnit will ignore any phpunit.xml file for launching the unit tests.
The project main test file including the relative path, ie: "/source/tests/AllTests.php". If not present, PHPUnit will look for phpunit.xml file in the test directory.
Ignore the unit tests files matching this pattern.
Use this bootsrap file to initialize the unit tests.
If true, Sonar PHP it will append test directory to PHPUnit. This will make PHPUnit look for test cases inside this directory. If several directories are defined as test directories, a phpunitRANDOM.xml file will be generated and passed to phpunit --configuration=. This generated file will contain all files inside the test directories.
|sonar.phpUnit.group||Only runs tests from the specified group(s).|
|sonar.phpUnit.loader||To specify which TestSuiteLoader implementation to use.|
Most of the time, using the sonar.exclusions property exclusion properties will be enough to exclude files from being reported by SonarSonarQubeTM. However, there might be some cases where you really want to exclude files from being analyzed by an external tool (may it be PHP CodeSniffer, PHPMD or PHP Depend):
- a file is badly written and the tool is crashing when analyzing this file, thus preventing Sonar SonarQubeTM from completing the analysis
- a big number of files must be excluded and there's no need for the external tools to spend time analyzing files that won't be reported in SonarSonarQubeTM
For these specific cases, you should use the
sonar.xxxx.argumentLine property of the external tool to manually define exclusions. For instance, for PHP CodeSniffer, you would add the following property: