diff --git a/Input/ArgvInput.php b/Input/ArgvInput.php index fe25b861a..d7c57f688 100644 --- a/Input/ArgvInput.php +++ b/Input/ArgvInput.php @@ -179,7 +179,7 @@ private function parseArgument(string $token): void } else { $all = $this->definition->getArguments(); $symfonyCommandName = null; - if (($inputArgument = $all[$key = array_key_first($all)] ?? null) && 'command' === $inputArgument->getName()) { + if (($inputArgument = $all[$key = array_key_first($all) ?? ''] ?? null) && 'command' === $inputArgument->getName()) { $symfonyCommandName = $this->arguments['command'] ?? null; unset($all[$key]); } diff --git a/Question/ChoiceQuestion.php b/Question/ChoiceQuestion.php index 36c240d37..4fc296d9f 100644 --- a/Question/ChoiceQuestion.php +++ b/Question/ChoiceQuestion.php @@ -25,9 +25,9 @@ class ChoiceQuestion extends Question private string $errorMessage = 'Value "%s" is invalid'; /** - * @param string $question The question to ask to the user - * @param array $choices The list of available choices - * @param string|bool|int|float|null $default The default answer to return + * @param string $question The question to ask to the user + * @param array $choices The list of available choices + * @param string|bool|int|float|null $default The default answer to return */ public function __construct( string $question, @@ -45,7 +45,7 @@ public function __construct( } /** - * Returns available choices. + * @return array */ public function getChoices(): array { diff --git a/Resources/completion.bash b/Resources/completion.bash index 64c6a338f..2befe76cb 100644 --- a/Resources/completion.bash +++ b/Resources/completion.bash @@ -37,7 +37,7 @@ _sf_{{ COMMAND_NAME }}() { local completecmd=("$sf_cmd" "_complete" "--no-interaction" "-sbash" "-c$cword" "-a{{ VERSION }}") for w in ${words[@]}; do - w=$(printf -- '%b' "$w") + w="${w//\\\\/\\}" # remove quotes from typed values quote="${w:0:1}" if [ "$quote" == \' ]; then diff --git a/Tester/TesterTrait.php b/Tester/TesterTrait.php index 127556d1d..238c7b7eb 100644 --- a/Tester/TesterTrait.php +++ b/Tester/TesterTrait.php @@ -168,10 +168,10 @@ private static function createStream(array $inputs) $stream = fopen('php://memory', 'r+', false); foreach ($inputs as $input) { - fwrite($stream, $input.\PHP_EOL); + fwrite($stream, $input); - if (str_contains($input, \PHP_EOL)) { - fwrite($stream, "\x4"); + if (!str_ends_with($input, "\x4")) { + fwrite($stream, \PHP_EOL); } } diff --git a/Tests/Tester/CommandTesterTest.php b/Tests/Tester/CommandTesterTest.php index cfdebe4d8..d36042038 100644 --- a/Tests/Tester/CommandTesterTest.php +++ b/Tests/Tester/CommandTesterTest.php @@ -139,6 +139,32 @@ public function testCommandWithInputs() $this->assertEquals(implode('', $questions), $tester->getDisplay(true)); } + public function testCommandWithMultilineInputs() + { + $question = 'What is your address?'; + + $command = new Command('foo'); + $command->setHelperSet(new HelperSet([new QuestionHelper()])); + $command->setCode(function (InputInterface $input, OutputInterface $output) use ($question, $command): int { + $output->write($command->getHelper('question')->ask($input, $output, (new Question($question))->setMultiline(true))); + $output->write(stream_get_contents($input->getStream())); + + return 0; + }); + + $tester = new CommandTester($command); + + $address = <<
setInputs([$address."\x04", $address]); + $tester->execute([]); + + $tester->assertCommandIsSuccessful(); + $this->assertSame($question.$address.$address.\PHP_EOL, $tester->getDisplay()); + } + public function testCommandWithDefaultInputs() { $questions = [