gpt4 book ai didi

php - 为什么 PHPUnit 在生成覆盖率报告时要执行代码?

转载 作者:可可西里 更新时间:2023-10-31 23:25:43 25 4
gpt4 key购买 nike

亲爱的stackoverflowers,我们正在开发一个基于 cakephp 的 Web 应用程序。 CakePHP 被证明有点难以以 TDD 方式使用,因此我们试图通过将所有业务逻辑提取到不依赖于 cakephp 的类中,在它自己的框架上开发尽可能少的代码。因此,我们能够使用 phpunit 测试我们的库,问题最少。然而,我们确实希望将未经测试的代码包含在我们的覆盖率报告中,而不是任何东西,以密切关注 cake 和我们无法测试的库之间的胶水代码量。那么问题是,当告诉 phpunit 解释这些代码时,它会疯狂地解析和执行 cakephp 的代码,并且它会崩溃。我的问题是:为什么 phpunit 会执行这段代码?这里有什么我们不理解或做错的地方吗?这是我们正在使用的 phpunit.xml 文件:

<?xml version="1.0" encoding="utf-8" ?>

<phpunit backupGlobals="true"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader">
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">app</directory>
<exclude>
<directory suffix=".php">tests</directory>
<directory suffix=".php">app/webroot</directory>
<directory suffix=".php">app/plugins</directory>
<directory suffix=".php">app/vendors</directory>
<directory suffix=".php">app/config</directory>
<directory suffix=".php">app/tmp</directory>
<directory suffix=".php">cake</directory>
<directory suffix=".php">vendors</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

感谢您的帮助。

最佳答案

您需要将 cakephp 文件添加到 blacklist .您应该能够在您的 xml 配置文件中执行此操作:

<filter>
<blacklist>
<directory suffix=".php">/path/to/files</directory>
<file>/path/to/file</file>
<exclude>
<directory suffix=".php">/path/to/files</directory>
<file>/path/to/file</file>
</exclude>
</blacklist>
</filter>

还有更多信息here

关于php - 为什么 PHPUnit 在生成覆盖率报告时要执行代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4263299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com