Skip to content

Commit f91588c

Browse files
Merge branch '4.4' into 5.0
* 4.4: Fix abstract method name in PHP doc block Various cleanups [HttpClient] fix issues in tests Fixes sprintf(): Too few arguments in form transformer [Console] Fix QuestionHelper::disableStty() [Validator] Use Mime component to determine mime type for file validator validate subforms in all validation groups Update Hungarian translations Add meaningful message when Process is not installed (ProcessHelper) [PropertyAccess] Fix TypeError parsing again. [TwigBridge] fix fallback html-to-txt body converter [Form] add missing Czech validators translation [Validator] add missing Czech translations never directly validate Existence (Required/Optional) constraints
2 parents a1b507f + 326b064 commit f91588c

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

Helper/ProcessHelper.php

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class ProcessHelper extends Helper
3636
*/
3737
public function run(OutputInterface $output, $cmd, string $error = null, callable $callback = null, int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): Process
3838
{
39+
if (!class_exists(Process::class)) {
40+
throw new \LogicException('The ProcessHelper cannot be run as the Process component is not installed. Try running "compose require symfony/process".');
41+
}
42+
3943
if ($output instanceof ConsoleOutputInterface) {
4044
$output = $output->getErrorOutput();
4145
}

Helper/QuestionHelper.php

+3-3
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 {
@@ -415,7 +415,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $
415415
return $value;
416416
}
417417

418-
if (Terminal::hasSttyAvailable()) {
418+
if (self::$stty && Terminal::hasSttyAvailable()) {
419419
$sttyMode = shell_exec('stty -g');
420420

421421
shell_exec('stty -echo');

Tests/Helper/QuestionHelperTest.php

+30
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)