PHPUnit: continue after die, expect “die” or somehow handle die()? [duplicate]

為{幸葍}努か 提交于 2019-12-24 00:58:59

问题


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


回答1:


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).



来源:https://stackoverflow.com/questions/3504277/phpunit-continue-after-die-expect-die-or-somehow-handle-die

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!