StreamOutputTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. $output = new StreamOutput('foo');
  23. $this->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
  24. } catch (\Exception $e) {
  25. $this->assertInstanceOf('\InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the first argument is not a stream');
  26. $this->assertEquals('The StreamOutput class needs a stream as its first argument.', $e->getMessage());
  27. }
  28. $output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
  29. $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
  30. $this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
  31. }
  32. public function testGetStream()
  33. {
  34. $output = new StreamOutput($this->stream);
  35. $this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
  36. }
  37. public function testDoWrite()
  38. {
  39. $output = new StreamOutput($this->stream);
  40. $output->writeln('foo');
  41. rewind($output->getStream());
  42. $this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
  43. }
  44. }