NullOutputTest.php 2.8 KB

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