Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • In practice, this only works for detecting syntax errors, because (1) a script does not usually survive isolated, (2) it's unfeasible to bootstrap an entire application like this, (3) it does not create a testing/repeatable context, (4) not having all the context set up could cause false fatal errors like undefined function. Thus, instead of executing php $tempfile it's better to execute php --no-php-ini --syntax-check $tempfile. php.net/manual/en/features.commandline.options.php
    – aercolino
    Commented Jan 15, 2015 at 19:17
  • Can you prove that? I don't think so
    – hek2mgl
    Commented Jan 15, 2015 at 21:12
  • Well, it "works" in the console because I see the fatal error. The $return is always 255 for the six uncatchable errors and always 0 otherwise. I think I need a shutdown handler to get to the error code. -- as for PHPUnit, even if I @runInSeparateProcess a single test causing a fatal error, it always appears as an 'E'. -- Your idea is interesting, and I upped you before. But to make it work, I think I need to dig into PHPUnit and write a patch or plugin. I wonder why nobody did it before. Is it unreasonable to expect a script to fail?
    – aercolino
    Commented Jan 20, 2015 at 23:44
  • Now I got your concerns. Will play around with PHPUnit a little bit, probably write some code and give you a feedback..
    – hek2mgl
    Commented Jan 22, 2015 at 11:09
  • I've found there is a customizable isolation template. There we need to register_shutdown_function('__phpunit_shutdown', $test, $result). __phpunit_shutdown($test, $result) (in case of error) only prints a serialized array like usual, but with an added error key set to error_get_last(). Then we can add support for an @expectedShutdownError <code> from PHPUnit_Util_PHP::runTestJob, which would call processChildResult with doctored arguments (mainly stderr = '').
    – aercolino
    Commented Jan 22, 2015 at 17:08