Skip to content

Commit 8d6da3d

Browse files
Merge branch '3.4' into 4.4
* 3.4: Fixes sprintf(): Too few arguments in form transformer [Console] Fix QuestionHelper::disableStty() validate subforms in all validation groups Update Hungarian translations Add meaningful message when Process is not installed (ProcessHelper) [PropertyAccess] Fix TypeError parsing again. [Form] add missing Czech validators translation [Validator] add missing Czech translations never directly validate Existence (Required/Optional) constraints
2 parents 6b456a7 + 6ad3319 commit 8d6da3d

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

Helper/ProcessHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class ProcessHelper extends Helper
3838
*/
3939
public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
4040
{
41+
if (!class_exists(Process::class)) {
42+
throw new \LogicException('The Process helper requires the "Process" component. Install "symfony/process" to use it.');
43+
}
44+
4145
if ($output instanceof ConsoleOutputInterface) {
4246
$output = $output->getErrorOutput();
4347
}

Helper/QuestionHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class QuestionHelper extends Helper
3333
{
3434
private $inputStream;
3535
private static $shell;
36-
private static $stty;
36+
private static $stty = true;
3737

3838
/**
3939
* Asks a question to the user.
@@ -107,7 +107,7 @@ private function doAsk(OutputInterface $output, Question $question)
107107
$inputStream = $this->inputStream ?: STDIN;
108108
$autocomplete = $question->getAutocompleterCallback();
109109

110-
if (null === $autocomplete || !Terminal::hasSttyAvailable()) {
110+
if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) {
111111
$ret = false;
112112
if ($question->isHidden()) {
113113
try {
@@ -417,7 +417,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $
417417
return $value;
418418
}
419419

420-
if (Terminal::hasSttyAvailable()) {
420+
if (self::$stty && Terminal::hasSttyAvailable()) {
421421
$sttyMode = shell_exec('stty -g');
422422

423423
shell_exec('stty -echo');

Tests/Helper/QuestionHelperTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Tests\Helper;
1313

14+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1415
use Symfony\Component\Console\Formatter\OutputFormatter;
1516
use Symfony\Component\Console\Helper\FormatterHelper;
1617
use Symfony\Component\Console\Helper\HelperSet;
@@ -783,6 +784,35 @@ public function testTraversableAutocomplete()
783784
$this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
784785
}
785786

787+
public function testDisableSttby()
788+
{
789+
if (!Terminal::hasSttyAvailable()) {
790+
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
791+
}
792+
793+
$this->expectException(InvalidArgumentException::class);
794+
$this->expectExceptionMessage('invalid');
795+
796+
QuestionHelper::disableStty();
797+
$dialog = new QuestionHelper();
798+
$dialog->setHelperSet(new HelperSet([new FormatterHelper()]));
799+
800+
$question = new ChoiceQuestion('Please select a bundle', [1 => 'AcmeDemoBundle', 4 => 'AsseticBundle']);
801+
$question->setMaxAttempts(1);
802+
803+
// <UP ARROW><UP ARROW><NEWLINE><DOWN ARROW><DOWN ARROW><NEWLINE>
804+
// Gives `AcmeDemoBundle` with stty
805+
$inputStream = $this->getInputStream("\033[A\033[A\n\033[B\033[B\n");
806+
807+
try {
808+
$dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question);
809+
} finally {
810+
$reflection = new \ReflectionProperty(QuestionHelper::class, 'stty');
811+
$reflection->setAccessible(true);
812+
$reflection->setValue(null, true);
813+
}
814+
}
815+
786816
public function testTraversableMultiselectAutocomplete()
787817
{
788818
// <NEWLINE>

0 commit comments

Comments
 (0)