How to get PHPunit to return nonzero exit status on warnings

When calling PHPunit on some tests that 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 is not; PHPunit marks this as "incomplete."

Check the status of the last exit:

$ echo $?
0

The configuration I'm 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 get PHPunit to emit non-zero exit status in case of "incomplete" tests?

+4
source share
1 answer

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

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

, PHPunit failed incomplete. - bootstrap_phpunit.php ( , bootstrap ).

0

Source: https://habr.com/ru/post/1545222/


All Articles