-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
I've been banging my head against tests for a class involving error_log for a bit, and I'm starting to wonder if I'm running into some sort of output buffer bug in PHPUnit. PHPUnit appears not to be capturing error_log output as I would expect. Here's a quick-and-dirty test I wrote.
ObTest.php:
<?php
namespace Some\Test;
class ObTest
{
public function writeToErrorLog($message)
{
error_log($message);
}
}
The corresponding test:
<?php
namespace Some\Test;
include "ObTest.php";
class ObTestTest extends \PHPUnit_Framework_TestCase
{
public static $error_log_config;
public static function setUpBeforeClass()
{
self::$error_log_config = ini_get("error_log");
ini_set("error_log", "/dev/stdout");
}
public static function tearDownAfterClass()
{
ini_set("error_log", self::$error_log_config);
}
public function testWriteToErrorLogOutputs()
{
$ob_test = new ObTest();
$this->expectOutputString("Test");
$ob_test->writeToErrorLog("Test");
}
}
And the output:
PHPUnit 5.4-g9b5b99b by Sebastian Bergmann and contributors.
[06-May-2016 01:05:51 UTC] Test
Failed asserting that two strings are equal.
Expected :'Test'
Actual :''
I've also tried setting error_log to php://output thinking that the issue had something to do with stdout not getting captured in PHPUnit's output buffering at all; PHPUnit still returns the empty string as "Actual", which is ultimately what led me to believe this might be a bug.
I get the same result with PHPUnit 5.3.2, and in general I'm running PHP 5.6.20-1+deb.sury.org~trusty+1
Metadata
Metadata
Assignees
Labels
No labels