强制从PHPUnit代码覆盖率中排除文件 [英] Force Exclude files from PHPUnit Code Coverage

查看:94
本文介绍了强制从PHPUnit代码覆盖率中排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从PHPUnit的代码范围中强制排除文件夹?

Is it possible to forcefully exclude a folder from PHPUnit's code coverage?

我遇到的问题是,我有一个Symfony 1.4项目,该项目的文件夹位于./lib/vendor/symfony/*.我想以递归方式排除./lib/vendor/*内部的任何内容.

Problem I've got is, that I have a Symfony 1.4 project, which has folders at ./lib/vendor/symfony/*. I want to exclude anything that's inside ./lib/vendor/* - recursively.

现在,我想排除它们,无论它们是否被我的测试隐式覆盖,即,我从不希望看到这些文件夹.因此,我已将此位添加到我的phpunit.xml配置文件中,但是无论我做什么,它似乎都没有排除这些文件夹:

Now, I want to exclude them whether they were covered implicitly by my tests or not, i.e. I never want to see these folders. So, I've added this bit to my phpunit.xml config file, but it doesn't seem to exclude these folders, no matter what I do:

<filter>
    <whitelist>
        <exclude>
            <directory>./lib/vendor/*</directory>
            <directory>./lib/vendor/symfony/lib/*</directory>
        </exclude>
    </whitelist>
</filter>

在我看来,当代码被点击时,XDebug注意到了它,无论如何,PHPUnit都会将其包括在代码覆盖率中.对于我来说,不利的是,该代码已经由Symfony开发人员进行了测试,因此无需将其包含在我的覆盖率报告中,从而弄乱了我的电话号码:P

It appears to me the moment code gets hit and XDebug notices it, PHPUnit will include it in the code coverage no matter what. The downside for me with this is, that this code is already tested by Symfony developers, so no need to include it in my coverage report, messing up my numbers :P

推荐答案

好,所以我认为您可以同时拥有黑名单部分或白名单部分,因此您可以同时拥有这两个文件夹,因此我将这些文件夹都列入了黑名单,并且可以正常工作:

Ok, so I thought that you can have either the blacklist section OR the whitelist section, turns out you can have both, so I blacklisted those folders and it worked:

    <filter>
        <blacklist>
              <directory>./lib/vendor</directory>
              <directory>./lib/helper</directory>
        </blacklist>
    </filter>

这篇关于强制从PHPUnit代码覆盖率中排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆