Phpunit 隐藏私人&x2B;受保护的方法不受代码覆盖率报告的影响?

Phpunit 隐藏私人&x2B;受保护的方法不受代码覆盖率报告的影响?,phpunit,code-coverage,xdebug,Phpunit,Code Coverage,Xdebug,我可以从PhpUnit的代码覆盖率报告中隐藏私有和受保护的方法吗 我知道有些人建议应该“间接”测试它们,但我真的不在乎它们是否被调用,我认为为私有实用程序方法设置@封套是完全浪费时间 这是我的phpunit.xml,如果您需要查看: <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colo

我可以从PhpUnit的代码覆盖率报告中隐藏私有和受保护的方法吗

我知道有些人建议应该“间接”测试它们,但我真的不在乎它们是否被调用,我认为为私有实用程序方法设置
@封套是完全浪费时间

这是我的
phpunit.xml
,如果您需要查看:

<phpunit
        backupGlobals="false"
        backupStaticAttributes="false"
        bootstrap="vendor/autoload.php"
        colors="true"
        convertErrorsToExceptions="true"
        convertNoticesToExceptions="true"
        convertWarningsToExceptions="true"
        processIsolation="false"
        stopOnFailure="false"
        syntaxCheck="false"
        timeoutForSmallTests="1"
        timeoutForMediumTests="10"
        timeoutForLargeTests="60">

    <testsuites>
        <testsuite name="default">
            <directory>./tests</directory>
            <exclude>
                <directory suffix=".php">./src/Internal</directory>
            </exclude>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory suffix=".php">./src</directory>
        </whitelist>
    </filter>

    <logging>
        <log type="coverage-html" target="./log/codeCoverage" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"/>
        <log type="testdox-html" target="./log/testdox.html"/>
    </logging>
</phpunit>

/测试
/src/内部
/src

就我所知,它不是PHPUnit功能,您必须进行fork项目并编辑源代码。也许这不是你想要的答案,但这似乎是目前唯一的选择

令人欣慰的是,这些变化非常简单。您可以编辑
CodeCoverage::getLinesToBeIgnored
并添加额外的条件

if (get_class($token) == 'PHP_Token_FUNCTION') {
    $methodVisibility = $token->getVisibility();

    if ($methodVisibility == 'private' || $methodVisibility == 'protected') {
       $endLine = $token->getEndLine();

       for ($i = $token->getLine(); $i <= $endLine; $i++) {
           self::$ignoredLines[$filename][$i] = TRUE;
       }
    }
}
if(get_class($token)='PHP_-token\u-FUNCTION'){
$methodVisibility=$token->getVisibility();
如果($methodVisibility=='private'.$methodVisibility=='protected'){
$endLine=$token->getEndLine();

对于($i=$token->getLine();$i好吧,如果一个公共方法依赖于私有方法,为什么要排除它们呢?这对我来说毫无意义,真的:)@DonCallisto不值得我这么做。回报递减。单元测试确保输出正确,代码覆盖率确保我测试所有不同的场景。我真的需要确保我执行库中的每一行代码吗,即使我可能过度概括了我的一些专用工具方法?我不这么认为。嗯,在在这种情况下,只需关闭代码覆盖率,否则仅将其应用于公共方法imho是没有意义的。顺便说一句,我不是100%代码覆盖率的粉丝或整合主义者,但我认为,如果打开它,应该让它评估您所使用的每一行代码have@DonCallisto我想我们在这一点上会有分歧。代码覆盖帮助我发现了一个错误自从我开始使用它以来,出现了很多错误。它确实很有用,但我只是看不到像
\uu debugInfo
这样的单元测试的价值。