2016-09-20 222 views
0

我在PHPUnit 5.5.4和XDebug 2.4.1中使用PHP 5.6.24,我的代碼覆蓋率爲0.83%。 但是,在PHPUnit 4.7.7和XDebug 2.3.3中使用PHP 5.6.0之前,代碼覆蓋率超過了84%。升級到PHPUnit 5.5.4後代碼覆蓋率報告不正確

我發現從PHP 5.5.x開始,你需要有一個配置了白名單的phpunit.xml。這對我來說是新的,所以我添加了以下文件:

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit> 
    <filter> 
     <whitelist processUncoveredFilesFromWhitelist="true"> 
      <directory suffix=".php">./</directory> 
      <file></file> 
     </whitelist> 
    </filter> 
    <logging> 
     <log type="coverage-html" target="../results/report" lowUpperBound="35" highLowerBound="70"/> 
    </logging> 
    <testsuites> 
     <testsuite name="DTS"> 
      <directory>./</directory> 
     </testsuite> 
    </testsuites> 
</phpunit> 

單元測試仍然有效。當我通過命令行運行它們時,我仍然可以看到所有測試都成功執行,但這只是代碼覆蓋率報告的結果。

回答

0

我正在運行5.5.4,這是最新的穩定版本,5.6是beta版本。我向我的記錄添加了日誌,看看它是否會起作用,並且確實如此。它生成了一個HTML報告,該報告位於報告目錄中,正確顯示了我的百分比。這是我的phpunit.xml文件

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit colors="true" bootstrap="vendor/autoload.php"> 
    <testsuite name="Full Suite"> 
     <directory>tests/</directory> 
    </testsuite> 
    <filter> 
     <whitelist processUncoveredFilesFromWhitelist="true"> 
      <directory suffix=".php">src</directory> 
     </whitelist> 
    </filter> 
    <logging> 
     <log type="coverage-html" target="report"/> 
    </logging> 
</phpunit> 

所以它可能是測試版,但你至少可以看到我的XML文件,並知道它的工作原理與5.5.4。祝你好運!

+0

感謝您的意見。我用你的文件作爲基礎(修改我的路徑),但我仍然得到相同的結果。 (我也使用最新的穩定的PHPUnit 5.5.4,從未嘗試過測試版) – Tornado

+1

這太糟糕了,希望它是一些小東西......(對不起,我誤解了你原來的帖子,看到PHP 5.6並認爲它是PHPUnit 5.6,因此beta混淆)...我也運行PHP 5.6。我只能建議設置一些簡單的測試用例,看看它是否運行,然後檢查你的環境。祝你好運! – Katie

+0

phpunit是否有關於文件夾/測試結構的任何特定要求?我很懷疑,因爲它找到並執行所有測試用例? 什麼是看到的是,我的所有3793測試成功執行,但只有13/822測試方法有代碼覆蓋率。 – Tornado

相關問題