StreamOutputTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /**
  32. * @expectedException \InvalidArgumentException
  33. * @expectedExceptionMessage The StreamOutput class needs a stream as its first argument.
  34. */
  35. public function testStreamIsRequired()
  36. {
  37. new StreamOutput('foo');
  38. }
  39. public function testGetStream()
  40. {
  41. $output = new StreamOutput($this->stream);
  42. $this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
  43. }
  44. public function testDoWrite()
  45. {
  46. $output = new StreamOutput($this->stream);
  47. $output->writeln('foo');
  48. rewind($output->getStream());
  49. $this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
  50. }
  51. }