StreamOutputTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. public function testConstructor()
  21. {
  22. try {
  23. $output = new StreamOutput('foo');
  24. $this->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
  25. } catch (\Exception $e) {
  26. $this->assertInstanceOf('\InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the first argument is not a stream');
  27. $this->assertEquals('The StreamOutput class needs a stream as its first argument.', $e->getMessage());
  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->assertTrue($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'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
  44. }
  45. }