When a Fatal Error occurs, the PHP process is terminated -- which means there is no way to have that same PHP process executed any kind of addionnal code, as it's no longer there.
This will also mean that :
- you'll probably not get much reporting
- the other tests after the one that ends up in a Fatal Error will not run
- You have a test that is failing -- badly.
You should fix the problem : a Fatal Error in your application is bad ; it's great that you detected it with your automated tests, of course -- but the next step is to make it go away ;-)
As you cannot run anymore PHP code in the same process that has died, the only solution I see would be to launch another process, to run your clean-up code.
The basic idea would be to :
- Launch your tests
- Use another, totally distinct, script, to run the clean-up operations
Of course, this means the clean-up will only be done once, after all tests have been run ; but I suppose it's better than nothing.
Now, how to do that in an automated way ?
The simplest solution would probably be to use a shell-script, that runs both commands ; something like this, I'd say :
#!/bin/sh
php /.../launch-tests.php
php /.../cleanup.php
And run your tests by launching that shell-script.