StreamOutputTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. require_once __DIR__.'/../../../bootstrap.php';
  11. use Symfony\Components\Console\Output\Output;
  12. use Symfony\Components\Console\Output\StreamOutput;
  13. class StreamOutputTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $stream;
  16. public function setUp()
  17. {
  18. $this->stream = fopen('php://memory', 'a', false);
  19. }
  20. public function testConstructor()
  21. {
  22. try
  23. {
  24. $output = new StreamOutput('foo');
  25. $this->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
  26. }
  27. catch (\InvalidArgumentException $e)
  28. {
  29. }
  30. $output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
  31. $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
  32. $this->assertEquals(true, $output->isDecorated(), '__construct() takes the decorated flag as its second argument');
  33. }
  34. public function testGetStream()
  35. {
  36. $output = new StreamOutput($this->stream);
  37. $this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
  38. }
  39. public function testDoWrite()
  40. {
  41. $output = new StreamOutput($this->stream);
  42. $output->writeln('foo');
  43. rewind($output->getStream());
  44. $this->assertEquals("foo\n", stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
  45. }
  46. }