StreamOutputTest.php 2.0 KB

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