[英]Excluding a PHP Interface from PHPUnit code coverage
我有一個 PHPUnit 測試,它測試了一個名為 HelpTokenizerTest 的 class。 這個 class 實現了 TokenizerInterface。 由於某些奇怪的原因,我不能將 TokenizerInterface 從代碼覆蓋范圍中排除。
盡管使用了@codeCoverageIgnore 甚至@codeCoverageIgnoreStart/End,但它在代碼覆蓋率報告中顯示為未涵蓋。
有任何想法嗎?
我不希望該接口包含在我的測試范圍中,因為它什么都不做。 測試接口有什么意義。
使用 phpunit.xml 時,您可以設置過濾器以排除具有特定名稱、特定文件夾或具有特定擴展名的文件。
請參閱它的文檔
例子:
<testsuite name="Application Test Suite">
<directory>./application/</directory>
</testsuite>
<filter>
<blacklist>
HERE
</blacklist>
or alternatively
<whitelist>
<directory suffix=".php">../library/</directory>
<directory suffix=".php">../application/</directory>
<exclude>
AND HERE
<directory suffix=".phtml">../application/</directory>
</exclude>
</whitelist>
</filter>
您可以使用@codeCoverageIgnore作為文件開頭的注釋來獲得 100% 0/0 覆蓋率。
<?php // @codeCoverageIgnoreStart
interface MyInterface
{
public function myfunction();
}
請注意,它在注釋塊中不起作用。
在 PHPUnit 的 github 上打開問題: https://github.com/sebastianbergmann/phpunit/issues/497
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.