Reputation: 22645
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.
Upvotes: 5
Views: 5602
Reputation: 153
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.
Upvotes: 1
Reputation: 22645
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).
Upvotes: 6