开发者

Excluding a PHP Interface from PHPUnit code coverage

开发者 https://www.devze.com 2023-03-09 22:33 出处:网络
I\'ve got a PHPUnit test that tests a class called HelpTokenizerTest. This class implements TokenizerInterface. For some weird reason I cannot exclude the TokenizerInterface from code coverage.

I've got a PHPUnit test that tests a class called HelpTokenizerTest. This class implements TokenizerInterface. For some weird reason I cannot exclude the TokenizerInterface from code coverage.

It shows up in code coverage reports as not covered, despite using @codeCoverageIgnore or even @codeCoverageIgnoreStart/End.

Any ideas?

I don't want the interface included in my test coverage, as it doesn't do anything. What's the point of testing an I开发者_如何学Pythonnterface.


When using a phpunit.xml you can set up filters to exclude files with particular names, in particular folders or with an particular extension.

see the documentation for it

Example:

<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>


You can use @codeCoverageIgnore as a comment at the beginning of the file to get 100% 0/0 coverage.

<?php // @codeCoverageIgnoreStart 
interface MyInterface
{
    public function myfunction();
}

Note that it doesn't work in a comment block.

Issue open on PHPUnit's github: https://github.com/sebastianbergmann/phpunit/issues/497

0

精彩评论

暂无评论...
验证码 换一张
取 消