I use Symfony\Component\Console\Output\ConsoleOutputto write to the console.
Obviously, I am writing php://stdout.
In my unit tests, I would like to check the output to the console.
Using the PHPUnit method expectOutputString(), I can check the output:
public function testOutputBufferingEcho()
{
$this->expectOutputString('Hello');
echo 'Hello';
}
This also works with output to php://output:
public function testOutputBufferingOutput()
{
$this->expectOutputString('Hello');
$out = fopen('php://output', 'w');
fputs ($out, 'Hello');
fclose($out);
}
However, it does not work with output on php://stdout(one ConsoleOutputuses by default):
public function testOutputBufferingStdOut()
{
$this->expectOutputString('Hello');
$out = fopen('php://stdout', 'w');
fputs ($out, 'Hello');
fclose($out);
}
In addition, it seems impossible to use functions ob_*to directly output output to php://stdout.
Is there a way to check the output on php://stdoutusing PHPUnit?
Or is there another way to capture output in php://stdouta string (and therefore a test in PHPUnit)?
The above tests were performed in PHPUnit 5.5.5.
Thanks in advance.