StreamOutputTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Tests\Output;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Output\Output;
  13. use Symfony\Component\Console\Output\StreamOutput;
  14. class StreamOutputTest extends TestCase
  15. {
  16. protected $stream;
  17. protected function setUp()
  18. {
  19. $this->stream = fopen('php://memory', 'a', false);
  20. }
  21. protected function tearDown()
  22. {
  23. $this->stream = null;
  24. }
  25. public function testConstructor()
  26. {
  27. $output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
  28. $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
  29. $this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
  30. }
  31. public function testStreamIsRequired()
  32. {
  33. $this->expectException('InvalidArgumentException');
  34. $this->expectExceptionMessage('The StreamOutput class needs a stream as its first argument.');
  35. new StreamOutput('foo');
  36. }
  37. public function testGetStream()
  38. {
  39. $output = new StreamOutput($this->stream);
  40. $this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
  41. }
  42. public function testDoWrite()
  43. {
  44. $output = new StreamOutput($this->stream);
  45. $output->writeln('foo');
  46. rewind($output->getStream());
  47. $this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
  48. }
  49. }