PHPUnit: continue after death, expect to "die" or somehow deal with die ()?

Possible duplicate:
How do you use PHPUnit to test a function if that function should kill PHP?

I am writing some unit tests. The system I'm testing is an MVC web application.

If we want to display pages without a site system, we traditionally run our code, as usual, but print "die ();" expression at the end of the function to exit to the rest of the website.

Now that we add unit testing, this seems like a problem. You see when you are DIE (); in MVC, which seems to send the same message in PHPUnit.

Grrrr ... code now appears as "unstable"

Or that?

How to plan a stamp (); In PHPUnit?

I know about adding this before the test:

/** * @expectedException PHPUnit_Framework_Error */ 

but this does not allow me to check the variables as they were "at the time of death" (at least I don't think so)

Can anyone enlighten me?

Thanks! : D

+2
source share
1 answer

In this case, you just need to use return instead of die . It should be easy to replace all deaths with a return to your IDE.

The real problem is when you really need to check the application exit code returned by exit or die (see edorian answer).

+3
source

Source: https://habr.com/ru/post/969986/


All Articles