2016-11-12 158 views
1

當執行聲納掃描儀可在示例項目: https://github.com/SonarSource/sonar-examples/tree/b0ebd45081e58c3cb7c660287d5ed7fb9c64bb17/projects/languages/php/php-sonar-runner-unit-testsSonarqube掃描器無法解決PHPUnit的覆蓋XML文件相對文件路徑

我得到以下警告,覆蓋數據不被髮送到聲納主機:

WARN: Could not resolve 1 file paths in phpunit.coverage.xml, first unresolved path: src/Math.php 

命令全輸出:

[email protected]:/home/test/sonar-examples-master/projects/languages/php/php-sonar-runner-unit-tests# /home/sonar-scanner-2.8/bin/sonar-scanner 
INFO: Scanner configuration file: /home/sonar-scanner-2.8/conf/sonar-scanner.properties 
INFO: Project root configuration file: /home/test/sonar-examples-master/projects/languages/php/php-sonar-runner-unit-tests/sonar-project.properties 
INFO: SonarQube Scanner 2.8 
INFO: Java 1.8.0_111 Oracle Corporation (64-bit) 
INFO: Linux 4.4.27-boot2docker amd64 
INFO: User cache: /root/.sonar/cache 
INFO: Load global repositories 
INFO: Load global repositories (done) | time=240ms 
INFO: User cache: /root/.sonar/cache 
INFO: Load plugins index 
INFO: Load plugins index (done) | time=24ms 
INFO: SonarQube server 6.1 
INFO: Default locale: "en", source code encoding: "UTF-8" 
INFO: Process project properties 
INFO: Load project repositories 
INFO: Load project repositories (done) | time=141ms 
INFO: Load quality profiles 
INFO: Load quality profiles (done) | time=55ms 
INFO: Load active rules 
INFO: Load active rules (done) | time=141ms 
WARN: SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project. 
INFO: Publish mode 
INFO: ------------- Scan PHP :: PHPUnit :: SonarQube Scanner 
INFO: Language is forced to php 
INFO: Load server rules 
INFO: Load server rules (done) | time=76ms 
INFO: Base dir: /home/test/sonar-examples-master/projects/languages/php/php-sonar-runner-unit-tests 
INFO: Working dir: /home/test/sonar-examples-master/projects/languages/php/php-sonar-runner-unit-tests/.sonar 
INFO: Source paths: src 
INFO: Test paths: tests 
INFO: Source encoding: UTF-8, default locale: en 
INFO: Index files 
INFO: 3 files indexed 
INFO: Quality profile for php: Sonar way 
INFO: Sensor Lines Sensor 
INFO: Sensor Lines Sensor (done) | time=25ms 
INFO: Sensor NoSonar Sensor 
INFO: Sensor NoSonar Sensor (done) | time=65ms 
INFO: Sensor SCM Sensor 
INFO: No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it. 
INFO: Sensor SCM Sensor (done) | time=0ms 
INFO: Sensor PHP sensor 
INFO: 2 source files to be analyzed 
INFO: 2/2 source files have been analyzed 
INFO: Analyzing PHPUnit test report: reports/phpunit.xml with [email protected] 
INFO: Analyzing PHPUnit unit test coverage report: reports/phpunit.coverage.xml with PHPUnit Unit Test Coverage Result Parser 
WARN: Could not resolve 1 file paths in phpunit.coverage.xml, first unresolved path: src/Math.php 
INFO: No PHPUnit integration test coverage report provided (see 'sonar.php.coverage.itReportPath' property) 
INFO: No PHPUnit overall coverage report provided (see 'sonar.php.coverage.overallReportPath' property) 
INFO: Sensor PHP sensor (done) | time=1419ms 
INFO: Sensor Analyzer for "php.ini" files 
INFO: Sensor Analyzer for "php.ini" files (done) | time=11ms 
INFO: Sensor Zero Coverage Sensor 
INFO: Sensor Zero Coverage Sensor (done) | time=49ms 
INFO: Sensor Code Colorizer Sensor 
INFO: Sensor Code Colorizer Sensor (done) | time=1ms 
INFO: Sensor CPD Block Indexer 
INFO: DefaultCpdBlockIndexer is used for php 
INFO: Sensor CPD Block Indexer (done) | time=2ms 
INFO: Calculating CPD for 2 files 
INFO: CPD calculation finished 
INFO: Analysis report generated in 96ms, dir size=27 KB 
INFO: Analysis reports compressed in 18ms, zip size=13 KB 
INFO: Analysis report uploaded in 115ms 
INFO: ANALYSIS SUCCESSFUL, you can browse http://***.elasticbeanstalk.com/dashboard/index/org.sonarqube:php-ut-sq-scanner 
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report 
INFO: More about the report processing at http://***.elasticbeanstalk.com/api/ce/task?id=AVhaEXKjVjsdBlz4sGdU 
INFO: Task total time: 3.511 s 
INFO: ------------------------------------------------------------------------ 
INFO: EXECUTION SUCCESS 
INFO: ------------------------------------------------------------------------ 
INFO: Total time: 5.098s 
INFO: Final Memory: 42M/149M 
INFO: ------------------------------------------------------------------------ 

當我改變PHPUnit的路徑是絕對的。 coverage.xml,它似乎在Linux中工作。在Windows搬運工快速啓動終端(MINGW64),使其工作的唯一方法是使用Windows風格的絕對路徑: C:\ Users \用戶名\項目\ PHP-聲納的亞軍單元測試

是有沒有辦法使它與相對路徑一起工作?

回答

1

從(你鏈接在同一頁上)的自述引用:

  • 在 「報告/ phpunit.coverage.xml」,更改路徑 「的src/Math.php」 到此文件在您的機器上的完整路徑。

您必須使用絕對路徑。它不適用於相對路徑。

請注意,這僅僅是一個覆蓋範圍報告文件的例子,使用一個由PHPUnit預先生成的文件(在自述文件中也提到)。通常,您在運行SonarQube分析之前自己生成覆蓋率報告文件,在這種情況下,它將在系統中具有正確的絕對路徑。

+0

謝謝你Janos。我完全錯過了關於改變路徑的評論。我實際上使用了自己生成的覆蓋文件。然而,我在docker容器中運行phpunit,所以它會生成linux樣式的路徑。聲納掃描儀,但我從Windows主機運行。在這種情況下,我想我沒有別的選擇,只能在報告文件上運行搜索和替換。 –

+0

不能在碼頭集裝箱中運行聲納掃描儀嗎? – janos

+0

我可以做到這一點。由於這是一個PHP項目,我不想在其中安裝Java。今天我嘗試了另一種方法:將PHP文件作爲卷映射到基於Java的聲納掃描器容器中,然後運行得非常好。 –