Skip to content

Commit

Permalink
testDoWriteOnFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Pédelagrabe committed Mar 26, 2020
1 parent cc290fc commit 1f042b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/Output/StreamOutput.php
Expand Up @@ -75,6 +75,7 @@ protected function doWrite($message, $newline)
}

if (!is_resource($this->stream) || !is_string($message)) {
// should never happen
throw new RuntimeException('Unable to write output.');
}
@fwrite($this->stream, $message);
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions src/Symfony/Component/Console/Tests/Output/StreamOutputTest.php
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Console\Tests\Output;

use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\StreamOutput;
Expand Down Expand Up @@ -56,4 +57,17 @@ public function testDoWrite()
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);
try {
$output->writeln('foo');
} catch (\RuntimeException $exception) {
throw new AssertionFailedError('dd');
}
rewind($output->getStream());
$this->assertEquals('', stream_get_contents($output->getStream()));
}
}

0 comments on commit 1f042b8

Please sign in to comment.