views:

30

answers:

2

Hi all.

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  A: 

Have a look into the accepted answers of this question: http://stackoverflow.com/questions/1347794/how-do-you-use-phpunit-to-test-a-function-if-that-function-is-supposed-to-kill-ph

edorian
+1  A: 

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

takeshin
+1, in most (nearly all) cases it's better to use return instead of die in a application.
edorian