Update vendored libs
This commit is contained in:
@@ -21,7 +21,7 @@ abstract class AbstractQuestionHelperTest extends TestCase
|
||||
$mock = $this->getMockBuilder(StreamableInputInterface::class)->getMock();
|
||||
$mock->expects($this->any())
|
||||
->method('isInteractive')
|
||||
->will($this->returnValue($interactive));
|
||||
->willReturn($interactive);
|
||||
|
||||
if ($stream) {
|
||||
$mock->expects($this->any())
|
||||
|
||||
@@ -40,7 +40,7 @@ class FormatterHelperTest extends TestCase
|
||||
$this->assertEquals(
|
||||
'<error> Some text to display </error>'."\n".
|
||||
'<error> foo bar </error>',
|
||||
$formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'),
|
||||
$formatter->formatBlock(['Some text to display', 'foo bar'], 'error'),
|
||||
'::formatBlock() formats a message in a block'
|
||||
);
|
||||
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
|
||||
class HelperSetTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$mock_helper = $this->getGenericMockHelper('fake_helper');
|
||||
$helperset = new HelperSet(array('fake_helper_alias' => $mock_helper));
|
||||
$helperset = new HelperSet(['fake_helper_alias' => $mock_helper]);
|
||||
|
||||
$this->assertEquals($mock_helper, $helperset->get('fake_helper_alias'), '__construct sets given helper to helpers');
|
||||
$this->assertTrue($helperset->has('fake_helper_alias'), '__construct sets helper alias for given helper');
|
||||
@@ -46,7 +46,7 @@ class HelperSetTest extends TestCase
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$helperset = new HelperSet(array('fake_helper_alias' => $this->getGenericMockHelper('fake_helper')));
|
||||
$helperset = new HelperSet(['fake_helper_alias' => $this->getGenericMockHelper('fake_helper')]);
|
||||
$this->assertTrue($helperset->has('fake_helper'), '->has() finds set helper');
|
||||
$this->assertTrue($helperset->has('fake_helper_alias'), '->has() finds set helper by alias');
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class HelperSetTest extends TestCase
|
||||
{
|
||||
$helper_01 = $this->getGenericMockHelper('fake_helper_01');
|
||||
$helper_02 = $this->getGenericMockHelper('fake_helper_02');
|
||||
$helperset = new HelperSet(array('fake_helper_01_alias' => $helper_01, 'fake_helper_02_alias' => $helper_02));
|
||||
$helperset = new HelperSet(['fake_helper_01_alias' => $helper_01, 'fake_helper_02_alias' => $helper_02]);
|
||||
$this->assertEquals($helper_01, $helperset->get('fake_helper_01'), '->get() returns correct helper by name');
|
||||
$this->assertEquals($helper_01, $helperset->get('fake_helper_01_alias'), '->get() returns correct helper by alias');
|
||||
$this->assertEquals($helper_02, $helperset->get('fake_helper_02'), '->get() returns correct helper by name');
|
||||
@@ -101,7 +101,7 @@ class HelperSetTest extends TestCase
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper_01', $helperset));
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper_02', $helperset));
|
||||
|
||||
$helpers = array('fake_helper_01', 'fake_helper_02');
|
||||
$helpers = ['fake_helper_01', 'fake_helper_02'];
|
||||
$i = 0;
|
||||
|
||||
foreach ($helperset as $helper) {
|
||||
@@ -114,7 +114,7 @@ class HelperSetTest extends TestCase
|
||||
$mock_helper = $this->getMockBuilder('\Symfony\Component\Console\Helper\HelperInterface')->getMock();
|
||||
$mock_helper->expects($this->any())
|
||||
->method('getName')
|
||||
->will($this->returnValue($name));
|
||||
->willReturn($name);
|
||||
|
||||
if ($helperset) {
|
||||
$mock_helper->expects($this->any())
|
||||
|
||||
@@ -18,28 +18,28 @@ class HelperTest extends TestCase
|
||||
{
|
||||
public function formatTimeProvider()
|
||||
{
|
||||
return array(
|
||||
array(0, '< 1 sec'),
|
||||
array(1, '1 sec'),
|
||||
array(2, '2 secs'),
|
||||
array(59, '59 secs'),
|
||||
array(60, '1 min'),
|
||||
array(61, '1 min'),
|
||||
array(119, '1 min'),
|
||||
array(120, '2 mins'),
|
||||
array(121, '2 mins'),
|
||||
array(3599, '59 mins'),
|
||||
array(3600, '1 hr'),
|
||||
array(7199, '1 hr'),
|
||||
array(7200, '2 hrs'),
|
||||
array(7201, '2 hrs'),
|
||||
array(86399, '23 hrs'),
|
||||
array(86400, '1 day'),
|
||||
array(86401, '1 day'),
|
||||
array(172799, '1 day'),
|
||||
array(172800, '2 days'),
|
||||
array(172801, '2 days'),
|
||||
);
|
||||
return [
|
||||
[0, '< 1 sec'],
|
||||
[1, '1 sec'],
|
||||
[2, '2 secs'],
|
||||
[59, '59 secs'],
|
||||
[60, '1 min'],
|
||||
[61, '1 min'],
|
||||
[119, '1 min'],
|
||||
[120, '2 mins'],
|
||||
[121, '2 mins'],
|
||||
[3599, '59 mins'],
|
||||
[3600, '1 hr'],
|
||||
[7199, '1 hr'],
|
||||
[7200, '2 hrs'],
|
||||
[7201, '2 hrs'],
|
||||
[86399, '23 hrs'],
|
||||
[86400, '1 day'],
|
||||
[86401, '1 day'],
|
||||
[172799, '1 day'],
|
||||
[172800, '2 days'],
|
||||
[172801, '2 days'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Symfony\Component\Console\Tests\Helper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Helper\DebugFormatterHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Console\Helper\ProcessHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class ProcessHelperTest extends TestCase
|
||||
@@ -25,8 +25,12 @@ 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())));
|
||||
$helper->setHelperSet(new HelperSet([new DebugFormatterHelper()]));
|
||||
$output = $this->getOutputStream($verbosity);
|
||||
$helper->run($output, $cmd, $error);
|
||||
$this->assertEquals($expected, $this->getOutput($output));
|
||||
@@ -35,13 +39,13 @@ class ProcessHelperTest extends TestCase
|
||||
public function testPassedCallbackIsExecuted()
|
||||
{
|
||||
$helper = new ProcessHelper();
|
||||
$helper->setHelperSet(new HelperSet(array(new DebugFormatterHelper())));
|
||||
$helper->setHelperSet(new HelperSet([new DebugFormatterHelper()]));
|
||||
$output = $this->getOutputStream(StreamOutput::VERBOSITY_NORMAL);
|
||||
|
||||
$executed = false;
|
||||
$callback = function () use (&$executed) { $executed = true; };
|
||||
|
||||
$helper->run($output, 'php -r "echo 42;"', null, $callback);
|
||||
$helper->run($output, ['php', '-r', 'echo 42;'], null, $callback);
|
||||
$this->assertTrue($executed);
|
||||
}
|
||||
|
||||
@@ -81,27 +85,38 @@ 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 = new Process(['php', '-r', 'echo 42;']);
|
||||
$args = $args->getCommandLine();
|
||||
$successOutputProcessDebug = str_replace("'php' '-r' 'echo 42;'", $args, $successOutputProcessDebug);
|
||||
$fromShellCommandline = method_exists(Process::class, 'fromShellCommandline') ? [Process::class, 'fromShellCommandline'] : function ($cmd) { return new Process($cmd); };
|
||||
|
||||
return array(
|
||||
array('', 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERBOSE, null),
|
||||
array($successOutputVerbose, 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERY_VERBOSE, null),
|
||||
array($successOutputDebug, 'php -r "echo 42;"', StreamOutput::VERBOSITY_DEBUG, null),
|
||||
array($successOutputDebugWithTags, 'php -r "echo \'<info>42</info>\';"', StreamOutput::VERBOSITY_DEBUG, null),
|
||||
array('', 'php -r "syntax error"', StreamOutput::VERBOSITY_VERBOSE, null),
|
||||
array($syntaxErrorOutputVerbose, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERY_VERBOSE, null),
|
||||
array($syntaxErrorOutputDebug, 'php -r "fwrite(STDERR, \'error message\');usleep(500000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_DEBUG, null),
|
||||
array($errorMessage.PHP_EOL, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERBOSE, $errorMessage),
|
||||
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),
|
||||
);
|
||||
return [
|
||||
['', 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERBOSE, null],
|
||||
[$successOutputVerbose, 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERY_VERBOSE, null],
|
||||
[$successOutputDebug, 'php -r "echo 42;"', StreamOutput::VERBOSITY_DEBUG, null],
|
||||
[$successOutputDebugWithTags, 'php -r "echo \'<info>42</info>\';"', StreamOutput::VERBOSITY_DEBUG, null],
|
||||
['', 'php -r "syntax error"', StreamOutput::VERBOSITY_VERBOSE, null],
|
||||
[$syntaxErrorOutputVerbose, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERY_VERBOSE, null],
|
||||
[$syntaxErrorOutputDebug, 'php -r "fwrite(STDERR, \'error message\');usleep(500000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_DEBUG, null],
|
||||
[$errorMessage.PHP_EOL, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERBOSE, $errorMessage],
|
||||
[$syntaxErrorOutputVerbose.$errorMessage.PHP_EOL, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERY_VERBOSE, $errorMessage],
|
||||
[$syntaxErrorOutputDebug.$errorMessage.PHP_EOL, 'php -r "fwrite(STDERR, \'error message\');usleep(500000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_DEBUG, $errorMessage],
|
||||
[$successOutputProcessDebug, ['php', '-r', 'echo 42;'], StreamOutput::VERBOSITY_DEBUG, null],
|
||||
[$successOutputDebug, $fromShellCommandline('php -r "echo 42;"'), StreamOutput::VERBOSITY_DEBUG, null],
|
||||
[$successOutputProcessDebug, [new Process(['php', '-r', 'echo 42;'])], StreamOutput::VERBOSITY_DEBUG, null],
|
||||
[$successOutputPhp, [$fromShellCommandline('php -r '.$PHP), 'PHP' => 'echo 42;'], StreamOutput::VERBOSITY_DEBUG, null],
|
||||
];
|
||||
}
|
||||
|
||||
private function getOutputStream($verbosity)
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\Helper;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
/**
|
||||
@@ -21,6 +23,19 @@ use Symfony\Component\Console\Output\StreamOutput;
|
||||
*/
|
||||
class ProgressBarTest extends TestCase
|
||||
{
|
||||
private $colSize;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->colSize = getenv('COLUMNS');
|
||||
putenv('COLUMNS=120');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
putenv($this->colSize ? 'COLUMNS='.$this->colSize : 'COLUMNS');
|
||||
}
|
||||
|
||||
public function testMultipleStart()
|
||||
{
|
||||
$bar = new ProgressBar($output = $this->getOutputStream());
|
||||
@@ -310,6 +325,88 @@ class ProgressBarTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testOverwriteWithSectionOutput()
|
||||
{
|
||||
$sections = [];
|
||||
$stream = $this->getOutputStream(true);
|
||||
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
|
||||
$bar = new ProgressBar($output, 50);
|
||||
$bar->start();
|
||||
$bar->display();
|
||||
$bar->advance();
|
||||
$bar->advance();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 2/50 [=>--------------------------] 4%'.PHP_EOL,
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testOverwriteMultipleProgressBarsWithSectionOutputs()
|
||||
{
|
||||
$sections = [];
|
||||
$stream = $this->getOutputStream(true);
|
||||
$output1 = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
|
||||
$progress = new ProgressBar($output1, 50);
|
||||
$progress2 = new ProgressBar($output2, 50);
|
||||
|
||||
$progress->start();
|
||||
$progress2->start();
|
||||
|
||||
$progress2->advance();
|
||||
$progress->advance();
|
||||
|
||||
rewind($stream->getStream());
|
||||
|
||||
$this->assertEquals(
|
||||
' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
"\x1b[2A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
' 1/50 [>---------------------------] 2%'.PHP_EOL,
|
||||
stream_get_contents($stream->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleSectionsWithCustomFormat()
|
||||
{
|
||||
$sections = [];
|
||||
$stream = $this->getOutputStream(true);
|
||||
$output1 = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
|
||||
ProgressBar::setFormatDefinition('test', '%current%/%max% [%bar%] %percent:3s%% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.');
|
||||
|
||||
$progress = new ProgressBar($output1, 50);
|
||||
$progress2 = new ProgressBar($output2, 50);
|
||||
$progress2->setFormat('test');
|
||||
|
||||
$progress->start();
|
||||
$progress2->start();
|
||||
|
||||
$progress->advance();
|
||||
$progress2->advance();
|
||||
|
||||
rewind($stream->getStream());
|
||||
|
||||
$this->assertEquals(' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
' 0/50 [>] 0% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.'.PHP_EOL.
|
||||
"\x1b[4A\x1b[0J".' 0/50 [>] 0% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.'.PHP_EOL.
|
||||
"\x1b[3A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
' 0/50 [>] 0% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.'.PHP_EOL.
|
||||
"\x1b[3A\x1b[0J".' 1/50 [>] 2% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.'.PHP_EOL,
|
||||
stream_get_contents($stream->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testStartWithMax()
|
||||
{
|
||||
$bar = new ProgressBar($output = $this->getOutputStream());
|
||||
@@ -592,6 +689,29 @@ class ProgressBarTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testSettingMaxStepsDuringProgressing()
|
||||
{
|
||||
$output = $this->getOutputStream();
|
||||
$bar = new ProgressBar($output);
|
||||
$bar->start();
|
||||
$bar->setProgress(2);
|
||||
$bar->setMaxSteps(10);
|
||||
$bar->setProgress(5);
|
||||
$bar->setMaxSteps(100);
|
||||
$bar->setProgress(10);
|
||||
$bar->finish();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
rtrim(' 0 [>---------------------------]').
|
||||
rtrim($this->generateOutput(' 2 [-->-------------------------]')).
|
||||
rtrim($this->generateOutput(' 5/10 [==============>-------------] 50%')).
|
||||
rtrim($this->generateOutput(' 10/100 [==>-------------------------] 10%')).
|
||||
rtrim($this->generateOutput(' 100/100 [============================] 100%')),
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithSmallScreen()
|
||||
{
|
||||
$output = $this->getOutputStream();
|
||||
@@ -752,12 +872,12 @@ class ProgressBarTest extends TestCase
|
||||
*/
|
||||
public function provideFormat()
|
||||
{
|
||||
return array(
|
||||
array('normal'),
|
||||
array('verbose'),
|
||||
array('very_verbose'),
|
||||
array('debug'),
|
||||
);
|
||||
return [
|
||||
['normal'],
|
||||
['verbose'],
|
||||
['very_verbose'],
|
||||
['debug'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOutputStream($decorated = true, $verbosity = StreamOutput::VERBOSITY_NORMAL)
|
||||
|
||||
@@ -79,7 +79,7 @@ class ProgressIndicatorTest extends TestCase
|
||||
|
||||
public function testCustomIndicatorValues()
|
||||
{
|
||||
$bar = new ProgressIndicator($output = $this->getOutputStream(), null, 100, array('a', 'b', 'c'));
|
||||
$bar = new ProgressIndicator($output = $this->getOutputStream(), null, 100, ['a', 'b', 'c']);
|
||||
|
||||
$bar->start('Starting...');
|
||||
usleep(101000);
|
||||
@@ -106,7 +106,7 @@ class ProgressIndicatorTest extends TestCase
|
||||
*/
|
||||
public function testCannotSetInvalidIndicatorCharacters()
|
||||
{
|
||||
$bar = new ProgressIndicator($this->getOutputStream(), null, 100, array('1'));
|
||||
$bar = new ProgressIndicator($this->getOutputStream(), null, 100, ['1']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,12 +161,12 @@ class ProgressIndicatorTest extends TestCase
|
||||
*/
|
||||
public function provideFormat()
|
||||
{
|
||||
return array(
|
||||
array('normal'),
|
||||
array('verbose'),
|
||||
array('very_verbose'),
|
||||
array('debug'),
|
||||
);
|
||||
return [
|
||||
['normal'],
|
||||
['verbose'],
|
||||
['very_verbose'],
|
||||
['debug'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOutputStream($decorated = true, $verbosity = StreamOutput::VERBOSITY_NORMAL)
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
@@ -29,10 +29,10 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
{
|
||||
$questionHelper = new QuestionHelper();
|
||||
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
|
||||
$heroes = array('Superman', 'Batman', 'Spiderman');
|
||||
$heroes = ['Superman', 'Batman', 'Spiderman'];
|
||||
|
||||
$inputStream = $this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n");
|
||||
|
||||
@@ -68,21 +68,85 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Batman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Superman', 'Spiderman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Superman', 'Spiderman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0,1');
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Superman', 'Batman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, ' 0 , 1 ');
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Superman', 'Batman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, 0);
|
||||
// We are supposed to get the default value since we are not in interactive mode
|
||||
$this->assertEquals('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, true), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testAskChoiceNonInteractive()
|
||||
{
|
||||
$questionHelper = new QuestionHelper();
|
||||
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
$inputStream = $this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n");
|
||||
|
||||
$heroes = ['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(['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(['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(['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));
|
||||
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', ['a' => 'Batman', 'b' => 'Superman'], 'a');
|
||||
$this->assertSame('a', $questionHelper->ask($this->createStreamableInputInterfaceMock('', false), $this->createOutputInterface(), $question), 'ChoiceQuestion validator returns the key if it\'s a string');
|
||||
|
||||
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()
|
||||
@@ -118,11 +182,11 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\nF00\177\177oo\t\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new Question('Please select a bundle', 'FrameworkBundle');
|
||||
$question->setAutocompleterValues(array('AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle'));
|
||||
$question->setAutocompleterValues(['AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle']);
|
||||
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AsseticBundleTest', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
@@ -144,15 +208,75 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$inputStream = $this->getInputStream("\033[A\033[A\n\033[B\033[B\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));
|
||||
$dialog->setHelperSet(new HelperSet([new FormatterHelper()]));
|
||||
|
||||
$question = new ChoiceQuestion('Please select a bundle', array(1 => 'AcmeDemoBundle', 4 => 'AsseticBundle'));
|
||||
$question = new ChoiceQuestion('Please select a bundle', [1 => 'AcmeDemoBundle', 4 => 'AsseticBundle']);
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AsseticBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testAskWithAutocompleteWithExactMatch()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
$inputStream = $this->getInputStream("b\n");
|
||||
|
||||
$possibleChoices = [
|
||||
'a' => 'berlin',
|
||||
'b' => 'copenhagen',
|
||||
'c' => 'amsterdam',
|
||||
];
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setHelperSet(new HelperSet([new FormatterHelper()]));
|
||||
|
||||
$question = new ChoiceQuestion('Please select a city', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
$this->assertSame('b', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function getInputs()
|
||||
{
|
||||
return [
|
||||
['$'], // 1 byte character
|
||||
['¢'], // 2 bytes character
|
||||
['€'], // 3 bytes character
|
||||
['𐍈'], // 4 bytes character
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInputs
|
||||
*/
|
||||
public function testAskWithAutocompleteWithMultiByteCharacter($character)
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
$inputStream = $this->getInputStream("$character\n");
|
||||
|
||||
$possibleChoices = [
|
||||
'$' => '1 byte character',
|
||||
'¢' => '2 bytes character',
|
||||
'€' => '3 bytes character',
|
||||
'𐍈' => '4 bytes character',
|
||||
];
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setHelperSet(new HelperSet([new FormatterHelper()]));
|
||||
|
||||
$question = new ChoiceQuestion('Please select a character', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
$this->assertSame($character, $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testAutocompleteWithTrailingBackslash()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
@@ -162,12 +286,12 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$inputStream = $this->getInputStream('E');
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new Question('');
|
||||
$expectedCompletion = 'ExampleNamespace\\';
|
||||
$question->setAutocompleterValues(array($expectedCompletion));
|
||||
$question->setAutocompleterValues([$expectedCompletion]);
|
||||
|
||||
$output = $this->createOutputInterface();
|
||||
$dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $output, $question);
|
||||
@@ -178,11 +302,11 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
// Shell control (esc) sequences are not so important: we only care that
|
||||
// <hl> tag is interpreted correctly and replaced
|
||||
$irrelevantEscSequences = array(
|
||||
$irrelevantEscSequences = [
|
||||
"\0337" => '', // Save cursor position
|
||||
"\0338" => '', // Restore cursor position
|
||||
"\033[K" => '', // Clear line from cursor till the end
|
||||
);
|
||||
];
|
||||
|
||||
$importantActualOutput = strtr($actualOutput, $irrelevantEscSequences);
|
||||
|
||||
@@ -194,7 +318,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
public function testAskHiddenResponse()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('This test is not supported on Windows');
|
||||
}
|
||||
|
||||
@@ -220,14 +344,14 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
public function getAskConfirmationData()
|
||||
{
|
||||
return array(
|
||||
array('', true),
|
||||
array('', false, false),
|
||||
array('y', true),
|
||||
array('yes', true),
|
||||
array('n', false),
|
||||
array('no', false),
|
||||
);
|
||||
return [
|
||||
['', true],
|
||||
['', false, false],
|
||||
['y', true],
|
||||
['yes', true],
|
||||
['n', false],
|
||||
['no', false],
|
||||
];
|
||||
}
|
||||
|
||||
public function testAskConfirmationWithCustomTrueAnswer()
|
||||
@@ -244,12 +368,12 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
public function testAskAndValidate()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$error = 'This is not a color!';
|
||||
$validator = function ($color) use ($error) {
|
||||
if (!in_array($color, array('white', 'black'))) {
|
||||
if (!\in_array($color, ['white', 'black'])) {
|
||||
throw new \InvalidArgumentException($error);
|
||||
}
|
||||
|
||||
@@ -277,14 +401,14 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
*/
|
||||
public function testSelectChoiceFromSimpleChoices($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
$possibleChoices = [
|
||||
'My environment 1',
|
||||
'My environment 2',
|
||||
'My environment 3',
|
||||
);
|
||||
];
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
@@ -296,14 +420,14 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
public function simpleAnswerProvider()
|
||||
{
|
||||
return array(
|
||||
array(0, 'My environment 1'),
|
||||
array(1, 'My environment 2'),
|
||||
array(2, 'My environment 3'),
|
||||
array('My environment 1', 'My environment 1'),
|
||||
array('My environment 2', 'My environment 2'),
|
||||
array('My environment 3', 'My environment 3'),
|
||||
);
|
||||
return [
|
||||
[0, 'My environment 1'],
|
||||
[1, 'My environment 2'],
|
||||
[2, 'My environment 3'],
|
||||
['My environment 1', 'My environment 1'],
|
||||
['My environment 2', 'My environment 2'],
|
||||
['My environment 3', 'My environment 3'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,14 +435,14 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
*/
|
||||
public function testSpecialCharacterChoiceFromMultipleChoiceList($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
$possibleChoices = [
|
||||
'.',
|
||||
'src',
|
||||
);
|
||||
];
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$inputStream = $this->getInputStream($providedAnswer."\n");
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the directory', $possibleChoices);
|
||||
@@ -331,10 +455,10 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
public function specialCharacterInMultipleChoice()
|
||||
{
|
||||
return array(
|
||||
array('.', array('.')),
|
||||
array('., src', array('.', 'src')),
|
||||
);
|
||||
return [
|
||||
['.', ['.']],
|
||||
['., src', ['.', 'src']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,15 +466,15 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
*/
|
||||
public function testChoiceFromChoicelistWithMixedKeys($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
$possibleChoices = [
|
||||
'0' => 'No environment',
|
||||
'1' => 'My environment 1',
|
||||
'env_2' => 'My environment 2',
|
||||
3 => 'My environment 3',
|
||||
);
|
||||
];
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
@@ -362,14 +486,14 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
public function mixedKeysChoiceListAnswerProvider()
|
||||
{
|
||||
return array(
|
||||
array('0', '0'),
|
||||
array('No environment', '0'),
|
||||
array('1', '1'),
|
||||
array('env_2', 'env_2'),
|
||||
array(3, '3'),
|
||||
array('My environment 1', '1'),
|
||||
);
|
||||
return [
|
||||
['0', '0'],
|
||||
['No environment', '0'],
|
||||
['1', '1'],
|
||||
['env_2', 'env_2'],
|
||||
[3, '3'],
|
||||
['My environment 1', '1'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,14 +501,14 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
*/
|
||||
public function testSelectChoiceFromChoiceList($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
$possibleChoices = [
|
||||
'env_1' => 'My environment 1',
|
||||
'env_2' => 'My environment',
|
||||
'env_3' => 'My environment',
|
||||
);
|
||||
];
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
@@ -400,14 +524,14 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
*/
|
||||
public function testAmbiguousChoiceFromChoicelist()
|
||||
{
|
||||
$possibleChoices = array(
|
||||
$possibleChoices = [
|
||||
'env_1' => 'My first environment',
|
||||
'env_2' => 'My environment',
|
||||
'env_3' => 'My environment',
|
||||
);
|
||||
];
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
@@ -418,12 +542,12 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
public function answerProvider()
|
||||
{
|
||||
return array(
|
||||
array('env_1', 'env_1'),
|
||||
array('env_2', 'env_2'),
|
||||
array('env_3', 'env_3'),
|
||||
array('My environment 1', 'env_1'),
|
||||
);
|
||||
return [
|
||||
['env_1', 'env_1'],
|
||||
['env_2', 'env_2'],
|
||||
['env_3', 'env_3'],
|
||||
['My environment 1', 'env_1'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testNoInteraction()
|
||||
@@ -439,22 +563,22 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
public function testChoiceOutputFormattingQuestionForUtf8Keys()
|
||||
{
|
||||
$question = 'Lorem ipsum?';
|
||||
$possibleChoices = array(
|
||||
$possibleChoices = [
|
||||
'foo' => 'foo',
|
||||
'żółw' => 'bar',
|
||||
'łabądź' => 'baz',
|
||||
);
|
||||
$outputShown = array(
|
||||
];
|
||||
$outputShown = [
|
||||
$question,
|
||||
' [<info>foo </info>] foo',
|
||||
' [<info>żółw </info>] bar',
|
||||
' [<info>łabądź</info>] baz',
|
||||
);
|
||||
];
|
||||
$output = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')->getMock();
|
||||
$output->method('getFormatter')->willReturn(new OutputFormatter());
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$output->expects($this->once())->method('writeln')->with($this->equalTo($outputShown));
|
||||
@@ -463,360 +587,9 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream("\n")), $output, $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskChoice()
|
||||
{
|
||||
$questionHelper = new QuestionHelper();
|
||||
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
|
||||
$heroes = array('Superman', 'Batman', 'Spiderman');
|
||||
|
||||
$questionHelper->setInputStream($this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n"));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '2');
|
||||
$question->setMaxAttempts(1);
|
||||
// first answer is an empty answer, we're supposed to receive the default value
|
||||
$this->assertEquals('Spiderman', $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes);
|
||||
$question->setMaxAttempts(1);
|
||||
$this->assertEquals('Batman', $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('Batman', $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes);
|
||||
$question->setErrorMessage('Input "%s" is not a superhero!');
|
||||
$question->setMaxAttempts(2);
|
||||
$this->assertEquals('Batman', $questionHelper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), $question));
|
||||
|
||||
rewind($output->getStream());
|
||||
$stream = stream_get_contents($output->getStream());
|
||||
$this->assertContains('Input "Fabien" is not a superhero!', $stream);
|
||||
|
||||
try {
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '1');
|
||||
$question->setMaxAttempts(1);
|
||||
$questionHelper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), $question);
|
||||
$this->fail();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertEquals('Value "Fabien" is invalid', $e->getMessage());
|
||||
}
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Batman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0,1');
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, ' 0 , 1 ');
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAsk()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\n8AM\n"));
|
||||
|
||||
$question = new Question('What time is it?', '2PM');
|
||||
$this->assertEquals('2PM', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new Question('What time is it?', '2PM');
|
||||
$this->assertEquals('8AM', $dialog->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), $question));
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('What time is it?', stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskWithAutocomplete()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
// Acm<NEWLINE>
|
||||
// Ac<BACKSPACE><BACKSPACE>s<TAB>Test<NEWLINE>
|
||||
// <NEWLINE>
|
||||
// <UP ARROW><UP ARROW><NEWLINE>
|
||||
// <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB>Test<NEWLINE>
|
||||
// <DOWN ARROW><NEWLINE>
|
||||
// S<BACKSPACE><BACKSPACE><DOWN ARROW><DOWN ARROW><NEWLINE>
|
||||
// F00<BACKSPACE><BACKSPACE>oo<TAB><NEWLINE>
|
||||
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\nF00\177\177oo\t\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($inputStream);
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new Question('Please select a bundle', 'FrameworkBundle');
|
||||
$question->setAutocompleterValues(array('AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle'));
|
||||
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AsseticBundleTest', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('FrameworkBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('SecurityBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('FooBundleTest', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('FooBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskWithAutocompleteWithNonSequentialKeys()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
// <UP ARROW><UP ARROW><NEWLINE><DOWN ARROW><DOWN ARROW><NEWLINE>
|
||||
$inputStream = $this->getInputStream("\033[A\033[A\n\033[B\033[B\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($inputStream);
|
||||
$dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));
|
||||
|
||||
$question = new ChoiceQuestion('Please select a bundle', array(1 => 'AcmeDemoBundle', 4 => 'AsseticBundle'));
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskHiddenResponse()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('This test is not supported on Windows');
|
||||
}
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream("8AM\n"));
|
||||
|
||||
$question = new Question('What time is it?');
|
||||
$question->setHidden(true);
|
||||
|
||||
$this->assertEquals('8AM', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider getAskConfirmationData
|
||||
*/
|
||||
public function testLegacyAskConfirmation($question, $expected, $default = true)
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream($question."\n"));
|
||||
$question = new ConfirmationQuestion('Do you like French fries?', $default);
|
||||
$this->assertEquals($expected, $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question), 'confirmation question should '.($expected ? 'pass' : 'cancel'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskConfirmationWithCustomTrueAnswer()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("j\ny\n"));
|
||||
$question = new ConfirmationQuestion('Do you like French fries?', false, '/^(j|y)/i');
|
||||
$this->assertTrue($dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$question = new ConfirmationQuestion('Do you like French fries?', false, '/^(j|y)/i');
|
||||
$this->assertTrue($dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskAndValidate()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$error = 'This is not a color!';
|
||||
$validator = function ($color) use ($error) {
|
||||
if (!in_array($color, array('white', 'black'))) {
|
||||
throw new \InvalidArgumentException($error);
|
||||
}
|
||||
|
||||
return $color;
|
||||
};
|
||||
|
||||
$question = new Question('What color was the white horse of Henry IV?', 'white');
|
||||
$question->setValidator($validator);
|
||||
$question->setMaxAttempts(2);
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\nblack\n"));
|
||||
$this->assertEquals('white', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('black', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("green\nyellow\norange\n"));
|
||||
try {
|
||||
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
$this->fail();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertEquals($error, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider simpleAnswerProvider
|
||||
*/
|
||||
public function testLegacySelectChoiceFromSimpleChoices($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
'My environment 1',
|
||||
'My environment 2',
|
||||
'My environment 3',
|
||||
);
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream($providedAnswer."\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
|
||||
$this->assertSame($expectedValue, $answer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider mixedKeysChoiceListAnswerProvider
|
||||
*/
|
||||
public function testLegacyChoiceFromChoicelistWithMixedKeys($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
'0' => 'No environment',
|
||||
'1' => 'My environment 1',
|
||||
'env_2' => 'My environment 2',
|
||||
3 => 'My environment 3',
|
||||
);
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream($providedAnswer."\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
|
||||
$this->assertSame($expectedValue, $answer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider answerProvider
|
||||
*/
|
||||
public function testLegacySelectChoiceFromChoiceList($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
'env_1' => 'My environment 1',
|
||||
'env_2' => 'My environment',
|
||||
'env_3' => 'My environment',
|
||||
);
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream($providedAnswer."\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
|
||||
$this->assertSame($expectedValue, $answer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The provided answer is ambiguous. Value should be one of env_2 or env_3.
|
||||
*/
|
||||
public function testLegacyAmbiguousChoiceFromChoicelist()
|
||||
{
|
||||
$possibleChoices = array(
|
||||
'env_1' => 'My first environment',
|
||||
'env_2' => 'My environment',
|
||||
'env_3' => 'My environment',
|
||||
);
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream("My environment\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires function mb_strwidth
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyChoiceOutputFormattingQuestionForUtf8Keys()
|
||||
{
|
||||
$question = 'Lorem ipsum?';
|
||||
$possibleChoices = array(
|
||||
'foo' => 'foo',
|
||||
'żółw' => 'bar',
|
||||
'łabądź' => 'baz',
|
||||
);
|
||||
$outputShown = array(
|
||||
$question,
|
||||
' [<info>foo </info>] foo',
|
||||
' [<info>żółw </info>] bar',
|
||||
' [<info>łabądź</info>] baz',
|
||||
);
|
||||
$output = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')->getMock();
|
||||
$output->method('getFormatter')->willReturn(new OutputFormatter());
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream("\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$output->expects($this->once())->method('writeln')->with($this->equalTo($outputShown));
|
||||
|
||||
$question = new ChoiceQuestion($question, $possibleChoices, 'foo');
|
||||
$dialog->ask($this->createInputInterfaceMock(), $output, $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Aborted
|
||||
* @expectedExceptionMessage Aborted.
|
||||
*/
|
||||
public function testAskThrowsExceptionOnMissingInput()
|
||||
{
|
||||
@@ -826,7 +599,17 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Aborted
|
||||
* @expectedExceptionMessage Aborted.
|
||||
*/
|
||||
public function testAskThrowsExceptionOnMissingInputForChoiceQuestion()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new ChoiceQuestion('Choice', ['a', 'b']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Aborted.
|
||||
*/
|
||||
public function testAskThrowsExceptionOnMissingInputWithValidator()
|
||||
{
|
||||
@@ -848,7 +631,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
*/
|
||||
public function testEmptyChoices()
|
||||
{
|
||||
new ChoiceQuestion('Question', array(), 'irrelevant');
|
||||
new ChoiceQuestion('Question', [], 'irrelevant');
|
||||
}
|
||||
|
||||
public function testTraversableAutocomplete()
|
||||
@@ -868,11 +651,11 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\nF00\177\177oo\t\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new Question('Please select a bundle', 'FrameworkBundle');
|
||||
$question->setAutocompleterValues(new AutocompleteValues(array('irrelevant' => 'AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle')));
|
||||
$question->setAutocompleterValues(new AutocompleteValues(['irrelevant' => 'AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle']));
|
||||
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AsseticBundleTest', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
@@ -884,6 +667,37 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testTraversableMultiselectAutocomplete()
|
||||
{
|
||||
// <NEWLINE>
|
||||
// F<TAB><NEWLINE>
|
||||
// A<3x UP ARROW><TAB>,F<TAB><NEWLINE>
|
||||
// F00<BACKSPACE><BACKSPACE>o<TAB>,A<DOWN ARROW>,<SPACE>SecurityBundle<NEWLINE>
|
||||
// Acme<TAB>,<SPACE>As<TAB><29x BACKSPACE>S<TAB><NEWLINE>
|
||||
// Ac<TAB>,As<TAB><3x BACKSPACE>d<TAB><NEWLINE>
|
||||
$inputStream = $this->getInputStream("\nF\t\nA\033[A\033[A\033[A\t,F\t\nF00\177\177o\t,A\033[B\t, SecurityBundle\nAcme\t, As\t\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177S\t\nAc\t,As\t\177\177\177d\t\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion(
|
||||
'Please select a bundle (defaults to AcmeDemoBundle and AsseticBundle)',
|
||||
['AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle'],
|
||||
'0,1'
|
||||
);
|
||||
|
||||
// This tests that autocomplete works for all multiselect choices entered by the user
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(['AcmeDemoBundle', 'AsseticBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['FooBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['AsseticBundle', 'FooBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['FooBundle', 'AsseticBundle', 'SecurityBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['SecurityBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['AcmeDemoBundle', 'AsseticBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
protected function getInputStream($input)
|
||||
{
|
||||
$stream = fopen('php://memory', 'r+', false);
|
||||
@@ -903,7 +717,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$mock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
|
||||
$mock->expects($this->any())
|
||||
->method('isInteractive')
|
||||
->will($this->returnValue($interactive));
|
||||
->willReturn($interactive);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
|
||||
/**
|
||||
* @group tty
|
||||
@@ -18,10 +18,10 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
|
||||
{
|
||||
$questionHelper = new SymfonyQuestionHelper();
|
||||
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
|
||||
$heroes = array('Superman', 'Batman', 'Spiderman');
|
||||
$heroes = ['Superman', 'Batman', 'Spiderman'];
|
||||
|
||||
$inputStream = $this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n");
|
||||
|
||||
@@ -55,25 +55,37 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Batman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Superman', 'Spiderman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Superman', 'Spiderman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0,1');
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Superman', 'Batman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question));
|
||||
$this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output);
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, ' 0 , 1 ');
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['Superman', 'Batman'], $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question));
|
||||
$this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output);
|
||||
}
|
||||
|
||||
public function testAskChoiceWithChoiceValueAsDefault()
|
||||
{
|
||||
$questionHelper = new SymfonyQuestionHelper();
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', ['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();
|
||||
@@ -112,7 +124,7 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Aborted
|
||||
* @expectedExceptionMessage Aborted.
|
||||
*/
|
||||
public function testAskThrowsExceptionOnMissingInput()
|
||||
{
|
||||
@@ -142,7 +154,7 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$mock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
|
||||
$mock->expects($this->any())
|
||||
->method('isInteractive')
|
||||
->will($this->returnValue($interactive));
|
||||
->willReturn($interactive);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
837
vendor/symfony/console/Tests/Helper/TableTest.php
vendored
837
vendor/symfony/console/Tests/Helper/TableTest.php
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user