Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit problem - no error messages

I've been trying to solve this problem for quite some time.

I have a simple PHPUnit test case with 2 tests. When I run it, I get this output:

PHPUnit 3.5.14 by Sebastian Bergmann.

.

So the first assertion runs, passes. The second assertion, however, causes some PHP error (exception or something), and PHPUnit just dies without any info about what could have gone wrong.

Here is my phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
    backupStaticAttributes="false"
    colors="false"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    processIsolation="false"
    stopOnFailure="true"
    syntaxCheck="false"
    bootstrap="bootstrap.php.cache"
>
    <testsuites>
        <testsuite name="Portal Test Suite">
            <directory>../src/OneSolution/Portal/*Bundle/Tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

Setting syntaxCheck to true doesn't give any additional information about the error. However, it does print twice (before running any tests) that The filename, directory name, or volume label syntax is incorrect.

???

So, does anyone have any ideas what could I do to make PHPUnit report those error messages (the --verbose option didn't help either)?

EDIT: I've found out what has been causing the test to fail. There was a mistyped method name (I rely too much on code assist, I guess). However, this doesn't solve the main problem. Any warnings, errors or exception go unreported by PHPUnit.

like image 448
Jakub Lédl Avatar asked Jun 16 '11 21:06

Jakub Lédl


2 Answers

OK, so if anyone has trouble with getting none or incomplete output from PHPUnit command line, double-check your php.ini configuration directives:

  • error_reporting - should be set to E_ALL | E_STRICT for your development environment
  • display_errors - should be set to On
like image 165
Jakub Lédl Avatar answered Nov 19 '22 02:11

Jakub Lédl


I had the same problem, even with all error reporting enabled.

I tried to put echo statements into my test and setUp methods to find out where it was hanging, but they never appeared. The problem turned out to be PHP's output buffering. When I added the following method to my test:

protected function debug($text)
{
    echo "\nDEBUG: $text\n";
    flush();
    ob_flush();
}

and used $this->debug() instead of plain echo, I was able to see my debug statements. A binary search through the code quickly led to the source of the problem (an invalid database fixture, in my case).

like image 31
Ian Phillips Avatar answered Nov 19 '22 01:11

Ian Phillips