composer update
This commit is contained in:
98
vendor/symfony/console/Tests/ApplicationTest.php
vendored
98
vendor/symfony/console/Tests/ApplicationTest.php
vendored
@@ -824,6 +824,56 @@ class ApplicationTest extends TestCase
|
||||
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_linebreaks.txt', $tester->getDisplay(true), '->renderException() keep multiple line breaks');
|
||||
}
|
||||
|
||||
public function testRenderAnonymousException()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->register('foo')->setCode(function () {
|
||||
throw new class('') extends \InvalidArgumentException {
|
||||
};
|
||||
});
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->run(array('command' => 'foo'), array('decorated' => false));
|
||||
$this->assertContains('[InvalidArgumentException@anonymous]', $tester->getDisplay(true));
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->register('foo')->setCode(function () {
|
||||
throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', \get_class(new class() {
|
||||
})));
|
||||
});
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->run(array('command' => 'foo'), array('decorated' => false));
|
||||
$this->assertContains('Dummy type "@anonymous" is invalid.', $tester->getDisplay(true));
|
||||
}
|
||||
|
||||
public function testRenderExceptionStackTraceContainsRootException()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->register('foo')->setCode(function () {
|
||||
throw new class('') extends \InvalidArgumentException {
|
||||
};
|
||||
});
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->run(array('command' => 'foo'), array('decorated' => false));
|
||||
$this->assertContains('[InvalidArgumentException@anonymous]', $tester->getDisplay(true));
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->register('foo')->setCode(function () {
|
||||
throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', \get_class(new class() {
|
||||
})));
|
||||
});
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->run(array('command' => 'foo'), array('decorated' => false));
|
||||
$this->assertContains('Dummy type "@anonymous" is invalid.', $tester->getDisplay(true));
|
||||
}
|
||||
|
||||
public function testRun()
|
||||
{
|
||||
$application = new Application();
|
||||
@@ -960,6 +1010,30 @@ class ApplicationTest extends TestCase
|
||||
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
|
||||
}
|
||||
|
||||
public function testRunDispatchesIntegerExitCode()
|
||||
{
|
||||
$passedRightValue = false;
|
||||
|
||||
// We can assume here that some other test asserts that the event is dispatched at all
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use (&$passedRightValue) {
|
||||
$passedRightValue = (4 === $event->getExitCode());
|
||||
});
|
||||
|
||||
$application = new Application();
|
||||
$application->setDispatcher($dispatcher);
|
||||
$application->setAutoExit(false);
|
||||
|
||||
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
throw new \Exception('', 4);
|
||||
});
|
||||
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'test'));
|
||||
|
||||
$this->assertTrue($passedRightValue, '-> exit code 4 was passed in the console.terminate event');
|
||||
}
|
||||
|
||||
public function testRunReturnsExitCodeOneForExceptionCodeZero()
|
||||
{
|
||||
$exception = new \Exception('', 0);
|
||||
@@ -975,6 +1049,30 @@ class ApplicationTest extends TestCase
|
||||
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
|
||||
}
|
||||
|
||||
public function testRunDispatchesExitCodeOneForExceptionCodeZero()
|
||||
{
|
||||
$passedRightValue = false;
|
||||
|
||||
// We can assume here that some other test asserts that the event is dispatched at all
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use (&$passedRightValue) {
|
||||
$passedRightValue = (1 === $event->getExitCode());
|
||||
});
|
||||
|
||||
$application = new Application();
|
||||
$application->setDispatcher($dispatcher);
|
||||
$application->setAutoExit(false);
|
||||
|
||||
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
throw new \Exception();
|
||||
});
|
||||
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'test'));
|
||||
|
||||
$this->assertTrue($passedRightValue, '-> exit code 1 was passed in the console.terminate event');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage An option with shortcut "e" already exists.
|
||||
|
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class Foo6Command extends Command
|
||||
|
@@ -322,6 +322,25 @@ more text
|
||||
EOF
|
||||
));
|
||||
}
|
||||
|
||||
public function testFormatAndWrap()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
|
||||
$this->assertSame("fo\no\e[37;41mb\e[39;49m\n\e[37;41mar\e[39;49m\nba\nz", $formatter->formatAndWrap('foo<error>bar</error> baz', 2));
|
||||
$this->assertSame("pr\ne \e[37;41m\e[39;49m\n\e[37;41mfo\e[39;49m\n\e[37;41mo \e[39;49m\n\e[37;41mba\e[39;49m\n\e[37;41mr \e[39;49m\n\e[37;41mba\e[39;49m\n\e[37;41mz\e[39;49m \npo\nst", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 2));
|
||||
$this->assertSame("pre\e[37;41m\e[39;49m\n\e[37;41mfoo\e[39;49m\n\e[37;41mbar\e[39;49m\n\e[37;41mbaz\e[39;49m\npos\nt", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 3));
|
||||
$this->assertSame("pre \e[37;41m\e[39;49m\n\e[37;41mfoo \e[39;49m\n\e[37;41mbar \e[39;49m\n\e[37;41mbaz\e[39;49m \npost", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 4));
|
||||
$this->assertSame("pre \e[37;41mf\e[39;49m\n\e[37;41moo ba\e[39;49m\n\e[37;41mr baz\e[39;49m\npost", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 5));
|
||||
|
||||
$formatter = new OutputFormatter();
|
||||
|
||||
$this->assertSame("fo\nob\nar\nba\nz", $formatter->formatAndWrap('foo<error>bar</error> baz', 2));
|
||||
$this->assertSame("pr\ne \nfo\no \nba\nr \nba\nz \npo\nst", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 2));
|
||||
$this->assertSame("pre\nfoo\nbar\nbaz\npos\nt", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 3));
|
||||
$this->assertSame("pre \nfoo \nbar \nbaz \npost", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 4));
|
||||
$this->assertSame("pre f\noo ba\nr baz\npost", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 5));
|
||||
}
|
||||
}
|
||||
|
||||
class TableCell
|
||||
|
@@ -25,6 +25,10 @@ class ProcessHelperTest extends TestCase
|
||||
*/
|
||||
public function testVariousProcessRuns($expected, $cmd, $verbosity, $error)
|
||||
{
|
||||
if (\is_string($cmd)) {
|
||||
$cmd = \method_exists(Process::class, 'fromShellCommandline') ? Process::fromShellCommandline($cmd) : new Process($cmd);
|
||||
}
|
||||
|
||||
$helper = new ProcessHelper();
|
||||
$helper->setHelperSet(new HelperSet(array(new DebugFormatterHelper())));
|
||||
$output = $this->getOutputStream($verbosity);
|
||||
@@ -41,7 +45,7 @@ class ProcessHelperTest extends TestCase
|
||||
$executed = false;
|
||||
$callback = function () use (&$executed) { $executed = true; };
|
||||
|
||||
$helper->run($output, 'php -r "echo 42;"', null, $callback);
|
||||
$helper->run($output, array('php', '-r', 'echo 42;'), null, $callback);
|
||||
$this->assertTrue($executed);
|
||||
}
|
||||
|
||||
@@ -81,12 +85,21 @@ EOT;
|
||||
OUT out message
|
||||
RES 252 Command did not run successfully
|
||||
|
||||
EOT;
|
||||
|
||||
$PHP = '\\' === \DIRECTORY_SEPARATOR ? '"!PHP!"' : '"$PHP"';
|
||||
$successOutputPhp = <<<EOT
|
||||
RUN php -r $PHP
|
||||
OUT 42
|
||||
RES Command ran successfully
|
||||
|
||||
EOT;
|
||||
|
||||
$errorMessage = 'An error occurred';
|
||||
$args = new Process(array('php', '-r', 'echo 42;'));
|
||||
$args = $args->getCommandLine();
|
||||
$successOutputProcessDebug = str_replace("'php' '-r' 'echo 42;'", $args, $successOutputProcessDebug);
|
||||
$fromShellCommandline = \method_exists(Process::class, 'fromShellCommandline') ? array(Process::class, 'fromShellCommandline') : function ($cmd) { return new Process($cmd); };
|
||||
|
||||
return array(
|
||||
array('', 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERBOSE, null),
|
||||
@@ -100,7 +113,9 @@ EOT;
|
||||
array($syntaxErrorOutputVerbose.$errorMessage.PHP_EOL, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERY_VERBOSE, $errorMessage),
|
||||
array($syntaxErrorOutputDebug.$errorMessage.PHP_EOL, 'php -r "fwrite(STDERR, \'error message\');usleep(500000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_DEBUG, $errorMessage),
|
||||
array($successOutputProcessDebug, array('php', '-r', 'echo 42;'), StreamOutput::VERBOSITY_DEBUG, null),
|
||||
array($successOutputDebug, new Process('php -r "echo 42;"'), StreamOutput::VERBOSITY_DEBUG, null),
|
||||
array($successOutputDebug, $fromShellCommandline('php -r "echo 42;"'), StreamOutput::VERBOSITY_DEBUG, null),
|
||||
array($successOutputProcessDebug, array(new Process(array('php', '-r', 'echo 42;'))), StreamOutput::VERBOSITY_DEBUG, null),
|
||||
array($successOutputPhp, array($fromShellCommandline('php -r '.$PHP), 'PHP' => 'echo 42;'), StreamOutput::VERBOSITY_DEBUG, null),
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -89,6 +89,63 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$this->assertEquals('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, true), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testAskChoiceNonInteractive()
|
||||
{
|
||||
$questionHelper = new QuestionHelper();
|
||||
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
$inputStream = $this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n");
|
||||
|
||||
$heroes = array('Superman', 'Batman', 'Spiderman');
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
|
||||
|
||||
$this->assertSame('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, 'Batman');
|
||||
$this->assertSame('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
|
||||
$this->assertNull($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
|
||||
$question->setValidator(null);
|
||||
$this->assertSame('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
||||
|
||||
try {
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
|
||||
$questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertSame('Value "" is invalid', $e->getMessage());
|
||||
}
|
||||
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
|
||||
$question->setMultiselect(true);
|
||||
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
|
||||
$question->setMultiselect(true);
|
||||
$question->setValidator(null);
|
||||
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, Batman');
|
||||
$question->setMultiselect(true);
|
||||
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, null);
|
||||
$question->setMultiselect(true);
|
||||
$this->assertNull($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
||||
|
||||
try {
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '');
|
||||
$question->setMultiselect(true);
|
||||
$questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertSame('Value "" is invalid', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testAsk()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
|
@@ -74,6 +74,18 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output);
|
||||
}
|
||||
|
||||
public function testAskChoiceWithChoiceValueAsDefault()
|
||||
{
|
||||
$questionHelper = new SymfonyQuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', array('Superman', 'Batman', 'Spiderman'), 'Batman');
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
$this->assertSame('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($this->getInputStream("Batman\n")), $output = $this->createOutputInterface(), $question));
|
||||
$this->assertOutputContains('What is your favorite superhero? [Batman]', $output);
|
||||
}
|
||||
|
||||
public function testAskReturnsNullIfValidatorAllowsIt()
|
||||
{
|
||||
$questionHelper = new SymfonyQuestionHelper();
|
||||
|
143
vendor/symfony/console/Tests/Helper/TableTest.php
vendored
143
vendor/symfony/console/Tests/Helper/TableTest.php
vendored
@@ -783,7 +783,7 @@ TABLE;
|
||||
$table->render();
|
||||
}
|
||||
|
||||
public function testColumnWith()
|
||||
public function testColumnWidth()
|
||||
{
|
||||
$table = new Table($output = $this->getOutputStream());
|
||||
$table
|
||||
@@ -815,7 +815,7 @@ TABLE;
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
public function testColumnWiths()
|
||||
public function testColumnWidths()
|
||||
{
|
||||
$table = new Table($output = $this->getOutputStream());
|
||||
$table
|
||||
@@ -974,6 +974,145 @@ TABLE;
|
||||
Table::getStyleDefinition('absent');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider renderSetTitle
|
||||
*/
|
||||
public function testSetTitle($headerTitle, $footerTitle, $style, $expected)
|
||||
{
|
||||
(new Table($output = $this->getOutputStream()))
|
||||
->setHeaderTitle($headerTitle)
|
||||
->setFooterTitle($footerTitle)
|
||||
->setHeaders(array('ISBN', 'Title', 'Author'))
|
||||
->setRows(array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
|
||||
array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens'),
|
||||
array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'),
|
||||
array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'),
|
||||
))
|
||||
->setStyle($style)
|
||||
->render()
|
||||
;
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
public function renderSetTitle()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'Books',
|
||||
'Page 1/2',
|
||||
'default',
|
||||
<<<'TABLE'
|
||||
+---------------+----------- Books --------+------------------+
|
||||
| ISBN | Title | Author |
|
||||
+---------------+--------------------------+------------------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
|
||||
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
|
||||
| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
|
||||
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
|
||||
+---------------+--------- Page 1/2 -------+------------------+
|
||||
|
||||
TABLE
|
||||
),
|
||||
array(
|
||||
'Books',
|
||||
'Page 1/2',
|
||||
'box',
|
||||
<<<'TABLE'
|
||||
┌───────────────┬─────────── Books ────────┬──────────────────┐
|
||||
│ ISBN │ Title │ Author │
|
||||
├───────────────┼──────────────────────────┼──────────────────┤
|
||||
│ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri │
|
||||
│ 9971-5-0210-0 │ A Tale of Two Cities │ Charles Dickens │
|
||||
│ 960-425-059-0 │ The Lord of the Rings │ J. R. R. Tolkien │
|
||||
│ 80-902734-1-6 │ And Then There Were None │ Agatha Christie │
|
||||
└───────────────┴───────── Page 1/2 ───────┴──────────────────┘
|
||||
|
||||
TABLE
|
||||
),
|
||||
array(
|
||||
'Boooooooooooooooooooooooooooooooooooooooooooooooooooooooks',
|
||||
'Page 1/999999999999999999999999999999999999999999999999999',
|
||||
'default',
|
||||
<<<'TABLE'
|
||||
+- Booooooooooooooooooooooooooooooooooooooooooooooooooooo... -+
|
||||
| ISBN | Title | Author |
|
||||
+---------------+--------------------------+------------------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
|
||||
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
|
||||
| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
|
||||
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
|
||||
+- Page 1/99999999999999999999999999999999999999999999999... -+
|
||||
|
||||
TABLE
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testColumnMaxWidths()
|
||||
{
|
||||
$table = new Table($output = $this->getOutputStream());
|
||||
$table
|
||||
->setRows(array(
|
||||
array('Divine Comedy', 'A Tale of Two Cities', 'The Lord of the Rings', 'And Then There Were None'),
|
||||
))
|
||||
->setColumnMaxWidth(1, 5)
|
||||
->setColumnMaxWidth(2, 10)
|
||||
->setColumnMaxWidth(3, 15);
|
||||
|
||||
$table->render();
|
||||
|
||||
$expected =
|
||||
<<<TABLE
|
||||
+---------------+-------+------------+-----------------+
|
||||
| Divine Comedy | A Tal | The Lord o | And Then There |
|
||||
| | e of | f the Ring | Were None |
|
||||
| | Two C | s | |
|
||||
| | ities | | |
|
||||
+---------------+-------+------------+-----------------+
|
||||
|
||||
TABLE;
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
public function testBoxedStyleWithColspan()
|
||||
{
|
||||
$boxed = new TableStyle();
|
||||
$boxed
|
||||
->setHorizontalBorderChars('─')
|
||||
->setVerticalBorderChars('│')
|
||||
->setCrossingChars('┼', '┌', '┬', '┐', '┤', '┘', '┴', '└', '├')
|
||||
;
|
||||
|
||||
$table = new Table($output = $this->getOutputStream());
|
||||
$table->setStyle($boxed);
|
||||
$table
|
||||
->setHeaders(array('ISBN', 'Title', 'Author'))
|
||||
->setRows(array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
|
||||
new TableSeparator(),
|
||||
array(new TableCell('This value spans 3 columns.', array('colspan' => 3))),
|
||||
))
|
||||
;
|
||||
$table->render();
|
||||
|
||||
$expected =
|
||||
<<<TABLE
|
||||
┌───────────────┬───────────────┬─────────────────┐
|
||||
│ ISBN │ Title │ Author │
|
||||
├───────────────┼───────────────┼─────────────────┤
|
||||
│ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri │
|
||||
├───────────────┼───────────────┼─────────────────┤
|
||||
│ This value spans 3 columns. │
|
||||
└───────────────┴───────────────┴─────────────────┘
|
||||
|
||||
TABLE;
|
||||
|
||||
$this->assertSame($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
protected function getOutputStream($decorated = false)
|
||||
{
|
||||
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);
|
||||
|
@@ -246,6 +246,11 @@ class ArgvInputTest extends TestCase
|
||||
new InputDefinition(array(new InputArgument('number'))),
|
||||
'The "-1" option does not exist.',
|
||||
),
|
||||
array(
|
||||
array('cli.php', '-fЩ'),
|
||||
new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))),
|
||||
'The "-Щ" option does not exist.',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -13,9 +13,12 @@ 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
|
||||
{
|
||||
@@ -23,7 +26,7 @@ class ConsoleSectionOutputTest extends TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->stream = fopen('php://memory', 'r+', false);
|
||||
$this->stream = fopen('php://memory', 'r+b', false);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
@@ -137,4 +140,24 @@ class ConsoleSectionOutputTest extends TestCase
|
||||
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 = array();
|
||||
$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()));
|
||||
}
|
||||
}
|
||||
|
@@ -90,4 +90,24 @@ class ApplicationTesterTest extends TestCase
|
||||
{
|
||||
$this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code');
|
||||
}
|
||||
|
||||
public function testErrorOutput()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->register('foo')
|
||||
->addArgument('foo')
|
||||
->setCode(function ($input, $output) {
|
||||
$output->getErrorOutput()->write('foo');
|
||||
})
|
||||
;
|
||||
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(
|
||||
array('command' => 'foo', 'foo' => 'bar'),
|
||||
array('capture_stderr_separately' => true)
|
||||
);
|
||||
|
||||
$this->assertSame('foo', $tester->getErrorOutput());
|
||||
}
|
||||
}
|
||||
|
@@ -160,4 +160,23 @@ class CommandTesterTest extends TestCase
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testErrorOutput()
|
||||
{
|
||||
$command = new Command('foo');
|
||||
$command->addArgument('command');
|
||||
$command->addArgument('foo');
|
||||
$command->setCode(function ($input, $output) {
|
||||
$output->getErrorOutput()->write('foo');
|
||||
}
|
||||
);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(
|
||||
array('foo' => 'bar'),
|
||||
array('capture_stderr_separately' => true)
|
||||
);
|
||||
|
||||
$this->assertSame('foo', $tester->getErrorOutput());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user