ConsoleOutputTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\ConsoleOutput;
  14. use Symfony\Component\Console\Output\Output;
  15. class ConsoleOutputTest extends TestCase
  16. {
  17. public function testConstructorWithoutFormatter()
  18. {
  19. $output = new ConsoleOutput(Output::VERBOSITY_QUIET, true);
  20. $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
  21. $this->assertNotSame($output->getFormatter(), $output->getErrorOutput()->getFormatter(), 'ErrorOutput should use it own formatter');
  22. }
  23. public function testConstructorWithFormatter()
  24. {
  25. $output = new ConsoleOutput(Output::VERBOSITY_QUIET, true, $formatter = new OutputFormatter());
  26. $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
  27. $this->assertSame($formatter, $output->getFormatter());
  28. $this->assertSame($formatter, $output->getErrorOutput()->getFormatter(), 'Output and ErrorOutput should use the same provided formatter');
  29. }
  30. public function testSetFormatter()
  31. {
  32. $output = new ConsoleOutput();
  33. $outputFormatter = new OutputFormatter();
  34. $output->setFormatter($outputFormatter);
  35. $this->assertSame($outputFormatter, $output->getFormatter());
  36. $this->assertSame($outputFormatter, $output->getErrorOutput()->getFormatter());
  37. }
  38. public function testSetVerbosity()
  39. {
  40. $output = new ConsoleOutput();
  41. $output->setVerbosity(Output::VERBOSITY_VERBOSE);
  42. $this->assertSame(Output::VERBOSITY_VERBOSE, $output->getVerbosity());
  43. }
  44. }