NullOutputTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\Component\Console\Tests\Output;
  11. use Symfony\Component\Console\Formatter\OutputFormatter;
  12. use Symfony\Component\Console\Output\NullOutput;
  13. use Symfony\Component\Console\Output\Output;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class NullOutputTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function testConstructor()
  18. {
  19. $output = new NullOutput();
  20. ob_start();
  21. $output->write('foo');
  22. $buffer = ob_get_clean();
  23. $this->assertSame('', $buffer, '->write() does nothing (at least nothing is printed)');
  24. $this->assertFalse($output->isDecorated(), '->isDecorated() returns false');
  25. }
  26. public function testVerbosity()
  27. {
  28. $output = new NullOutput();
  29. $this->assertSame(OutputInterface::VERBOSITY_QUIET, $output->getVerbosity(), '->getVerbosity() returns VERBOSITY_QUIET for NullOutput by default');
  30. $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
  31. $this->assertSame(OutputInterface::VERBOSITY_QUIET, $output->getVerbosity(), '->getVerbosity() always returns VERBOSITY_QUIET for NullOutput');
  32. }
  33. public function testSetFormatter()
  34. {
  35. $output = new NullOutput();
  36. $outputFormatter = new OutputFormatter();
  37. $output->setFormatter($outputFormatter);
  38. $this->assertNotSame($outputFormatter, $output->getFormatter());
  39. }
  40. public function testSetVerbosity()
  41. {
  42. $output = new NullOutput();
  43. $output->setVerbosity(Output::VERBOSITY_NORMAL);
  44. $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity());
  45. }
  46. public function testSetDecorated()
  47. {
  48. $output = new NullOutput();
  49. $output->setDecorated(true);
  50. $this->assertFalse($output->isDecorated());
  51. }
  52. public function testIsQuiet()
  53. {
  54. $output = new NullOutput();
  55. $this->assertTrue($output->isQuiet());
  56. }
  57. public function testIsVerbose()
  58. {
  59. $output = new NullOutput();
  60. $this->assertFalse($output->isVerbose());
  61. }
  62. public function testIsVeryVerbose()
  63. {
  64. $output = new NullOutput();
  65. $this->assertFalse($output->isVeryVerbose());
  66. }
  67. public function testIsDebug()
  68. {
  69. $output = new NullOutput();
  70. $this->assertFalse($output->isDebug());
  71. }
  72. }