StreamOutputTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 Symfony\Component\Console\Output\Output;
  12. use Symfony\Component\Console\Output\StreamOutput;
  13. class StreamOutputTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $stream;
  16. protected function setUp()
  17. {
  18. $this->stream = fopen('php://memory', 'a', false);
  19. }
  20. protected function tearDown()
  21. {
  22. $this->stream = null;
  23. }
  24. public function testConstructor()
  25. {
  26. $output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
  27. $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
  28. $this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
  29. }
  30. /**
  31. * @expectedException \InvalidArgumentException
  32. * @expectedExceptionMessage The StreamOutput class needs a stream as its first argument.
  33. */
  34. public function testStreamIsRequired()
  35. {
  36. new StreamOutput('foo');
  37. }
  38. public function testGetStream()
  39. {
  40. $output = new StreamOutput($this->stream);
  41. $this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
  42. }
  43. public function testDoWrite()
  44. {
  45. $output = new StreamOutput($this->stream);
  46. $output->writeln('foo');
  47. rewind($output->getStream());
  48. $this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
  49. }
  50. }