StreamOutputTest.php 1.6 KB

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