如何在phpunit中排除代码覆盖率中的目录

时间:2015-05-15 10:11:09

标签: zend-framework phpunit

我有zend应用程序的Testproject的目录结构,如

-Source Files
 -application
 -library
   -Zend
 -public
-Test Files
 -application
 -phpunit.xml   

phpunit.xml配置

<phpunit bootstrap="./bootstrap.php">
    <testsuite name="Application Test Suite">
        <directory>./application</directory>
    </testsuite>
    <!--<testsuite name="Library Test Suite">
        <directory>./library</directory>
    </testsuite>-->

    <filter>
        <!-- If Zend Framework is inside your project's library, uncomment this filter -->

        <whitelist>
            <directory suffix=".php">../../library/Zend</directory>
        </whitelist>

    </filter>
    <logging>

      <log type="coverage-html" target="./log/htmlreport" charset="UTF-8"
        yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"/>
        <log type="json" target="./log/jsonreport.json" charset="UTF-8"/>

    </logging>
</phpunit>

我正在调用phpunit for application.It工作正常,代码覆盖也生成。但是我想从代码覆盖中排除library / zend。我的意思是不应该为库文件夹生成代码覆盖。我试图排除但是它总是生成的。我的phpunit.xml文件中是否存在任何配置错误?

1 个答案:

答案 0 :(得分:0)

我说你应该将应用程序文件夹的路径添加到白名单而不是库。

在许多情况下,白色等于&#34;添加&#34;,&#34;好&#34;,&#34;包括&#34;和黑色等于&#34;删除&#34;,&#34;坏,&#34;排除&#34;。

如果没有过滤器,phphunit会报告几乎所有内容。添加白名单最初会删除覆盖范围内的所有内容,然后添加白名单中的所有内容(减去任何排除或黑名单)。