PHPUnit:死后继续,期待“死”或者以某种方式处理 die()?

发布于 2024-09-14 13:38:11 字数 708 浏览 2 评论 0原文

可能的重复:
如果某个函数应该杀死 PHP,那么如何使用 PHPUnit 来测试该函数?

我正在编写一些单元测试。我当前正在测试的系统是 MVC 框架中的 Web 应用程序。

如果我们想在没有站点皮肤系统的情况下渲染页面,我们传统上会照常运行我们的代码,但打印一个“die();”函数末尾的语句在网站的其余部分呈现之前退出。

现在我们添加了单元测试,这似乎是一个问题。你看,当你 DIE();在 MVC 中,这似乎向 PHPUnit 发送了相同的消息。

Grrrrr...代码现在已呈现“无法测试”

或者是吗?

一个人如何计划一场骰子();在 PHPUnit 中?

我知道在测试之前添加这个:

/**
 * @expectedException PHPUnit_Framework_Error
 */

但它不允许我测试变量,因为它们是“死亡时”(至少我不这么认为)

有人能够启发我吗?

谢谢! :D

Possible Duplicate:
How do you use PHPUnit to test a function if that function is supposed to kill PHP?

I'm writing some unit tests. The system I'm currently testing is a web-app in an MVC framework.

If we want to render pages without the site-skin system we've traditionally run our code as usual, but printed a "die();" statement at the end of the function to exit before the rest of the website renders.

Well now that we're adding unit testing, this seems to be a problem. You see, when you DIE(); in the MVC, that seems to send the same message to PHPUnit.

Grrrr... the code has now been rendered "Untestable"

Or has it?

How does one plan for a die(); In PHPUnit?

I know about adding this before a test:

/**
 * @expectedException PHPUnit_Framework_Error
 */

but it doesn't allow me to test the variables as they were 'at time of death' (at least I don't think so)

Anyone able to enlighten me?

Thanks!
:D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远山浅 2024-09-21 13:38:11

在这种情况下,您只需使用 return 而不是 die。在 IDE 中将所有死亡替换为返回应该很容易。

真正的问题是,当您确实需要测试 exitdie 返回的应用程序退出代码时(请参阅 edorian 的答案)。

In this case you just need to use return instead of die. It should be easy to replace all the deaths to returns in your IDE.

The real problem is, when you really need to test application exit code returned by exit or die (see edorian's answer).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文