为什么 PHPUnit 在生成覆盖率报告时要执行代码?
亲爱的叠花, 我们正在开发一个基于 cakephp 的 Web 应用程序。事实证明,以 TDD 方式使用 CakePHP 有点困难,因此我们尝试通过将所有业务逻辑提取到不依赖 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>
感谢您的帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将 cakephp 文件添加到 黑名单。您应该能够在 xml 配置文件中执行此操作:
有更多信息 此处
You need to add the cakephp files to the blacklist. You should be able to do this in your xml config file:
There is further information here
它这样做是因为它还需要获取有关未涵盖的类、方法和函数的信息。它包含它找到的文件,并使用 Reflection 来发现有关类的所有信息。这比手动解析和分析 PHP 文件的解析的标记更容易。
It does this because it needs to get information about the classes, methods and functions that are not covered, too. It includes the files it finds and uses Reflection to discover all information about the classes. That's easier than manually parsing and analyzing the parsed tokens of a PHP file.