From 863f63205415ee9add06ee50f2984194a9f77b91 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Wed, 6 Dec 2017 13:44:17 +0100 Subject: [PATCH 1/4] [Console] Commands with an alias should not be recognized as ambiguous --- src/Symfony/Component/Console/Application.php | 9 ++++---- .../Console/Tests/ApplicationTest.php | 10 +++++++++ .../Console/Tests/Fixtures/TestTiti.php | 21 ++++++++++++++++++ .../Console/Tests/Fixtures/TestToto.php | 22 +++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/TestTiti.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/TestToto.php diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 6ab9f011ac..53460d2de2 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -498,7 +498,7 @@ class Application public function find($name) { $this->init(); - + $aliases = array(); $allCommands = array_keys($this->commands); $expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name); $commands = preg_grep('{^'.$expr.'}', $allCommands); @@ -526,15 +526,16 @@ class Application // filter out aliases for commands which are already on the list if (count($commands) > 1) { $commandList = $this->commands; - $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) { + $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands, &$aliases) { $commandName = $commandList[$nameOrAlias]->getName(); + $aliases[$nameOrAlias] = $commandName; return $commandName === $nameOrAlias || !in_array($commandName, $commands); }); } - $exact = in_array($name, $commands, true); - if (count($commands) > 1 && !$exact) { + $exact = in_array($name, $commands, true) || isset($aliases[$name]); + if (!$exact && count($commands) > 1) { $suggestions = $this->getAbbreviationSuggestions(array_values($commands)); throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions)); diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 8ffc5d6951..5ab3b0a598 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -49,6 +49,8 @@ class ApplicationTest extends TestCase require_once self::$fixturesPath.'/BarBucCommand.php'; require_once self::$fixturesPath.'/FooSubnamespaced1Command.php'; require_once self::$fixturesPath.'/FooSubnamespaced2Command.php'; + require_once self::$fixturesPath.'/TestTiti.php'; + require_once self::$fixturesPath.'/TestToto.php'; } protected function normalizeLineBreaks($text) @@ -226,6 +228,14 @@ class ApplicationTest extends TestCase $application->findNamespace('f'); } + public function testFindNonAmbiguous() + { + $application = new Application(); + $application->add(new \TestTiti()); + $application->add(new \TestToto()); + $this->assertEquals('test-toto', $application->find('test')->getName()); + } + /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage There are no commands defined in the "bar" namespace. diff --git a/src/Symfony/Component/Console/Tests/Fixtures/TestTiti.php b/src/Symfony/Component/Console/Tests/Fixtures/TestTiti.php new file mode 100644 index 0000000000..72e29d2a0a --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/TestTiti.php @@ -0,0 +1,21 @@ +setName('test-titi') + ->setDescription('The test:titi command') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->write('test-titi'); + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/TestToto.php b/src/Symfony/Component/Console/Tests/Fixtures/TestToto.php new file mode 100644 index 0000000000..f14805db68 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/TestToto.php @@ -0,0 +1,22 @@ +setName('test-toto') + ->setDescription('The test-toto command') + ->setAliases(array('test')) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->write('test-toto'); + } +} From a5bc7d649b9c519ff1445493ccaeb6e6591c267d Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Tue, 19 Dec 2017 22:44:19 +0100 Subject: [PATCH 2/4] PHP CS Fixer: use PHPUnit Migration ruleset --- .php_cs.dist | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.php_cs.dist b/.php_cs.dist index 7f8d3b03bc..27b38a4dae 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -8,9 +8,10 @@ return PhpCsFixer\Config::create() ->setRules(array( '@Symfony' => true, '@Symfony:risky' => true, + '@PHPUnit48Migration:risky' => true, + 'php_unit_no_expectation_annotation' => false, // part of `PHPUnitXYMigration:risky` ruleset, to be enabled when PHPUnit 4.x support will be dropped, as we don't want to rewrite exceptions handling twice 'array_syntax' => array('syntax' => 'long'), 'protected_to_private' => false, - 'php_unit_dedicate_assert' => array('target' => '3.5'), )) ->setRiskyAllowed(true) ->setFinder( From d4a428c20d996886c167be64c904adbaf95c3262 Mon Sep 17 00:00:00 2001 From: "Issei.M" Date: Wed, 27 Dec 2017 17:53:35 +0900 Subject: [PATCH 3/4] [Config] Fix closure CS --- src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php index 004042817a..f83f1c209b 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php @@ -161,7 +161,7 @@ class ExprBuilder */ public function thenInvalid($message) { - $this->thenPart = function ($v) use ($message) {throw new \InvalidArgumentException(sprintf($message, json_encode($v))); }; + $this->thenPart = function ($v) use ($message) { throw new \InvalidArgumentException(sprintf($message, json_encode($v))); }; return $this; } From 29486a431cb24e690dc34ee2d66d8fe031b041a0 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 28 Dec 2017 02:21:22 +0200 Subject: [PATCH 4/4] [Serializer] Correct typing mistake in DocBlock | Q | A | ------------- | --- | Branch? | 2.1 to 4.0 | Bug fix? | yes (comment only) | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | na | Fixed tickets | na | License | MIT | Doc PR | DocBlock comment referred to `NormalizableInterface` but code was using `DenormalizableInterface` --- .../Component/Serializer/Normalizer/CustomNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php index f64aa4d3e3..a470a65561 100644 --- a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php @@ -49,7 +49,7 @@ class CustomNormalizer extends SerializerAwareNormalizer implements NormalizerIn } /** - * Checks if the given class implements the NormalizableInterface. + * Checks if the given class implements the DenormalizableInterface. * * @param mixed $data Data to denormalize from * @param string $type The class to which the data should be denormalized