From 62c4b969e4a88f90aad65aa4c60736cffa277710 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Mon, 23 Dec 2019 21:21:28 +0100 Subject: [PATCH 1/6] [Console] Fix filtering out identical alternatives when there is a command loader --- Application.php | 13 +++++++------ Tests/ApplicationTest.php | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Application.php b/Application.php index d181e41e8..1463967ff 100644 --- a/Application.php +++ b/Application.php @@ -645,8 +645,13 @@ public function find($name) // filter out aliases for commands which are already on the list if (\count($commands) > 1) { $commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands; - $commands = array_unique(array_filter($commands, function ($nameOrAlias) use ($commandList, $commands, &$aliases) { - $commandName = $commandList[$nameOrAlias] instanceof Command ? $commandList[$nameOrAlias]->getName() : $nameOrAlias; + $commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) { + if (!$commandList[$nameOrAlias] instanceof Command) { + $commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias); + } + + $commandName = $commandList[$nameOrAlias]->getName(); + $aliases[$nameOrAlias] = $commandName; return $commandName === $nameOrAlias || !\in_array($commandName, $commands); @@ -662,10 +667,6 @@ public function find($name) $maxLen = max(Helper::strlen($abbrev), $maxLen); } $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen) { - if (!$commandList[$cmd] instanceof Command) { - $commandList[$cmd] = $this->commandLoader->get($cmd); - } - if ($commandList[$cmd]->isHidden()) { return false; } diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index 30c0688ac..559c42599 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -568,6 +568,9 @@ public function testFindAlternativeCommandsWithAnAlias() $fooCommand->setAliases(['foo2']); $application = new Application(); + $application->setCommandLoader(new FactoryCommandLoader([ + 'foo3' => static function () use ($fooCommand) { return $fooCommand; }, + ])); $application->add($fooCommand); $result = $application->find('foo'); From ca0c37cac523747e13d4c4fcc150f75bd7765c1d Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Sun, 29 Dec 2019 18:50:02 +0100 Subject: [PATCH 2/6] [Console][FormatterHelper] Use helper strlen statically and remove duplicated code --- Helper/FormatterHelper.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Helper/FormatterHelper.php b/Helper/FormatterHelper.php index 4ad63856d..d6eccee8e 100644 --- a/Helper/FormatterHelper.php +++ b/Helper/FormatterHelper.php @@ -54,12 +54,12 @@ public function formatBlock($messages, $style, $large = false) foreach ($messages as $message) { $message = OutputFormatter::escape($message); $lines[] = sprintf($large ? ' %s ' : ' %s ', $message); - $len = max($this->strlen($message) + ($large ? 4 : 2), $len); + $len = max(self::strlen($message) + ($large ? 4 : 2), $len); } $messages = $large ? [str_repeat(' ', $len)] : []; for ($i = 0; isset($lines[$i]); ++$i) { - $messages[] = $lines[$i].str_repeat(' ', $len - $this->strlen($lines[$i])); + $messages[] = $lines[$i].str_repeat(' ', $len - self::strlen($lines[$i])); } if ($large) { $messages[] = str_repeat(' ', $len); @@ -83,17 +83,13 @@ public function formatBlock($messages, $style, $large = false) */ public function truncate($message, $length, $suffix = '...') { - $computedLength = $length - $this->strlen($suffix); + $computedLength = $length - self::strlen($suffix); - if ($computedLength > $this->strlen($message)) { + if ($computedLength > self::strlen($message)) { return $message; } - if (false === $encoding = mb_detect_encoding($message, null, true)) { - return substr($message, 0, $length).$suffix; - } - - return mb_substr($message, 0, $length, $encoding).$suffix; + return self::substr($message, 0, $length).$suffix; } /** From a667177a24547c6b799ef37bf2dc27312a7985eb Mon Sep 17 00:00:00 2001 From: Jan Rosier Date: Wed, 1 Jan 2020 12:03:25 +0100 Subject: [PATCH 3/6] Update year in license files --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index a677f4376..9e936ec04 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2019 Fabien Potencier +Copyright (c) 2004-2020 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 9611615f4dda813f2c4dfd82001dab71ae10c101 Mon Sep 17 00:00:00 2001 From: Shaharia Azam Date: Sat, 21 Dec 2019 04:13:14 +0600 Subject: [PATCH 4/6] Update links to documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 664a37c0e..3e2fc605e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ interfaces. Resources --------- - * [Documentation](https://symfony.com/doc/current/components/console/index.html) + * [Documentation](https://symfony.com/doc/current/components/console.html) * [Contributing](https://symfony.com/doc/current/contributing/index.html) * [Report issues](https://github.com/symfony/symfony/issues) and [send Pull Requests](https://github.com/symfony/symfony/pulls) From 7c5bdd346f9d90a2d22d4e1fe61e02dc19b98f12 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Thu, 9 Jan 2020 19:48:50 +0100 Subject: [PATCH 5/6] [Console] Fix SymfonyQuestionHelper tests sometimes failing on AppVeyor --- Tests/Helper/SymfonyQuestionHelperTest.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Tests/Helper/SymfonyQuestionHelperTest.php b/Tests/Helper/SymfonyQuestionHelperTest.php index b7a26f950..467f38b6d 100644 --- a/Tests/Helper/SymfonyQuestionHelperTest.php +++ b/Tests/Helper/SymfonyQuestionHelperTest.php @@ -145,13 +145,13 @@ public function testChoiceQuestionPadding() ); $this->assertOutputContains(<< EOT - , $output); + , $output, true); } public function testChoiceQuestionCustomPrompt() @@ -168,9 +168,9 @@ public function testChoiceQuestionCustomPrompt() $this->assertOutputContains(<<ccc> + >ccc> EOT - , $output); + , $output, true); } protected function getInputStream($input) @@ -200,10 +200,15 @@ protected function createInputInterfaceMock($interactive = true) return $mock; } - private function assertOutputContains($expected, StreamOutput $output) + private function assertOutputContains($expected, StreamOutput $output, $normalize = false) { rewind($output->getStream()); $stream = stream_get_contents($output->getStream()); + + if ($normalize) { + $stream = str_replace(PHP_EOL, "\n", $stream); + } + $this->assertStringContainsString($expected, $stream); } } From 345ab6ecb456b5147ea3b3271d7f1f00aadfd257 Mon Sep 17 00:00:00 2001 From: Dmitry Danilson Date: Sun, 19 Jan 2020 18:13:19 +0700 Subject: [PATCH 6/6] Fix #35385: Fix Console typehint --- Input/Input.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Input/Input.php b/Input/Input.php index 8c7905db7..ff5d3170f 100644 --- a/Input/Input.php +++ b/Input/Input.php @@ -104,7 +104,7 @@ public function getArguments() /** * {@inheritdoc} */ - public function getArgument($name) + public function getArgument(string $name) { if (!$this->definition->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); @@ -116,7 +116,7 @@ public function getArgument($name) /** * {@inheritdoc} */ - public function setArgument($name, $value) + public function setArgument(string $name, $value) { if (!$this->definition->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));