Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 732a9ca

Browse files
Merge branch '7.3' into 7.4
* 7.3: [HttpClient] Fix ever growing $maxHostConnections Fix typo [DependencyInjection] Fix referencing build-time array parameters cs fix [FrameworkBundle] Fix cache:pool:prune exit code on failure [Form] Always normalize CRLF and CR to LF in `TextareaType` [Cache] Fix stampede protection when forcing item recomputation [Console] Fix EofShortcut instruction when using a modern terminal on Windows [Console] Do not call non-static method via class-name [Console] Fix choice autocomplete issue when string has spaces Update SameOriginCsrfTokenManager.php [Serializer] Fix inconsistent field naming from accessors when using groups [Finder] Fix converting unanchored glob patterns to regex
2 parents b2683d6 + 3fe6281 commit 732a9ca

5 files changed

Lines changed: 35 additions & 6 deletions

File tree

Attribute/Argument.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public static function tryFrom(\ReflectionParameter|\ReflectionProperty $member)
8787
}
8888

8989
if (\is_array($self->suggestedValues) && !\is_callable($self->suggestedValues) && 2 === \count($self->suggestedValues) && ($instance = $reflection->getSourceThis()) && $instance::class === $self->suggestedValues[0] && \is_callable([$instance, $self->suggestedValues[1]])) {
90+
// In case that the callback is declared as a static method `[Foo::class, 'methodName']` - yet it is not callable,
91+
// while non-static method `[Foo $instance, 'methodName']` would be callable, we transform the callback on the fly into a non-static version.
9092
$self->suggestedValues = [$instance, $self->suggestedValues[1]];
9193
}
9294

Helper/QuestionHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
306306
if ($numMatches > 0 && -1 !== $ofs) {
307307
$ret = (string) $matches[$ofs];
308308
// Echo out remaining chars for current match
309-
$remainingCharacters = substr($ret, \strlen(trim($this->mostRecentlyEnteredValue($fullChoice))));
309+
$remainingCharacters = substr($ret, \strlen($this->mostRecentlyEnteredValue($fullChoice)));
310310
$output->write($remainingCharacters);
311311
$fullChoice .= $remainingCharacters;
312312
$i = (false === $encoding = mb_detect_encoding($fullChoice, null, true)) ? \strlen($fullChoice) : mb_strlen($fullChoice, $encoding);
@@ -360,7 +360,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
360360
if ($numMatches > 0 && -1 !== $ofs) {
361361
$cursor->savePosition();
362362
// Write highlighted text, complete the partially entered response
363-
$charactersEntered = \strlen(trim($this->mostRecentlyEnteredValue($fullChoice)));
363+
$charactersEntered = \strlen($this->mostRecentlyEnteredValue($fullChoice));
364364
$output->write('<hl>'.OutputFormatter::escapeTrailingBackslash(substr($matches[$ofs], $charactersEntered)).'</hl>');
365365
$cursor->restorePosition();
366366
}

Helper/SymfonyQuestionHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function writePrompt(OutputInterface $output, Question $question): voi
3131
$default = $question->getDefault();
3232

3333
if ($question->isMultiline()) {
34-
$text .= \sprintf(' (press %s to continue)', $this->getEofShortcut());
34+
$text .= \sprintf(' (press %s to continue)', $this->getEofShortcut($output));
3535
}
3636

3737
switch (true) {
@@ -92,9 +92,9 @@ protected function writeError(OutputInterface $output, \Exception $error): void
9292
parent::writeError($output, $error);
9393
}
9494

95-
private function getEofShortcut(): string
95+
private function getEofShortcut(OutputInterface $output): string
9696
{
97-
if ('Windows' === \PHP_OS_FAMILY) {
97+
if ('\\' === \DIRECTORY_SEPARATOR && !$output->isDecorated()) {
9898
return '<comment>Ctrl+Z</comment> then <comment>Enter</comment>';
9999
}
100100

Tests/Command/InvokableCommandTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ public function testCommandInputArgumentDefinition()
4242
#[Argument] ?string $firstName,
4343
#[Argument] string $lastName = '',
4444
#[Argument(description: 'Short argument description')] string $bio = '',
45+
// In this test case, we declare the callback in static context, even when the method is NOT static.
46+
// PHP doesn't allow using `$this` here, and the callback is later modified on-the-fly
47+
// to be called on the instance instead, and this test case validates if this mechanism works.
48+
//
49+
// @see \Symfony\Component\Console\Attribute\Argument
4550
#[Argument(suggestedValues: [self::class, 'getSuggestedRoles'])] array $roles = ['ROLE_USER'],
4651
): int {
52+
\assert(null !== $this); // so PHP CS Fixer knows this callback is actually coupled with `$this` and `static_lambda` rule shall not be applied
53+
4754
return 0;
4855
});
4956

@@ -88,6 +95,8 @@ public function testCommandInputOptionDefinition()
8895
#[Option(suggestedValues: [self::class, 'getSuggestedRoles'])] array $roles = ['ROLE_USER'],
8996
#[Option] string|bool $opt = false,
9097
): int {
98+
\assert(null !== $this); // so PHP CS Fixer knows this callback is actually coupled with `$this` and `static_lambda` rule shall not be applied
99+
91100
return 0;
92101
});
93102

Tests/Helper/QuestionHelperTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,24 @@ public function testAskWithAutocompleteWithMultiByteCharacter($character)
415415
$this->assertSame($character, $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
416416
}
417417

418+
public function testAutocompleteWithSpaceAfterPartialMatch()
419+
{
420+
if (!Terminal::hasSttyAvailable()) {
421+
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
422+
}
423+
424+
// a<SPACE><TAB><NEWLINE>
425+
$inputStream = $this->getInputStream("a \t\n");
426+
427+
$dialog = new QuestionHelper();
428+
$dialog->setHelperSet(new HelperSet([new FormatterHelper()]));
429+
430+
$question = new ChoiceQuestion('Please select a choice', ['a test', 'another choice']);
431+
$question->setMaxAttempts(1);
432+
433+
$this->assertSame('a test', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
434+
}
435+
418436
public function testAutocompleteWithTrailingBackslash()
419437
{
420438
if (!Terminal::hasSttyAvailable()) {
@@ -970,7 +988,7 @@ public function testExitCommandOnInputSIGINT(string $mode)
970988
}
971989

972990
$p = new Process(
973-
['php', dirname(__DIR__).'/Fixtures/application_test_sigint.php', $mode],
991+
['php', \dirname(__DIR__).'/Fixtures/application_test_sigint.php', $mode],
974992
timeout: 2, // the process will auto shutdown if not killed by SIGINT, to prevent blocking
975993
);
976994
$p->setPty(true);

0 commit comments

Comments
 (0)