StreamOutputTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. require_once __DIR__.'/../../../../bootstrap.php';
  10. use Symfony\Components\Console\Output\Output;
  11. use Symfony\Components\Console\Output\StreamOutput;
  12. $t = new LimeTest(5);
  13. $stream = fopen('php://memory', 'a', false);
  14. // __construct()
  15. $t->diag('__construct()');
  16. try
  17. {
  18. $output = new StreamOutput('foo');
  19. $t->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
  20. }
  21. catch (\InvalidArgumentException $e)
  22. {
  23. $t->pass('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
  24. }
  25. $output = new StreamOutput($stream, Output::VERBOSITY_QUIET, true);
  26. $t->is($output->getVerbosity(), Output::VERBOSITY_QUIET, '__construct() takes the verbosity as its first argument');
  27. $t->is($output->isDecorated(), true, '__construct() takes the decorated flag as its second argument');
  28. // ->getStream()
  29. $t->diag('->getStream()');
  30. $output = new StreamOutput($stream);
  31. $t->is($output->getStream(), $stream, '->getStream() returns the current stream');
  32. // ->doWrite()
  33. $t->diag('->doWrite()');
  34. $output = new StreamOutput($stream);
  35. $output->write('foo');
  36. rewind($output->getStream());
  37. $t->is(stream_get_contents($output->getStream()), "foo\n", '->doWrite() writes to the stream');