NullOutputTest.php 2.5 KB

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