[Console] Fix OutputStream for PHP 7.4

This commit is contained in:
Guillaume Pédelagrabe 2020-03-26 14:31:51 +01:00 committed by Fabien Potencier
parent a29ee7c220
commit b375f93ed7
3 changed files with 9 additions and 5 deletions

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Output;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
/**
@ -74,10 +73,7 @@ class StreamOutput extends Output
$message .= PHP_EOL;
}
if (false === @fwrite($this->stream, $message)) {
// should never happen
throw new RuntimeException('Unable to write output.');
}
@fwrite($this->stream, $message);
fflush($this->stream);
}

View File

@ -56,4 +56,12 @@ class StreamOutputTest extends TestCase
rewind($output->getStream());
$this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
}
public function testDoWriteOnFailure()
{
$resource = fopen(__DIR__.'/../Fixtures/stream_output_file.txt', 'r', false);
$output = new StreamOutput($resource);
rewind($output->getStream());
$this->assertEquals('', stream_get_contents($output->getStream()));
}
}