如何使SonarQube PHP插件与PHPUnit一起工作?
我已经安装了jenkins和SonarQube Runner 2.4、SonarQube服务器5.1.2、php插件2.6、PHPUNT5.1 然后我运行独立的sonarqube分析,这是我的配置:如何使SonarQube PHP插件与PHPUnit一起工作?,php,phpunit,sonarqube,Php,Phpunit,Sonarqube,我已经安装了jenkins和SonarQube Runner 2.4、SonarQube服务器5.1.2、php插件2.6、PHPUNT5.1 然后我运行独立的sonarqube分析,这是我的配置: sonar.language=php sonar.projectVersion=1.0 sonar.sourceEncoding=UTF-8 sonar.phpCodesniffer.timeout=120 sonar.projectKey=xxx sonar.projectName=xxxx s
sonar.language=php
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.phpCodesniffer.timeout=120
sonar.projectKey=xxx
sonar.projectName=xxxx
sonar.sources=.
sonar.tests=./tests/tests/
以下是控制台输出:
$ /apps/svr/sonar-runner/bin/sonar-runner -e -Dsonar.projectBaseDir=/home/apps/.jenkins/workspace/pc_dev_example -Dsonar.sourceEncoding=UTF-8 -Dsonar.sources=. -Dsonar.language=php -Dsonar.projectVersion=1.0 -Dsonar.projectKey=php:pc_dev_example -Dsonar.phpUnit.argumentLine="/apps/svr/sonar" -Dsonar.inclusions=applications/vipuser/public/passport.php -Dsonar.phpCodesniffer.timeout=120 -Dsonar.tests=./tests/tests/ -Dsonar.projectName=pc_dev_example
SonarQube Runner 2.4
Java 1.7.0_71 Oracle Corporation (64-bit)
Linux 2.6.32-504.23.4.el6.x86_64 amd64
INFO: Error stacktraces are turned on.
INFO: Runner configuration file: /apps/svr/sonar-runner/conf/sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: /home/apps/.jenkins/workspace/pc_dev_example/.sonar
INFO: SonarQube Server 5.1.2
15:56:42.207 INFO - Load global repositories
15:56:42.471 INFO - Load global repositories (done) | time=267ms
15:56:42.474 INFO - Server id: 20151009151309
15:56:42.477 INFO - User cache: /home/apps/.sonar/cache
15:56:42.490 INFO - Install plugins
15:56:42.634 INFO - Install JDBC driver
15:56:42.642 INFO - Create JDBC datasource for jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
15:56:44.209 INFO - Initializing Hibernate
15:56:45.887 INFO - Load project repositories
15:56:46.582 INFO - Load project repositories (done) | time=695ms
15:56:46.582 INFO - Load project settings
15:56:47.405 INFO - Load technical debt model
15:56:47.432 INFO - Apply project exclusions
15:56:47.697 INFO - ------------- Scan pc_dev_vip_example
15:56:47.702 INFO - Load module settings
15:56:47.862 INFO - Language is forced to php
15:56:47.871 INFO - Load rules
15:56:48.455 INFO - Base dir: /home/apps/.jenkins/workspace/pc_dev_example
15:56:48.455 INFO - Working dir: /home/apps/.jenkins/workspace/pc_dev_example/.sonar
15:56:48.456 INFO - Source paths: .
15:56:48.456 INFO - Test paths: tests/tests
15:56:48.457 INFO - Source encoding: UTF-8, default locale: en_US
15:56:48.457 INFO - Index files
15:56:48.470 INFO - Included sources:
15:56:48.470 INFO - applications/vipuser/public/passport.php
15:56:48.542 INFO - 2 files indexed
15:56:48.542 INFO - 470 files ignored because of inclusion/exclusion patterns
15:56:48.610 INFO - Quality profile for php: Sonar way
15:56:48.736 INFO - Sensor NoSonar and Commented out LOC Sensor
15:56:48.769 INFO - Sensor NoSonar and Commented out LOC Sensor (done) | time=33ms
15:56:48.769 INFO - Sensor Lines Sensor
15:56:48.771 INFO - Sensor Lines Sensor (done) | time=2ms
15:56:48.771 INFO - Sensor QProfileSensor
15:56:48.775 INFO - Sensor QProfileSensor (done) | time=4ms
15:56:48.775 INFO - Sensor InitialOpenIssuesSensor
15:56:48.798 INFO - Sensor InitialOpenIssuesSensor (done) | time=23ms
15:56:48.798 INFO - Sensor ProjectLinksSensor
15:56:48.806 INFO - Sensor ProjectLinksSensor (done) | time=8ms
15:56:48.806 INFO - Sensor VersionEventsSensor
15:56:48.833 INFO - Sensor VersionEventsSensor (done) | time=27ms
15:56:48.834 INFO - Sensor PHPSquidSensor
15:56:48.880 INFO - 1 source files to be analyzed
15:56:49.109 INFO - 1/1 source files have been analyzed
15:56:49.132 INFO - Sensor PHPSquidSensor (done) | time=298ms
15:56:49.132 INFO - Sensor PHPUnit Sensor
15:56:49.132 INFO - No PHPUnit test report provided (see 'sonar.php.tests.reportPath' property)
15:56:49.133 INFO - No PHPUnit unit test coverage report provided (see 'sonar.php.coverage.reportPath' property)
15:56:49.133 INFO - No PHPUnit integration test coverage report provided (see 'sonar.php.coverage.itReportPath' property)
15:56:49.133 INFO - No PHPUnit overall coverage report provided (see 'sonar.php.coverage.overallReportPath' property)
15:56:49.133 INFO - Sensor PHPUnit Sensor (done) | time=1ms
15:56:49.133 INFO - Sensor SCM Sensor
15:56:49.137 INFO - Sensor SCM Sensor (done) | time=4ms
15:56:49.137 INFO - Sensor CPD Sensor
15:56:49.137 INFO - DefaultCpdEngine is used for php
15:56:49.137 INFO - Cross-project analysis disabled
15:56:49.180 INFO - Sensor CPD Sensor (done) | time=43ms
15:56:49.182 INFO - No quality gate is configured.
15:56:49.240 INFO - Compare to previous analysis (2015-10-09)
15:56:49.249 INFO - Compare over 30 days (2015-09-09, analysis of Fri Oct 09 10:02:34 CST 2015)
15:56:49.618 INFO - Execute decorators...
15:56:50.177 INFO - Store results in database
15:56:50.494 INFO - Analysis reports generated in 21ms, dir size=1 KB
15:56:50.504 INFO - Analysis reports compressed in 10ms, zip size=2 KB
15:56:50.552 INFO - Analysis reports sent to server in 48ms
15:56:50.552 INFO - ANALYSIS SUCCESSFUL, you can browse http://10.199.250.171:9040/dashboard/index/php:pc_dev_vip_example
15:56:50.552 INFO - Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report.
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
Total time: 8.930s
Final Memory: 17M/563M
INFO: ------------------------------------------------------------------------
Finished: SUCCESS
它运行成功,我可以看到sonar报告,但PHPUnit测试不起作用,看看这个,它似乎找不到PHPUnit,但我已经在服务器上安装了。有人知道这是怎么发生的吗?我如何使PHPUnit起作用
15:56:49.132 INFO - Sensor PHPUnit Sensor
15:56:49.132 INFO - No PHPUnit test report provided (see 'sonar.php.tests.reportPath' property)
15:56:49.133 INFO - No PHPUnit unit test coverage report provided (see 'sonar.php.coverage.reportPath' property)
15:56:49.133 INFO - No PHPUnit integration test coverage report provided (see 'sonar.php.coverage.itReportPath' property)
15:56:49.133 INFO - No PHPUnit overall coverage report provided (see 'sonar.php.coverage.overallReportPath' property)
15:56:49.133 INFO - Sensor PHPUnit Sensor (done) | time=1ms
从您的日志中:
No PHPUnit test report provided (see 'sonar.php.tests.reportPath' property)
您应该按照日志和上的文档中所述配置sonar.php.tests.reportPath,以便为带有phpunit的声纳扫描仪生成单位和覆盖率报告: 您必须在安装之前安装xdebug
pecl install xdebug
然后
更改sonar-project.properties:
sonar.php.coverage.reportPath=phpunit.coverage.xml
sonar.php.tests.reportPath=phpunit.report.xml
正如其他人回答的那样,您需要通过设置
--coverage clover
从phpunit
生成覆盖率报告
非常重要的一点是,仅设置该参数是不可行的,您需要设置白名单目录:
vendor/bin/sonar scanner-Dsonar.sources=src-Dsonar.host.url=repository sonar-Dsonar.projectKey=akileepay:backend-Dsonar.exclusions=src/Migrations/**-Dsonar.php.coverage.reportpath=reports.xml也不起作用。当我设置路径时,它报告:它找不到文件。所以看起来PHPUnit不起作用,并且该文件无法生成。能否共享您的sonar.php.tests.reportPath设置和报告的消息?是的,我的配置:sonar.php.tests.reportPath=phpunit.xml,输出:Sensor phpunit Sensor 17:45:23.818 INFO-phpunit xml test report not found:phpunit.xml 17:45:23.818 INFO-未提供phpunit单元测试覆盖率报告(参见'sonar.php.coverage.reportPath'属性)17:45:23.818信息-未提供PHPUnit集成测试覆盖率报告(参见'sonar.php.coverage.itReportPath'属性)17:45:23.818信息-未提供PHPUnit总体覆盖率报告(参见'sonar.php.coverage.overallReportPath'属性)17:45:23.818信息-传感器PHPUnit传感器(完成)| time=0是分析项目根目录下的phpunit.xml文件吗?运行分析时它是否存在?项目中没有phpunit.xml文件,该文件是一个报告,因此它应该由phpunit生成,是吗?
sonar.php.coverage.reportPath
应该是sonar.php.coverage.reportPath
,缺少一个s
。请参阅
sonar.php.coverage.reportPath=phpunit.coverage.xml
sonar.php.tests.reportPath=phpunit.report.xml