I've been using mock objects when testing code that uses files and other stuff that's hard to test because there are too many effects on the code's surroundings and you have to test . I've been doing that on an ad hoc basis. Now Mike Naberezny has an interesting generalized class for wrapping PHP modules to make it possible to replace them with mocks.
That solves some of those challenges, but there are some functions that are not amenable to that approach. exit() is one of them. Let's try using anonymous functions. exit() is a particularly hot candidate, since it plays havoc with tests. If the code under test exits before the test run is finished, it's like hitting the poor test framework over the head with a brick. It's out cold and has no chance to report the results from the test.
An anonymous function to replace exit() can be created with create_function(), as in the constructor of this class: