从 PHPUnit 代码覆盖率中排除 PHP 接口
我有一个 PHPUnit 测试,用于测试名为 HelpTokenizerTest 的类。该类实现 TokenizerInterface。由于某些奇怪的原因,我无法将 TokenizerInterface 从代码覆盖率中排除。
尽管使用了 @codeCoverageIgnore 甚至 @codeCoverageIgnoreStart/End,但它在代码覆盖率报告中显示为未覆盖。
有什么想法吗?
我不希望该接口包含在我的测试覆盖范围中,因为它不执行任何操作。测试接口有什么意义?
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 Interface.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 phpunit.xml 时,您可以设置过滤器来排除具有特定名称、特定文件夹或具有特定扩展名的文件。
请参阅相关文档
示例:
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:
您可以在文件开头使用@codeCoverageIgnore作为注释来获得100% 0/0覆盖率。
请注意,它在评论块中不起作用。
PHPUnit 的 github 上开放的问题: https://github.com/sebastianbergmann/phpunit/issues/497
You can use @codeCoverageIgnore as a comment at the beginning of the file to get 100% 0/0 coverage.
Note that it doesn't work in a comment block.
Issue open on PHPUnit's github: https://github.com/sebastianbergmann/phpunit/issues/497