Update vendored libs
This commit is contained in:
163
vendor/symfony/console/Tests/Output/ConsoleSectionOutputTest.php
vendored
Normal file
163
vendor/symfony/console/Tests/Output/ConsoleSectionOutputTest.php
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Input\StreamableInputInterface;
|
||||
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
|
||||
class ConsoleSectionOutputTest extends TestCase
|
||||
{
|
||||
private $stream;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->stream = fopen('php://memory', 'r+b', false);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->stream = null;
|
||||
}
|
||||
|
||||
public function testClearAll()
|
||||
{
|
||||
$sections = [];
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output->writeln('Foo'.PHP_EOL.'Bar');
|
||||
$output->clear();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('Foo'.PHP_EOL.'Bar'.PHP_EOL.sprintf("\x1b[%dA", 2)."\x1b[0J", stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testClearNumberOfLines()
|
||||
{
|
||||
$sections = [];
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output->writeln("Foo\nBar\nBaz\nFooBar");
|
||||
$output->clear(2);
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals("Foo\nBar\nBaz\nFooBar".PHP_EOL.sprintf("\x1b[%dA", 2)."\x1b[0J", stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testClearNumberOfLinesWithMultipleSections()
|
||||
{
|
||||
$output = new StreamOutput($this->stream);
|
||||
$sections = [];
|
||||
$output1 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output2->writeln('Foo');
|
||||
$output2->writeln('Bar');
|
||||
$output2->clear(1);
|
||||
$output1->writeln('Baz');
|
||||
|
||||
rewind($output->getStream());
|
||||
|
||||
$this->assertEquals('Foo'.PHP_EOL.'Bar'.PHP_EOL."\x1b[1A\x1b[0J\e[1A\e[0J".'Baz'.PHP_EOL.'Foo'.PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testClearPreservingEmptyLines()
|
||||
{
|
||||
$output = new StreamOutput($this->stream);
|
||||
$sections = [];
|
||||
$output1 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output2->writeln(PHP_EOL.'foo');
|
||||
$output2->clear(1);
|
||||
$output1->writeln('bar');
|
||||
|
||||
rewind($output->getStream());
|
||||
|
||||
$this->assertEquals(PHP_EOL.'foo'.PHP_EOL."\x1b[1A\x1b[0J\x1b[1A\x1b[0J".'bar'.PHP_EOL.PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testOverwrite()
|
||||
{
|
||||
$sections = [];
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output->writeln('Foo');
|
||||
$output->overwrite('Bar');
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('Foo'.PHP_EOL."\x1b[1A\x1b[0JBar".PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testOverwriteMultipleLines()
|
||||
{
|
||||
$sections = [];
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output->writeln('Foo'.PHP_EOL.'Bar'.PHP_EOL.'Baz');
|
||||
$output->overwrite('Bar');
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('Foo'.PHP_EOL.'Bar'.PHP_EOL.'Baz'.PHP_EOL.sprintf("\x1b[%dA", 3)."\x1b[0J".'Bar'.PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testAddingMultipleSections()
|
||||
{
|
||||
$sections = [];
|
||||
$output1 = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$this->assertCount(2, $sections);
|
||||
}
|
||||
|
||||
public function testMultipleSectionsOutput()
|
||||
{
|
||||
$output = new StreamOutput($this->stream);
|
||||
$sections = [];
|
||||
$output1 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output1->writeln('Foo');
|
||||
$output2->writeln('Bar');
|
||||
|
||||
$output1->overwrite('Baz');
|
||||
$output2->overwrite('Foobar');
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('Foo'.PHP_EOL.'Bar'.PHP_EOL."\x1b[2A\x1b[0JBar".PHP_EOL."\x1b[1A\x1b[0JBaz".PHP_EOL.'Bar'.PHP_EOL."\x1b[1A\x1b[0JFoobar".PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testClearSectionContainingQuestion()
|
||||
{
|
||||
$inputStream = fopen('php://memory', 'r+b', false);
|
||||
fwrite($inputStream, "Batman & Robin\n");
|
||||
rewind($inputStream);
|
||||
|
||||
$input = $this->getMockBuilder(StreamableInputInterface::class)->getMock();
|
||||
$input->expects($this->once())->method('isInteractive')->willReturn(true);
|
||||
$input->expects($this->once())->method('getStream')->willReturn($inputStream);
|
||||
|
||||
$sections = [];
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
(new QuestionHelper())->ask($input, $output, new Question('What\'s your favorite super hero?'));
|
||||
$output->clear();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertSame('What\'s your favorite super hero?'.PHP_EOL."\x1b[2A\x1b[0J", stream_get_contents($output->getStream()));
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\Console\Tests\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
|
||||
class OutputTest extends TestCase
|
||||
{
|
||||
@@ -77,10 +77,23 @@ class OutputTest extends TestCase
|
||||
public function testWriteAnArrayOfMessages()
|
||||
{
|
||||
$output = new TestOutput();
|
||||
$output->writeln(array('foo', 'bar'));
|
||||
$output->writeln(['foo', 'bar']);
|
||||
$this->assertEquals("foo\nbar\n", $output->output, '->writeln() can take an array of messages to output');
|
||||
}
|
||||
|
||||
public function testWriteAnIterableOfMessages()
|
||||
{
|
||||
$output = new TestOutput();
|
||||
$output->writeln($this->generateMessages());
|
||||
$this->assertEquals("foo\nbar\n", $output->output, '->writeln() can take an iterable of messages to output');
|
||||
}
|
||||
|
||||
private function generateMessages(): iterable
|
||||
{
|
||||
yield 'foo';
|
||||
yield 'bar';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideWriteArguments
|
||||
*/
|
||||
@@ -93,10 +106,10 @@ class OutputTest extends TestCase
|
||||
|
||||
public function provideWriteArguments()
|
||||
{
|
||||
return array(
|
||||
array('<info>foo</info>', Output::OUTPUT_RAW, "<info>foo</info>\n"),
|
||||
array('<info>foo</info>', Output::OUTPUT_PLAIN, "foo\n"),
|
||||
);
|
||||
return [
|
||||
['<info>foo</info>', Output::OUTPUT_RAW, "<info>foo</info>\n"],
|
||||
['<info>foo</info>', Output::OUTPUT_PLAIN, "foo\n"],
|
||||
];
|
||||
}
|
||||
|
||||
public function testWriteWithDecorationTurnedOff()
|
||||
@@ -109,7 +122,7 @@ class OutputTest extends TestCase
|
||||
|
||||
public function testWriteDecoratedMessage()
|
||||
{
|
||||
$fooStyle = new OutputFormatterStyle('yellow', 'red', array('blink'));
|
||||
$fooStyle = new OutputFormatterStyle('yellow', 'red', ['blink']);
|
||||
$output = new TestOutput();
|
||||
$output->getFormatter()->setStyle('FOO', $fooStyle);
|
||||
$output->setDecorated(true);
|
||||
@@ -150,13 +163,13 @@ class OutputTest extends TestCase
|
||||
|
||||
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'),
|
||||
);
|
||||
return [
|
||||
[Output::VERBOSITY_QUIET, '2', '->write() in QUIET mode only outputs when an explicit QUIET verbosity is passed'],
|
||||
[Output::VERBOSITY_NORMAL, '123', '->write() in NORMAL mode outputs anything below an explicit VERBOSE verbosity'],
|
||||
[Output::VERBOSITY_VERBOSE, '1234', '->write() in VERBOSE mode outputs anything below an explicit VERY_VERBOSE verbosity'],
|
||||
[Output::VERBOSITY_VERY_VERBOSE, '12345', '->write() in VERY_VERBOSE mode outputs anything below an explicit DEBUG verbosity'],
|
||||
[Output::VERBOSITY_DEBUG, '123456', '->write() in DEBUG mode outputs everything'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user