22

I use PHPUnit for unit tests, but when a fatal error is triggered, the script dies and I have no correct PHPUnit output.

I'd like that the PHPUnit output stays correctly formated, because it is read by a plugin for Eclipse. Actually the fatal error stops PHPUnit and in Eclipse the plugin can't interpret anything (because the PHPUnit script had an error, instead of handling it).

Thanks

1
  • what sort of fatal errors? if they're syntax or semantics-related, you're out of luck.
    – bcosca
    Commented Oct 1, 2010 at 18:55

2 Answers 2

30

You need to use PHPUnit's process isolation features - start each test suite in a new process.

phpunit --process-isolation ...

This is the only way to make sure fatal errors don't break your phpunit output.

Execution time

Process isolation multiplies your test run time, because for each single test, a new PHP instance is started, the bootstrap is executed etc.

To amend this situation, you may choose to run full test cases in a separate process (@runTestsInSeparateProcesses), or only single ones that are known to fatal out sometimes (@runInSeparateProcess).

3
  • 1
    Be awre though it does considerably increase test execution. Went from 4 seconds to 90 seconds here with just 150 tests on a small app. Commented May 19, 2011 at 4:39
  • You can i.e. disable "backup globals" to get better test speeds. It also depends on the speed of your bootstrap file.
    – cweiske
    Commented May 19, 2011 at 5:42
  • --process-isolation can cause huge brains damage when I'll try run 7000+ tests, I used register_shutdown_function() in --bootstrap and --printer for TeamCity integration. I'll share sources later this month. Commented Apr 26, 2012 at 16:17
2

set_error_handler() won't help you there. You can catch fatal errors using register_shutdown_function()

1
  • As said, I'd like to have a PHPUnit error (I want the phpunit output not to be messed up). I've extended the description of the question. Commented Oct 1, 2010 at 18:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.