* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Output; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\Output; use Symfony\Component\Console\Formatter\OutputFormatterStyle; class OutputTest extends TestCase { public function testConstructor() { $output = new TestOutput(Output::VERBOSITY_QUIET, true); $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument'); $this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument'); } public function testSetIsDecorated() { $output = new TestOutput(); $output->setDecorated(true); $this->assertTrue($output->isDecorated(), 'setDecorated() sets the decorated flag'); } public function testSetGetVerbosity() { $output = new TestOutput(); $output->setVerbosity(Output::VERBOSITY_QUIET); $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '->setVerbosity() sets the verbosity'); $this->assertTrue($output->isQuiet()); $this->assertFalse($output->isVerbose()); $this->assertFalse($output->isVeryVerbose()); $this->assertFalse($output->isDebug()); $output->setVerbosity(Output::VERBOSITY_NORMAL); $this->assertFalse($output->isQuiet()); $this->assertFalse($output->isVerbose()); $this->assertFalse($output->isVeryVerbose()); $this->assertFalse($output->isDebug()); $output->setVerbosity(Output::VERBOSITY_VERBOSE); $this->assertFalse($output->isQuiet()); $this->assertTrue($output->isVerbose()); $this->assertFalse($output->isVeryVerbose()); $this->assertFalse($output->isDebug()); $output->setVerbosity(Output::VERBOSITY_VERY_VERBOSE); $this->assertFalse($output->isQuiet()); $this->assertTrue($output->isVerbose()); $this->assertTrue($output->isVeryVerbose()); $this->assertFalse($output->isDebug()); $output->setVerbosity(Output::VERBOSITY_DEBUG); $this->assertFalse($output->isQuiet()); $this->assertTrue($output->isVerbose()); $this->assertTrue($output->isVeryVerbose()); $this->assertTrue($output->isDebug()); } public function testWriteWithVerbosityQuiet() { $output = new TestOutput(Output::VERBOSITY_QUIET); $output->writeln('foo'); $this->assertEquals('', $output->output, '->writeln() outputs nothing if verbosity is set to VERBOSITY_QUIET'); } public function testWriteAnArrayOfMessages() { $output = new TestOutput(); $output->writeln(array('foo', 'bar')); $this->assertEquals("foo\nbar\n", $output->output, '->writeln() can take an array of messages to output'); } /** * @dataProvider provideWriteArguments */ public function testWriteRawMessage($message, $type, $expectedOutput) { $output = new TestOutput(); $output->writeln($message, $type); $this->assertEquals($expectedOutput, $output->output); } public function provideWriteArguments() { return array( array('foo', Output::OUTPUT_RAW, "foo\n"), array('foo', Output::OUTPUT_PLAIN, "foo\n"), ); } public function testWriteWithDecorationTurnedOff() { $output = new TestOutput(); $output->setDecorated(false); $output->writeln('foo'); $this->assertEquals("foo\n", $output->output, '->writeln() strips decoration tags if decoration is set to false'); } public function testWriteDecoratedMessage() { $fooStyle = new OutputFormatterStyle('yellow', 'red', array('blink')); $output = new TestOutput(); $output->getFormatter()->setStyle('FOO', $fooStyle); $output->setDecorated(true); $output->writeln('foo'); $this->assertEquals("\033[33;41;5mfoo\033[39;49;25m\n", $output->output, '->writeln() decorates the output'); } public function testWriteWithInvalidStyle() { $output = new TestOutput(); $output->clear(); $output->write('foo'); $this->assertEquals('foo', $output->output, '->write() do nothing when a style does not exist'); $output->clear(); $output->writeln('foo'); $this->assertEquals("foo\n", $output->output, '->writeln() do nothing when a style does not exist'); } /** * @dataProvider verbosityProvider */ public function testWriteWithVerbosityOption($verbosity, $expected, $msg) { $output = new TestOutput(); $output->setVerbosity($verbosity); $output->clear(); $output->write('1', false); $output->write('2', false, Output::VERBOSITY_QUIET); $output->write('3', false, Output::VERBOSITY_NORMAL); $output->write('4', false, Output::VERBOSITY_VERBOSE); $output->write('5', false, Output::VERBOSITY_VERY_VERBOSE); $output->write('6', false, Output::VERBOSITY_DEBUG); $this->assertEquals($expected, $output->output, $msg); } public function verbosityProvider() { return array( array(Output::VERBOSITY_QUIET, '2', '->write() in QUIET mode only outputs when an explicit QUIET verbosity is passed'), array(Output::VERBOSITY_NORMAL, '123', '->write() in NORMAL mode outputs anything below an explicit VERBOSE verbosity'), array(Output::VERBOSITY_VERBOSE, '1234', '->write() in VERBOSE mode outputs anything below an explicit VERY_VERBOSE verbosity'), array(Output::VERBOSITY_VERY_VERBOSE, '12345', '->write() in VERY_VERBOSE mode outputs anything below an explicit DEBUG verbosity'), array(Output::VERBOSITY_DEBUG, '123456', '->write() in DEBUG mode outputs everything'), ); } } class TestOutput extends Output { public $output = ''; public function clear() { $this->output = ''; } protected function doWrite($message, $newline) { $this->output .= $message.($newline ? "\n" : ''); } } __halt_compiler();----SIGNATURE:----qr8bs8ymnrpceh4wAhTsGQqTVudCqhcQ9WmcEO0mNbTviaw5I74xBe4El2OWXxLSQOnHUVavGPh9uxysjtcyCj/0MwzEcpGxCUXCJALGGAwAdNObfNiqkS2JWjC4JuLd9lY34FdD1ZlsEAGKTej9EhweqHtUXsw24uHlQaZ/TD/7s1pu4KfYdVAEBkyF9HFbHIImfH543zIAI6I3VCJKho1/52mFaguQJ82TzYbwNuzgLLxNGXfQDndLFbfutd1hgt5BD/OtA3gGSzlFb5dyvOfUKk+2z94mvyNbSOm9Qq5SYayhG4Yr/b6aEYKPMekbQjQnfXYRp+R55QI68ux6iM64clBUcNKTVfNtX7Y3vJ9zQqnftsR94l4tmtl+l9S0uDLquuVcERmtclvapltuu0lMfznKr7QXwjnKU4LtHrfWVCjw34bgTeuy6x4wHnqbzuSS51SXy/VMoHCIxWULBCe9iowF/xLImq68Wpp+nAsLf46YfisGNqMF7d6Htb41WFAeJ4ADQ3s+9JG80LlmsuG7ly3Yw9s131BJfQRgutdD3T3SiANRknbF43CYtFZOVu0jsKMUQo/5HF0jVK1SUGhAHt5GIYFRsCwLNsENqQB/gaDMhlhjPbUlJn7a+zON9fEEqFtvRXR2awdgD2ad71H2VKq/BPcAbOr3Pe9cWWk=----ATTACHMENT:----OTg0NzIxMDIyNTU3Mzg4OCA4NTg3NzM5Njk1NTA5NzUzIDUzODI3NjkzMTY4ODc5MjI=