Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get phpunit to not swallow error_log output?

When error_log() is run from within phpunit it isn't written to the normal error log file. I'd like to stop this so that it writes to file as if I was hitting PHP via a browser.

<?php

class exampleTest extends PHPUnit_Framework_TestCase {

    public function testSomething() {
        error_log('This will not be written to the error log, but I wish it was!');
        $this->assertEquals(2, 1+1);
    }

}

I am currently using php version 5.5, phpunit version 3.7. This happens both on osx and ubunutu. This does not happen on Windows 7.

like image 568
Aaron Silverman Avatar asked Aug 08 '14 00:08

Aaron Silverman


2 Answers

So this turned out to be a symptom of php run from command line not logging errors (discussed here) and was solved by ensuring that the user executing phpunit has write permissions to the error log.

Also at play was the fact when invoked from the command line php used a different ini file (discussed here).

like image 135
3 revs Avatar answered Oct 19 '22 13:10

3 revs


When executed by PHPUnit, the error_log() function writes to the PHP STDERR rather than the config of the project itself. This is resulted by an error handler defined by PHPUnit. This default behavior can be altered using a custom error handler.

like image 37
Panduka Avatar answered Oct 19 '22 12:10

Panduka