【问题标题】:How can PHPUnit code coverage ignore my autoloader?PHPUnit 代码覆盖率如何忽略我的自动加载器?
【发布时间】:2012-07-09 17:23:56
【问题描述】:

我的 phpunit 配置中有一个引导程序,它运行 Zend\Loader\StandardAutoloader.php。当我添加时,我可以获得 PHPUnit 代码覆盖以忽略它

<filter>
   <blacklist>
       <directory suffix=".php">/absolute/path/to/zf</directory>
   </blacklist>
</filter>

到 PHPUnit 配置 XML 文件。但我必须指定一个绝对路径。我希望它是一个相对路径,但 PHPUnit 不会忽略代码覆盖中的 Zend 文件夹。我不想为在家工作时添加不同的位置,也不希望其他开发人员添加自己的路径。 Zend 框架位于 php.ini include_path 设置中,但这不起作用:

<filter>
   <blacklist>
       <directory suffix=".php">./Zend</directory>
   </blacklist>
</filter>

有什么建议吗?

【问题讨论】:

    标签: php zend-framework phpunit code-coverage zend-autoloader


    【解决方案1】:

    您可以使用&lt;filter&gt;&lt;whitelist&gt; 中的&lt;exclude&gt;...&lt;/exclude&gt; 指令从代码覆盖范围中排除路径:

    <filter>
        <whitelist>
            <directory suffix=".php">../src/library/</directory>
            <!-- add more directories -->
            <exclude>
                <directory suffix=".phtml">./src/application/</directory>
                <directory suffix=".php">./Zend/</directory>
                <!-- add more directories with relative or absolute path -->
            </exclude>
        </whitelist>
    </filter>    
    

    【讨论】:

    • 为什么要在排除目录中添加suffix 参数?
    【解决方案2】:

    实际上,这也可以通过黑名单来完成。该路径需要相对于您的测试目录。

    这在我的项目中起到了作用:

    <filter>
        <blacklist>
            <directory suffix=".php">../../../cache</directory>
        </blacklist>
    </filter>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      • 2012-08-04
      • 1970-01-01
      • 2018-05-29
      • 2012-01-18
      • 2016-10-22
      • 2021-07-29
      相关资源
      最近更新 更多