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

Viewed 18979

Essentially I have a method of a class called killProgram, which is intended to send a hTTP redirect and then kill PHP.

How am I supposed to test this? When I run phpunit it doesn't return anything for that test, and closes completely.

Right now I'm considering having the killProgram function throw an exception which shouldn't get handled, which would allow me to assert that an exception was thrown.

Is there a better way?

6 Answers

You can kill the script or throw an exception, depending on the value of an environmental variable...

So you kill in production or throw an exception in test environment.

Any call to die or exit, Kills the whole process...

This was supposed to be a comment but I can't comment with the level of my reputation points.

Related