PHPUnit:死后继续,期待“死”或者以某种方式处理 die()?
我正在编写一些单元测试。我当前正在测试的系统是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,您只需使用
return
而不是die
。在 IDE 中将所有死亡替换为返回应该很容易。真正的问题是,当您确实需要测试
exit
或die
返回的应用程序退出代码时(请参阅 edorian 的答案)。In this case you just need to use
return
instead ofdie
. 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
ordie
(see edorian's answer).