2010-08-26 62 views
6

爲什麼我需要這個?我正在symfony項目上運行測試(並使用Zend FW),phpunit爲所有受影響的文件生成三葉草。但我不想看到symfony和Zend libs(以及所有其他第三方庫)的報道。我只希望看到我的代碼覆蓋。 或者可能是這個應該做三葉草查看器?我爲哈德森使用三葉草插件,但它不支持查看特定來源。三葉草插件顯示,我的代碼只覆蓋了20%,這是不正確的,因爲它考慮了symfony和Zend庫。phpunit三葉草從一些特定的目錄,而不是完整的三葉草。可能嗎?

順便說一句,可能有另一種方法來獲得這個?

回答

10

您需要爲phpunit創建配置文件,在該配置文件中您可以從代碼覆蓋範圍中排除特定文件或目錄。

實例文件看起來像這樣:

<phpunit stopOnFailure="false"> 
    <testsuite name="Name"> 
    </testsuite> 

<filter> 
    <whitelist> 
      <directory suffix=".php">../php</directory> 
      <exclude> 
        <file>../php/somefile.php</file> 
        <directory suffix=".php">../php/pdf</directory> 
      </exclude> 
    </whitelist> 
</filter> 

<logging> 


     <log type="coverage-html" target="target-dir/coverage" charset="UTF-8" yui="true" highlight="true"/> 
     <log type="coverage-clover" target="target-dir/build/logs/clover.xml"/> 
</logging> 

</phpunit> 

隨着下../php上述文件的一切(這是從那裏測試是在與phprun從執行目錄相對)被包含在代碼覆蓋, 除了文件../php/somefile.php和目錄中所有帶擴展名.php的文件../php/pdf

將此文件命名爲phpunit.xml,將它放到您運行測試的相同目錄中從。他們,如果你運行phpunit,它會選擇配置。

如果你不能用這種特殊的文件名,你可以在命令行給出名稱

phpunit --configuration yourconf.xml 

詳細瞭解PHPUnit的配置文件的詳細信息,請訪問:http://phpunit.de/manual/3.7/en/appendixes.configuration.html

+0

您提到的相對路徑很有幫助,謝謝! – 2011-08-24 21:48:49

0

我覺得過濾音符的配置

像這樣::

<phpunit stopOnFailure="false"> 
    <testsuite name="Name"></testsuite> 

    <logging> 
     <filter> 
       <whitelist> 
         <directory suffix=".php">../php</directory> 
         <exclude> 
           <file>../php/somefile.php</file> 
           <directory suffix=".php">../php/pdf</directory> 
         </exclude> 
       </whitelist> 
     </filter> 

     <log type="coverage-html" target="target-dir/coverage" charset="UTF-8" yui="true" highlight="true"/> 
     <log type="coverage-clover" target="target-dir/build/logs/clover.xml"/> 
    </logging> 
XML文件必須由洛節點包裹