6

When invoking PHPunit on some tests which fail with warnings, I get:

$ phpunit -c phpunit.xml --group app
Warning - MongoCollection::insert(): expects parameter 1 to be an array or object, null given in ...
    <more output>

OK, but incomplete or skipped tests!
Tests: 17, Assertions: 81, Incomplete: 1.

One of the tests should fail, but it doesn't; PHPunit marks it as "incomplete".

Let's check last exit status:

$ echo $?
0

The config I am using is:

<phpunit
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    strict="true"
    stopOnError="true"
    stopOnFailure="true"
    stopOnIncomplete="true"
    stopOnSkipped="true"

    colors="true"
    bootstrap="bootstrap_phpunit.php"
    >

Any idea how to force PHPunit to emit nonzero exit status in case of "incomplete" tests?

5
  • Did you double-check that the config file is effectively being loaded? you should get a message like this: Configuration read from /your/path/phpunit.xml Commented Jun 19, 2014 at 11:59
  • I did - colors="false" changes output, so it is used. Commented Jun 19, 2014 at 13:57
  • 1
    Do you set a custom error handler in your code? Commented Jun 19, 2014 at 14:00
  • I did - disabling it has changed error output, but didn't change exit status. Commented Jun 20, 2014 at 6:00
  • @gontrollez: thanks! I solved it: disabling error handler didn't help, but replacing it with the one that raises an exception worked wonderfully. Commented Jun 20, 2014 at 8:12

1 Answer 1

1

Thanks to gontrollez, I started looking into error handlers and finally found a solution:

set_error_handler(function ($severity, $message, $filepath, $line)
{
    throw new Exception($severity." - ".$message." - ".$filepath." - ".$line);
});

This code throws an exception which causes PHPunit to properly detect test as failed instead of incomplete. It should be put somewhere in bootstrap_phpunit.php (that is, in file, specified as bootstrap file).

Sign up to request clarification or add additional context in comments.

1 Comment

will this work correctly though, what about tests with expected excepttions - i'm wondering if this will be called before the phpunit handling of it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.