composer update
This commit is contained in:
+19
-6
@@ -44,6 +44,7 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Debug\ErrorHandler;
|
||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
|
||||
|
||||
/**
|
||||
* An Application is the container for a collection of commands.
|
||||
@@ -90,9 +91,12 @@ class Application
|
||||
$this->defaultCommand = 'list';
|
||||
}
|
||||
|
||||
/**
|
||||
* @final since Symfony 4.3, the type-hint will be updated to the interface from symfony/contracts in 5.0
|
||||
*/
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
|
||||
}
|
||||
|
||||
public function setCommandLoader(CommandLoaderInterface $commandLoader)
|
||||
@@ -235,7 +239,7 @@ class Application
|
||||
if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== \count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) {
|
||||
if (null !== $this->dispatcher) {
|
||||
$event = new ConsoleErrorEvent($input, $output, $e);
|
||||
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
|
||||
|
||||
if (0 === $event->getExitCode()) {
|
||||
return 0;
|
||||
@@ -254,7 +258,7 @@ class Application
|
||||
if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
|
||||
if (null !== $this->dispatcher) {
|
||||
$event = new ConsoleErrorEvent($input, $output, $e);
|
||||
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
|
||||
|
||||
return $event->getExitCode();
|
||||
}
|
||||
@@ -610,6 +614,15 @@ class Application
|
||||
$this->init();
|
||||
|
||||
$aliases = [];
|
||||
|
||||
foreach ($this->commands as $command) {
|
||||
foreach ($command->getAliases() as $alias) {
|
||||
if (!$this->has($alias)) {
|
||||
$this->commands[$alias] = $command;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
|
||||
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
|
||||
$commands = preg_grep('{^'.$expr.'}', $allCommands);
|
||||
@@ -920,7 +933,7 @@ class Application
|
||||
$e = null;
|
||||
|
||||
try {
|
||||
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::COMMAND);
|
||||
|
||||
if ($event->commandShouldRun()) {
|
||||
$exitCode = $command->run($input, $output);
|
||||
@@ -929,7 +942,7 @@ class Application
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$event = new ConsoleErrorEvent($input, $output, $e, $command);
|
||||
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
|
||||
$e = $event->getError();
|
||||
|
||||
if (0 === $exitCode = $event->getExitCode()) {
|
||||
@@ -938,7 +951,7 @@ class Application
|
||||
}
|
||||
|
||||
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
|
||||
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::TERMINATE);
|
||||
|
||||
if (null !== $e) {
|
||||
throw $e;
|
||||
|
||||
Vendored
+8
@@ -1,6 +1,14 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
||||
* added support for hyperlinks
|
||||
* added `ProgressBar::iterate()` method that simplify updating the progress bar when iterating
|
||||
* added `Question::setAutocompleterCallback()` to provide a callback function
|
||||
that dynamically generates suggestions as the user types
|
||||
|
||||
4.2.0
|
||||
-----
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ class CommandNotFoundException extends \InvalidArgumentException implements Exce
|
||||
* @param string $message Exception message to throw
|
||||
* @param array $alternatives List of similar defined names
|
||||
* @param int $code Exception code
|
||||
* @param \Exception $previous Previous exception used for the exception chaining
|
||||
* @param \Throwable $previous Previous exception used for the exception chaining
|
||||
*/
|
||||
public function __construct(string $message, array $alternatives = [], int $code = 0, \Exception $previous = null)
|
||||
public function __construct(string $message, array $alternatives = [], int $code = 0, \Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
|
||||
|
||||
+3
-1
@@ -141,7 +141,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
|
||||
{
|
||||
$offset = 0;
|
||||
$output = '';
|
||||
$tagRegex = '[a-z][a-z0-9,_=;-]*+';
|
||||
$tagRegex = '[a-z][^<>]*+';
|
||||
$currentLineLength = 0;
|
||||
preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE);
|
||||
foreach ($matches[0] as $i => $match) {
|
||||
@@ -216,6 +216,8 @@ class OutputFormatter implements WrappableOutputFormatterInterface
|
||||
$style->setForeground(strtolower($match[1]));
|
||||
} elseif ('bg' == $match[0]) {
|
||||
$style->setBackground(strtolower($match[1]));
|
||||
} elseif ('href' === $match[0]) {
|
||||
$style->setHref($match[1]);
|
||||
} elseif ('options' === $match[0]) {
|
||||
preg_match_all('([^,;]+)', strtolower($match[1]), $options);
|
||||
$options = array_shift($options);
|
||||
|
||||
+19
-5
@@ -52,7 +52,9 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
|
||||
private $foreground;
|
||||
private $background;
|
||||
private $href;
|
||||
private $options = [];
|
||||
private $handlesHrefGracefully;
|
||||
|
||||
/**
|
||||
* Initializes output formatter style.
|
||||
@@ -118,6 +120,11 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
$this->background = static::$availableBackgroundColors[$color];
|
||||
}
|
||||
|
||||
public function setHref(string $url): void
|
||||
{
|
||||
$this->href = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets some specific style option.
|
||||
*
|
||||
@@ -179,6 +186,10 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
$setCodes = [];
|
||||
$unsetCodes = [];
|
||||
|
||||
if (null === $this->handlesHrefGracefully) {
|
||||
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
|
||||
}
|
||||
|
||||
if (null !== $this->foreground) {
|
||||
$setCodes[] = $this->foreground['set'];
|
||||
$unsetCodes[] = $this->foreground['unset'];
|
||||
@@ -187,11 +198,14 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
$setCodes[] = $this->background['set'];
|
||||
$unsetCodes[] = $this->background['unset'];
|
||||
}
|
||||
if (\count($this->options)) {
|
||||
foreach ($this->options as $option) {
|
||||
$setCodes[] = $option['set'];
|
||||
$unsetCodes[] = $option['unset'];
|
||||
}
|
||||
|
||||
foreach ($this->options as $option) {
|
||||
$setCodes[] = $option['set'];
|
||||
$unsetCodes[] = $option['unset'];
|
||||
}
|
||||
|
||||
if (null !== $this->href && $this->handlesHrefGracefully) {
|
||||
$text = "\033]8;;$this->href\033\\$text\033]8;;\033\\";
|
||||
}
|
||||
|
||||
if (0 === \count($setCodes)) {
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
* @author Roland Franssen <franssen.roland@gmail.com>
|
||||
*/
|
||||
final class Dumper
|
||||
{
|
||||
private $output;
|
||||
private $dumper;
|
||||
private $cloner;
|
||||
private $handler;
|
||||
|
||||
public function __construct(OutputInterface $output, CliDumper $dumper = null, ClonerInterface $cloner = null)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->dumper = $dumper;
|
||||
$this->cloner = $cloner;
|
||||
|
||||
if (class_exists(CliDumper::class)) {
|
||||
$this->handler = function ($var): string {
|
||||
$dumper = $this->dumper ?? $this->dumper = new CliDumper(null, null, CliDumper::DUMP_LIGHT_ARRAY | CliDumper::DUMP_COMMA_SEPARATOR);
|
||||
$dumper->setColors($this->output->isDecorated());
|
||||
|
||||
return rtrim($dumper->dump(($this->cloner ?? $this->cloner = new VarCloner())->cloneVar($var)->withRefHandles(false), true));
|
||||
};
|
||||
} else {
|
||||
$this->handler = function ($var): string {
|
||||
switch (true) {
|
||||
case null === $var:
|
||||
return 'null';
|
||||
case true === $var:
|
||||
return 'true';
|
||||
case false === $var:
|
||||
return 'false';
|
||||
case \is_string($var):
|
||||
return '"'.$var.'"';
|
||||
default:
|
||||
return rtrim(print_r($var, true));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public function __invoke($var): string
|
||||
{
|
||||
return ($this->handler)($var);
|
||||
}
|
||||
}
|
||||
+18
@@ -243,6 +243,24 @@ final class ProgressBar
|
||||
$this->redrawFreq = max($freq, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator that will automatically update the progress bar when iterated.
|
||||
*
|
||||
* @param int|null $max Number of steps to complete the bar (0 if indeterminate), if null it will be inferred from $iterable
|
||||
*/
|
||||
public function iterate(iterable $iterable, ?int $max = null): iterable
|
||||
{
|
||||
$this->start($max ?? (\is_countable($iterable) ? \count($iterable) : 0));
|
||||
|
||||
foreach ($iterable as $key => $value) {
|
||||
yield $key => $value;
|
||||
|
||||
$this->advance();
|
||||
}
|
||||
|
||||
$this->finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the progress output.
|
||||
*
|
||||
|
||||
+50
-18
@@ -115,7 +115,7 @@ class QuestionHelper extends Helper
|
||||
$this->writePrompt($output, $question);
|
||||
|
||||
$inputStream = $this->inputStream ?: STDIN;
|
||||
$autocomplete = $question->getAutocompleterValues();
|
||||
$autocomplete = $question->getAutocompleterCallback();
|
||||
|
||||
if (null === $autocomplete || !$this->hasSttyAvailable()) {
|
||||
$ret = false;
|
||||
@@ -137,7 +137,7 @@ class QuestionHelper extends Helper
|
||||
$ret = trim($ret);
|
||||
}
|
||||
} else {
|
||||
$ret = trim($this->autocomplete($output, $question, $inputStream, \is_array($autocomplete) ? $autocomplete : iterator_to_array($autocomplete, false)));
|
||||
$ret = trim($this->autocomplete($output, $question, $inputStream, $autocomplete));
|
||||
}
|
||||
|
||||
if ($output instanceof ConsoleSectionOutput) {
|
||||
@@ -194,17 +194,16 @@ class QuestionHelper extends Helper
|
||||
/**
|
||||
* Autocompletes a question.
|
||||
*
|
||||
* @param OutputInterface $output
|
||||
* @param Question $question
|
||||
* @param resource $inputStream
|
||||
* @param resource $inputStream
|
||||
*/
|
||||
private function autocomplete(OutputInterface $output, Question $question, $inputStream, array $autocomplete): string
|
||||
private function autocomplete(OutputInterface $output, Question $question, $inputStream, callable $autocomplete): string
|
||||
{
|
||||
$fullChoice = '';
|
||||
$ret = '';
|
||||
|
||||
$i = 0;
|
||||
$ofs = -1;
|
||||
$matches = $autocomplete;
|
||||
$matches = $autocomplete($ret);
|
||||
$numMatches = \count($matches);
|
||||
|
||||
$sttyMode = shell_exec('stty -g');
|
||||
@@ -226,13 +225,14 @@ class QuestionHelper extends Helper
|
||||
} elseif ("\177" === $c) { // Backspace Character
|
||||
if (0 === $numMatches && 0 !== $i) {
|
||||
--$i;
|
||||
$fullChoice = substr($fullChoice, 0, -1);
|
||||
// Move cursor backwards
|
||||
$output->write("\033[1D");
|
||||
}
|
||||
|
||||
if (0 === $i) {
|
||||
$ofs = -1;
|
||||
$matches = $autocomplete;
|
||||
$matches = $autocomplete($ret);
|
||||
$numMatches = \count($matches);
|
||||
} else {
|
||||
$numMatches = 0;
|
||||
@@ -260,18 +260,27 @@ class QuestionHelper extends Helper
|
||||
} elseif (\ord($c) < 32) {
|
||||
if ("\t" === $c || "\n" === $c) {
|
||||
if ($numMatches > 0 && -1 !== $ofs) {
|
||||
$ret = $matches[$ofs];
|
||||
$ret = (string) $matches[$ofs];
|
||||
// Echo out remaining chars for current match
|
||||
$output->write(substr($ret, $i));
|
||||
$i = \strlen($ret);
|
||||
$remainingCharacters = substr($ret, \strlen(trim($this->mostRecentlyEnteredValue($fullChoice))));
|
||||
$output->write($remainingCharacters);
|
||||
$fullChoice .= $remainingCharacters;
|
||||
$i = \strlen($fullChoice);
|
||||
|
||||
$matches = array_filter(
|
||||
$autocomplete($ret),
|
||||
function ($match) use ($ret) {
|
||||
return '' === $ret || 0 === strpos($match, $ret);
|
||||
}
|
||||
);
|
||||
$numMatches = \count($matches);
|
||||
$ofs = -1;
|
||||
}
|
||||
|
||||
if ("\n" === $c) {
|
||||
$output->write($c);
|
||||
break;
|
||||
}
|
||||
|
||||
$numMatches = 0;
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -282,14 +291,21 @@ class QuestionHelper extends Helper
|
||||
|
||||
$output->write($c);
|
||||
$ret .= $c;
|
||||
$fullChoice .= $c;
|
||||
++$i;
|
||||
|
||||
$tempRet = $ret;
|
||||
|
||||
if ($question instanceof ChoiceQuestion && $question->isMultiselect()) {
|
||||
$tempRet = $this->mostRecentlyEnteredValue($fullChoice);
|
||||
}
|
||||
|
||||
$numMatches = 0;
|
||||
$ofs = 0;
|
||||
|
||||
foreach ($autocomplete as $value) {
|
||||
foreach ($autocomplete($ret) as $value) {
|
||||
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
|
||||
if (0 === strpos($value, $ret)) {
|
||||
if (0 === strpos($value, $tempRet)) {
|
||||
$matches[$numMatches++] = $value;
|
||||
}
|
||||
}
|
||||
@@ -301,8 +317,9 @@ class QuestionHelper extends Helper
|
||||
if ($numMatches > 0 && -1 !== $ofs) {
|
||||
// Save cursor position
|
||||
$output->write("\0337");
|
||||
// Write highlighted text
|
||||
$output->write('<hl>'.OutputFormatter::escapeTrailingBackslash(substr($matches[$ofs], $i)).'</hl>');
|
||||
// Write highlighted text, complete the partially entered response
|
||||
$charactersEntered = \strlen(trim($this->mostRecentlyEnteredValue($fullChoice)));
|
||||
$output->write('<hl>'.OutputFormatter::escapeTrailingBackslash(substr($matches[$ofs], $charactersEntered)).'</hl>');
|
||||
// Restore cursor position
|
||||
$output->write("\0338");
|
||||
}
|
||||
@@ -311,7 +328,22 @@ class QuestionHelper extends Helper
|
||||
// Reset stty so it behaves normally again
|
||||
shell_exec(sprintf('stty %s', $sttyMode));
|
||||
|
||||
return $ret;
|
||||
return $fullChoice;
|
||||
}
|
||||
|
||||
private function mostRecentlyEnteredValue($entered)
|
||||
{
|
||||
// Determine the most recent value that the user entered
|
||||
if (false === strpos($entered, ',')) {
|
||||
return $entered;
|
||||
}
|
||||
|
||||
$choices = explode(',', $entered);
|
||||
if (\strlen($lastChoice = trim($choices[\count($choices) - 1])) > 0) {
|
||||
return $lastChoice;
|
||||
}
|
||||
|
||||
return $entered;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+38
-7
@@ -25,7 +25,7 @@ class Question
|
||||
private $attempts;
|
||||
private $hidden = false;
|
||||
private $hiddenFallback = true;
|
||||
private $autocompleterValues;
|
||||
private $autocompleterCallback;
|
||||
private $validator;
|
||||
private $default;
|
||||
private $normalizer;
|
||||
@@ -81,7 +81,7 @@ class Question
|
||||
*/
|
||||
public function setHidden($hidden)
|
||||
{
|
||||
if ($this->autocompleterValues) {
|
||||
if ($this->autocompleterCallback) {
|
||||
throw new LogicException('A hidden question cannot use the autocompleter.');
|
||||
}
|
||||
|
||||
@@ -121,7 +121,9 @@ class Question
|
||||
*/
|
||||
public function getAutocompleterValues()
|
||||
{
|
||||
return $this->autocompleterValues;
|
||||
$callback = $this->getAutocompleterCallback();
|
||||
|
||||
return $callback ? $callback('') : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,17 +140,46 @@ class Question
|
||||
{
|
||||
if (\is_array($values)) {
|
||||
$values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values);
|
||||
}
|
||||
|
||||
if (null !== $values && !\is_array($values) && !$values instanceof \Traversable) {
|
||||
$callback = static function () use ($values) {
|
||||
return $values;
|
||||
};
|
||||
} elseif ($values instanceof \Traversable) {
|
||||
$valueCache = null;
|
||||
$callback = static function () use ($values, &$valueCache) {
|
||||
return $valueCache ?? $valueCache = iterator_to_array($values, false);
|
||||
};
|
||||
} elseif (null === $values) {
|
||||
$callback = null;
|
||||
} else {
|
||||
throw new InvalidArgumentException('Autocompleter values can be either an array, "null" or a "Traversable" object.');
|
||||
}
|
||||
|
||||
if ($this->hidden) {
|
||||
return $this->setAutocompleterCallback($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the callback function used for the autocompleter.
|
||||
*/
|
||||
public function getAutocompleterCallback(): ?callable
|
||||
{
|
||||
return $this->autocompleterCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callback function used for the autocompleter.
|
||||
*
|
||||
* The callback is passed the user input as argument and should return an iterable of corresponding suggestions.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAutocompleterCallback(callable $callback = null): self
|
||||
{
|
||||
if ($this->hidden && null !== $callback) {
|
||||
throw new LogicException('A hidden question cannot use the autocompleter.');
|
||||
}
|
||||
|
||||
$this->autocompleterValues = $values;
|
||||
$this->autocompleterCallback = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ class SymfonyStyle extends OutputStyle
|
||||
*/
|
||||
public function warning($message)
|
||||
{
|
||||
$this->block($message, 'WARNING', 'fg=white;bg=red', ' ', true);
|
||||
$this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ', true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+27
-5
@@ -73,8 +73,8 @@ class ApplicationTest extends TestCase
|
||||
require_once self::$fixturesPath.'/FooSubnamespaced1Command.php';
|
||||
require_once self::$fixturesPath.'/FooSubnamespaced2Command.php';
|
||||
require_once self::$fixturesPath.'/FooWithoutAliasCommand.php';
|
||||
require_once self::$fixturesPath.'/TestTiti.php';
|
||||
require_once self::$fixturesPath.'/TestToto.php';
|
||||
require_once self::$fixturesPath.'/TestAmbiguousCommandRegistering.php';
|
||||
require_once self::$fixturesPath.'/TestAmbiguousCommandRegistering2.php';
|
||||
}
|
||||
|
||||
protected function normalizeLineBreaks($text)
|
||||
@@ -165,6 +165,28 @@ class ApplicationTest extends TestCase
|
||||
$this->assertEquals('foo', $command->getName(), '->register() registers a new command');
|
||||
}
|
||||
|
||||
public function testRegisterAmbiguous()
|
||||
{
|
||||
$code = function (InputInterface $input, OutputInterface $output) {
|
||||
$output->writeln('It works!');
|
||||
};
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application
|
||||
->register('test-foo')
|
||||
->setAliases(['test'])
|
||||
->setCode($code);
|
||||
|
||||
$application
|
||||
->register('test-bar')
|
||||
->setCode($code);
|
||||
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(['test']);
|
||||
$this->assertContains('It works!', $tester->getDisplay(true));
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$application = new Application();
|
||||
@@ -304,9 +326,9 @@ class ApplicationTest extends TestCase
|
||||
public function testFindNonAmbiguous()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \TestTiti());
|
||||
$application->add(new \TestToto());
|
||||
$this->assertEquals('test-toto', $application->find('test')->getName());
|
||||
$application->add(new \TestAmbiguousCommandRegistering());
|
||||
$application->add(new \TestAmbiguousCommandRegistering2());
|
||||
$this->assertEquals('test-ambiguous', $application->find('test')->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ class CommandTest extends TestCase
|
||||
public function testSetAliasesNull()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$command->setAliases(null);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -4,19 +4,19 @@ use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class TestToto extends Command
|
||||
class TestAmbiguousCommandRegistering extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('test-toto')
|
||||
->setDescription('The test-toto command')
|
||||
->setName('test-ambiguous')
|
||||
->setDescription('The test-ambiguous command')
|
||||
->setAliases(['test'])
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->write('test-toto');
|
||||
$output->write('test-ambiguous');
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -4,18 +4,18 @@ use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class TestTiti extends Command
|
||||
class TestAmbiguousCommandRegistering2 extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('test-titi')
|
||||
->setDescription('The test:titi command')
|
||||
->setName('test-ambiguous2')
|
||||
->setDescription('The test-ambiguous2 command')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->write('test-titi');
|
||||
$output->write('test-ambiguous2');
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ class OutputFormatterStyleTest extends TestCase
|
||||
$style->setForeground('default');
|
||||
$this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo'));
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$style->setForeground('undefined-color');
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class OutputFormatterStyleTest extends TestCase
|
||||
$style->setBackground('default');
|
||||
$this->assertEquals("\033[49mfoo\033[49m", $style->apply('foo'));
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$style->setBackground('undefined-color');
|
||||
}
|
||||
|
||||
@@ -97,4 +97,19 @@ class OutputFormatterStyleTest extends TestCase
|
||||
$this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||
}
|
||||
}
|
||||
|
||||
public function testHref()
|
||||
{
|
||||
$prevTerminalEmulator = getenv('TERMINAL_EMULATOR');
|
||||
putenv('TERMINAL_EMULATOR');
|
||||
|
||||
$style = new OutputFormatterStyle();
|
||||
|
||||
try {
|
||||
$style->setHref('idea://open/?file=/path/SomeFile.php&line=12');
|
||||
$this->assertSame("\e]8;;idea://open/?file=/path/SomeFile.php&line=12\e\\some URL\e]8;;\e\\", $style->apply('some URL'));
|
||||
} finally {
|
||||
putenv('TERMINAL_EMULATOR'.($prevTerminalEmulator ? "=$prevTerminalEmulator" : ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+27
-32
@@ -228,7 +228,7 @@ class OutputFormatterTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testNotDecoratedFormatter()
|
||||
public function testFormatterHasStyles()
|
||||
{
|
||||
$formatter = new OutputFormatter(false);
|
||||
|
||||
@@ -236,40 +236,35 @@ class OutputFormatterTest extends TestCase
|
||||
$this->assertTrue($formatter->hasStyle('info'));
|
||||
$this->assertTrue($formatter->hasStyle('comment'));
|
||||
$this->assertTrue($formatter->hasStyle('question'));
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
'some error', $formatter->format('<error>some error</error>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'some info', $formatter->format('<info>some info</info>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'some comment', $formatter->format('<comment>some comment</comment>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'some question', $formatter->format('<question>some question</question>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'some text with inline style', $formatter->format('<fg=red>some text with inline style</>')
|
||||
);
|
||||
/**
|
||||
* @dataProvider provideDecoratedAndNonDecoratedOutput
|
||||
*/
|
||||
public function testNotDecoratedFormatter(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput, string $terminalEmulator = 'foo')
|
||||
{
|
||||
$prevTerminalEmulator = getenv('TERMINAL_EMULATOR');
|
||||
putenv('TERMINAL_EMULATOR='.$terminalEmulator);
|
||||
|
||||
$formatter->setDecorated(true);
|
||||
try {
|
||||
$this->assertEquals($expectedDecoratedOutput, (new OutputFormatter(true))->format($input));
|
||||
$this->assertEquals($expectedNonDecoratedOutput, (new OutputFormatter(false))->format($input));
|
||||
} finally {
|
||||
putenv('TERMINAL_EMULATOR'.($prevTerminalEmulator ? "=$prevTerminalEmulator" : ''));
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
"\033[37;41msome error\033[39;49m", $formatter->format('<error>some error</error>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[32msome info\033[39m", $formatter->format('<info>some info</info>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[33msome comment\033[39m", $formatter->format('<comment>some comment</comment>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[30;46msome question\033[39;49m", $formatter->format('<question>some question</question>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[31msome text with inline style\033[39m", $formatter->format('<fg=red>some text with inline style</>')
|
||||
);
|
||||
public function provideDecoratedAndNonDecoratedOutput()
|
||||
{
|
||||
return [
|
||||
['<error>some error</error>', 'some error', "\033[37;41msome error\033[39;49m"],
|
||||
['<info>some info</info>', 'some info', "\033[32msome info\033[39m"],
|
||||
['<comment>some comment</comment>', 'some comment', "\033[33msome comment\033[39m"],
|
||||
['<question>some question</question>', 'some question', "\033[30;46msome question\033[39;49m"],
|
||||
['<fg=red>some text with inline style</>', 'some text with inline style', "\033[31msome text with inline style\033[39m"],
|
||||
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"],
|
||||
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', 'JetBrains-JediTerm'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testContentWithLineBreaks()
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ClassExistsMock;
|
||||
use Symfony\Component\Console\Helper\Dumper;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
class DumperNativeFallbackTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
ClassExistsMock::register(Dumper::class);
|
||||
ClassExistsMock::withMockedClasses([
|
||||
CliDumper::class => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
ClassExistsMock::withMockedClasses([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideVariables
|
||||
*/
|
||||
public function testInvoke($variable, $primitiveString)
|
||||
{
|
||||
$dumper = new Dumper($this->getMockBuilder(OutputInterface::class)->getMock());
|
||||
|
||||
$this->assertSame($primitiveString, $dumper($variable));
|
||||
}
|
||||
|
||||
public function provideVariables()
|
||||
{
|
||||
return [
|
||||
[null, 'null'],
|
||||
[true, 'true'],
|
||||
[false, 'false'],
|
||||
[1, '1'],
|
||||
[-1.5, '-1.5'],
|
||||
['string', '"string"'],
|
||||
[[1, '2'], "Array\n(\n [0] => 1\n [1] => 2\n)"],
|
||||
[new \stdClass(), "stdClass Object\n(\n)"],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Helper\Dumper;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
||||
|
||||
class DumperTest extends TestCase
|
||||
{
|
||||
use VarDumperTestTrait;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
putenv('DUMP_LIGHT_ARRAY=1');
|
||||
putenv('DUMP_COMMA_SEPARATOR=1');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
putenv('DUMP_LIGHT_ARRAY');
|
||||
putenv('DUMP_COMMA_SEPARATOR');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideVariables
|
||||
*/
|
||||
public function testInvoke($variable)
|
||||
{
|
||||
$dumper = new Dumper($this->getMockBuilder(OutputInterface::class)->getMock());
|
||||
|
||||
$this->assertDumpMatchesFormat($dumper($variable), $variable);
|
||||
}
|
||||
|
||||
public function provideVariables()
|
||||
{
|
||||
return [
|
||||
[null],
|
||||
[true],
|
||||
[false],
|
||||
[1],
|
||||
[-1.5],
|
||||
['string'],
|
||||
[[1, '2']],
|
||||
[new \stdClass()],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -880,6 +880,41 @@ class ProgressBarTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testIterate(): void
|
||||
{
|
||||
$bar = new ProgressBar($output = $this->getOutputStream());
|
||||
|
||||
$this->assertEquals([1, 2], \iterator_to_array($bar->iterate([1, 2])));
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
' 0/2 [>---------------------------] 0%'.
|
||||
$this->generateOutput(' 1/2 [==============>-------------] 50%').
|
||||
$this->generateOutput(' 2/2 [============================] 100%').
|
||||
$this->generateOutput(' 2/2 [============================] 100%'),
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testIterateUncountable(): void
|
||||
{
|
||||
$bar = new ProgressBar($output = $this->getOutputStream());
|
||||
|
||||
$this->assertEquals([1, 2], \iterator_to_array($bar->iterate((function () {
|
||||
yield 1;
|
||||
yield 2;
|
||||
})())));
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
' 0 [>---------------------------]'.
|
||||
$this->generateOutput(' 1 [->--------------------------]').
|
||||
$this->generateOutput(' 2 [-->-------------------------]').
|
||||
$this->generateOutput(' 2 [============================]'),
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
protected function getOutputStream($decorated = true, $verbosity = StreamOutput::VERBOSITY_NORMAL)
|
||||
{
|
||||
return new StreamOutput(fopen('php://memory', 'r+', false), $verbosity, $decorated);
|
||||
|
||||
@@ -198,6 +198,49 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testAskWithAutocompleteCallback()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
// Po<TAB>Cr<TAB>P<DOWN ARROW><DOWN ARROW><NEWLINE>
|
||||
$inputStream = $this->getInputStream("Pa\177\177o\tCr\tP\033[A\033[A\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new Question('What\'s for dinner?');
|
||||
|
||||
// A simple test callback - return an array containing the words the
|
||||
// user has already completed, suffixed with all known words.
|
||||
//
|
||||
// Eg: If the user inputs "Potato C", the return will be:
|
||||
//
|
||||
// ["Potato Carrot ", "Potato Creme ", "Potato Curry ", ...]
|
||||
//
|
||||
// No effort is made to avoid irrelevant suggestions, as this is handled
|
||||
// by the autocomplete function.
|
||||
$callback = function ($input) {
|
||||
$knownWords = ['Carrot', 'Creme', 'Curry', 'Parsnip', 'Pie', 'Potato', 'Tart'];
|
||||
$inputWords = explode(' ', $input);
|
||||
array_pop($inputWords);
|
||||
$suggestionBase = $inputWords ? implode(' ', $inputWords).' ' : '';
|
||||
|
||||
return array_map(
|
||||
function ($word) use ($suggestionBase) {
|
||||
return $suggestionBase.$word.' ';
|
||||
},
|
||||
$knownWords
|
||||
);
|
||||
};
|
||||
|
||||
$question->setAutocompleterCallback($callback);
|
||||
|
||||
$this->assertSame('Potato Creme Pie', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testAskWithAutocompleteWithNonSequentialKeys()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
@@ -667,6 +710,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\nSecurityBundle\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);
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Question;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
|
||||
class QuestionTest extends TestCase
|
||||
{
|
||||
private $question;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->question = new Question('Test question');
|
||||
}
|
||||
|
||||
public function providerTrueFalse()
|
||||
{
|
||||
return [[true], [false]];
|
||||
}
|
||||
|
||||
public function testGetQuestion()
|
||||
{
|
||||
self::assertSame('Test question', $this->question->getQuestion());
|
||||
}
|
||||
|
||||
public function testGetDefault()
|
||||
{
|
||||
$question = new Question('Test question', 'Default value');
|
||||
self::assertSame('Default value', $question->getDefault());
|
||||
}
|
||||
|
||||
public function testGetDefaultDefault()
|
||||
{
|
||||
self::assertNull($this->question->getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTrueFalse
|
||||
*/
|
||||
public function testIsSetHidden(bool $hidden)
|
||||
{
|
||||
$this->question->setHidden($hidden);
|
||||
self::assertSame($hidden, $this->question->isHidden());
|
||||
}
|
||||
|
||||
public function testIsHiddenDefault()
|
||||
{
|
||||
self::assertFalse($this->question->isHidden());
|
||||
}
|
||||
|
||||
public function testSetHiddenWithAutocompleterCallback()
|
||||
{
|
||||
$this->question->setAutocompleterCallback(
|
||||
function (string $input): array { return []; }
|
||||
);
|
||||
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'A hidden question cannot use the autocompleter.'
|
||||
);
|
||||
|
||||
$this->question->setHidden(true);
|
||||
}
|
||||
|
||||
public function testSetHiddenWithNoAutocompleterCallback()
|
||||
{
|
||||
$this->question->setAutocompleterCallback(
|
||||
function (string $input): array { return []; }
|
||||
);
|
||||
$this->question->setAutocompleterCallback(null);
|
||||
|
||||
$exception = null;
|
||||
try {
|
||||
$this->question->setHidden(true);
|
||||
} catch (\Exception $exception) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
$this->assertNull($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTrueFalse
|
||||
*/
|
||||
public function testIsSetHiddenFallback(bool $hidden)
|
||||
{
|
||||
$this->question->setHiddenFallback($hidden);
|
||||
self::assertSame($hidden, $this->question->isHiddenFallback());
|
||||
}
|
||||
|
||||
public function testIsHiddenFallbackDefault()
|
||||
{
|
||||
self::assertTrue($this->question->isHiddenFallback());
|
||||
}
|
||||
|
||||
public function providerGetSetAutocompleterValues()
|
||||
{
|
||||
return [
|
||||
'array' => [
|
||||
['a', 'b', 'c', 'd'],
|
||||
['a', 'b', 'c', 'd'],
|
||||
],
|
||||
'associative array' => [
|
||||
['a' => 'c', 'b' => 'd'],
|
||||
['a', 'b', 'c', 'd'],
|
||||
],
|
||||
'iterator' => [
|
||||
new \ArrayIterator(['a', 'b', 'c', 'd']),
|
||||
['a', 'b', 'c', 'd'],
|
||||
],
|
||||
'null' => [null, null],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerGetSetAutocompleterValues
|
||||
*/
|
||||
public function testGetSetAutocompleterValues($values, $expectValues)
|
||||
{
|
||||
$this->question->setAutocompleterValues($values);
|
||||
self::assertSame(
|
||||
$expectValues,
|
||||
$this->question->getAutocompleterValues()
|
||||
);
|
||||
}
|
||||
|
||||
public function providerSetAutocompleterValuesInvalid()
|
||||
{
|
||||
return [
|
||||
['Potato'],
|
||||
[new \stdclass()],
|
||||
[false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSetAutocompleterValuesInvalid
|
||||
*/
|
||||
public function testSetAutocompleterValuesInvalid($values)
|
||||
{
|
||||
self::expectException(InvalidArgumentException::class);
|
||||
self::expectExceptionMessage(
|
||||
'Autocompleter values can be either an array, "null" or a "Traversable" object.'
|
||||
);
|
||||
|
||||
$this->question->setAutocompleterValues($values);
|
||||
}
|
||||
|
||||
public function testSetAutocompleterValuesWithTraversable()
|
||||
{
|
||||
$question1 = new Question('Test question 1');
|
||||
$iterator1 = $this->getMockForAbstractClass(\IteratorAggregate::class);
|
||||
$iterator1
|
||||
->expects($this->once())
|
||||
->method('getIterator')
|
||||
->willReturn(new \ArrayIterator(['Potato']));
|
||||
$question1->setAutocompleterValues($iterator1);
|
||||
|
||||
$question2 = new Question('Test question 2');
|
||||
$iterator2 = $this->getMockForAbstractClass(\IteratorAggregate::class);
|
||||
$iterator2
|
||||
->expects($this->once())
|
||||
->method('getIterator')
|
||||
->willReturn(new \ArrayIterator(['Carrot']));
|
||||
$question2->setAutocompleterValues($iterator2);
|
||||
|
||||
// Call multiple times to verify that Traversable result is cached, and
|
||||
// that there is no crosstalk between cached copies.
|
||||
self::assertSame(['Potato'], $question1->getAutocompleterValues());
|
||||
self::assertSame(['Carrot'], $question2->getAutocompleterValues());
|
||||
self::assertSame(['Potato'], $question1->getAutocompleterValues());
|
||||
self::assertSame(['Carrot'], $question2->getAutocompleterValues());
|
||||
}
|
||||
|
||||
public function testGetAutocompleterValuesDefault()
|
||||
{
|
||||
self::assertNull($this->question->getAutocompleterValues());
|
||||
}
|
||||
|
||||
public function testGetSetAutocompleterCallback()
|
||||
{
|
||||
$callback = function (string $input): array { return []; };
|
||||
|
||||
$this->question->setAutocompleterCallback($callback);
|
||||
self::assertSame($callback, $this->question->getAutocompleterCallback());
|
||||
}
|
||||
|
||||
public function testGetAutocompleterCallbackDefault()
|
||||
{
|
||||
self::assertNull($this->question->getAutocompleterCallback());
|
||||
}
|
||||
|
||||
public function testSetAutocompleterCallbackWhenHidden()
|
||||
{
|
||||
$this->question->setHidden(true);
|
||||
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'A hidden question cannot use the autocompleter.'
|
||||
);
|
||||
|
||||
$this->question->setAutocompleterCallback(
|
||||
function (string $input): array { return []; }
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetAutocompleterCallbackWhenNotHidden()
|
||||
{
|
||||
$this->question->setHidden(true);
|
||||
$this->question->setHidden(false);
|
||||
|
||||
$exception = null;
|
||||
try {
|
||||
$this->question->setAutocompleterCallback(
|
||||
function (string $input): array { return []; }
|
||||
);
|
||||
} catch (\Exception $exception) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
$this->assertNull($exception);
|
||||
}
|
||||
|
||||
public function providerGetSetValidator()
|
||||
{
|
||||
return [
|
||||
[function ($input) { return $input; }],
|
||||
[null],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerGetSetValidator
|
||||
*/
|
||||
public function testGetSetValidator($callback)
|
||||
{
|
||||
$this->question->setValidator($callback);
|
||||
self::assertSame($callback, $this->question->getValidator());
|
||||
}
|
||||
|
||||
public function testGetValidatorDefault()
|
||||
{
|
||||
self::assertNull($this->question->getValidator());
|
||||
}
|
||||
|
||||
public function providerGetSetMaxAttempts()
|
||||
{
|
||||
return [[1], [5], [null]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerGetSetMaxAttempts
|
||||
*/
|
||||
public function testGetSetMaxAttempts($attempts)
|
||||
{
|
||||
$this->question->setMaxAttempts($attempts);
|
||||
self::assertSame($attempts, $this->question->getMaxAttempts());
|
||||
}
|
||||
|
||||
public function providerSetMaxAttemptsInvalid()
|
||||
{
|
||||
return [['Potato'], [0], [-1]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSetMaxAttemptsInvalid
|
||||
*/
|
||||
public function testSetMaxAttemptsInvalid($attempts)
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
self::expectExceptionMessage('Maximum number of attempts must be a positive value.');
|
||||
|
||||
$this->question->setMaxAttempts($attempts);
|
||||
}
|
||||
|
||||
public function testGetMaxAttemptsDefault()
|
||||
{
|
||||
self::assertNull($this->question->getMaxAttempts());
|
||||
}
|
||||
|
||||
public function testGetSetNormalizer()
|
||||
{
|
||||
$normalizer = function ($input) { return $input; };
|
||||
$this->question->setNormalizer($normalizer);
|
||||
self::assertSame($normalizer, $this->question->getNormalizer());
|
||||
}
|
||||
|
||||
public function testGetNormalizerDefault()
|
||||
{
|
||||
self::assertNull($this->question->getNormalizer());
|
||||
}
|
||||
}
|
||||
Vendored
+7
-4
@@ -17,15 +17,17 @@
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"symfony/contracts": "^1.0",
|
||||
"symfony/polyfill-mbstring": "~1.0"
|
||||
"symfony/polyfill-mbstring": "~1.0",
|
||||
"symfony/polyfill-php73": "^1.8",
|
||||
"symfony/service-contracts": "^1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/config": "~3.4|~4.0",
|
||||
"symfony/event-dispatcher": "~3.4|~4.0",
|
||||
"symfony/event-dispatcher": "^4.3",
|
||||
"symfony/dependency-injection": "~3.4|~4.0",
|
||||
"symfony/lock": "~3.4|~4.0",
|
||||
"symfony/process": "~3.4|~4.0",
|
||||
"symfony/var-dumper": "^4.3",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"provide": {
|
||||
@@ -39,6 +41,7 @@
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/dependency-injection": "<3.4",
|
||||
"symfony/event-dispatcher": "<4.3",
|
||||
"symfony/process": "<3.3"
|
||||
},
|
||||
"autoload": {
|
||||
@@ -50,7 +53,7 @@
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.2-dev"
|
||||
"dev-master": "4.3-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user