Skip to content

Commit

Permalink
Merge branch '2.8' into 3.3
Browse files Browse the repository at this point in the history
* 2.8:
  [Serializer] Correct typing mistake in DocBlock
  [Config] Fix closure CS
  PHP CS Fixer: use PHPUnit Migration ruleset
  [Console] Commands with an alias should not be recognized as ambiguous
  • Loading branch information
Robin Chalas committed Dec 29, 2017
2 parents 8a1a9f9 + 88f7e33 commit 67ceb50
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .php_cs.dist
Expand Up @@ -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(
Expand Down
Expand Up @@ -186,7 +186,7 @@ public function thenEmptyArray()
*/
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;
}
Expand Down
7 changes: 4 additions & 3 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -550,7 +550,7 @@ public function findNamespace($namespace)
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);
Expand Down Expand Up @@ -578,14 +578,15 @@ public function find($name)
// 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);
$exact = in_array($name, $commands, true) || isset($aliases[$name]);
if (count($commands) > 1 && !$exact) {
$usableWidth = $this->terminal->getWidth() - 10;
$abbrevs = array_values($commands);
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -51,6 +51,8 @@ public static function setUpBeforeClass()
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)
Expand Down Expand Up @@ -234,6 +236,14 @@ public function testFindAmbiguousNamespace()
$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 \Symfony\Component\Console\Exception\CommandNotFoundException
* @expectedExceptionMessage There are no commands defined in the "bar" namespace.
Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Component/Console/Tests/Fixtures/TestTiti.php
@@ -0,0 +1,21 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestTiti extends Command
{
protected function configure()
{
$this
->setName('test-titi')
->setDescription('The test:titi command')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$output->write('test-titi');
}
}
22 changes: 22 additions & 0 deletions src/Symfony/Component/Console/Tests/Fixtures/TestToto.php
@@ -0,0 +1,22 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestToto extends Command
{
protected function configure()
{
$this
->setName('test-toto')
->setDescription('The test-toto command')
->setAliases(array('test'))
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$output->write('test-toto');
}
}
Expand Up @@ -54,7 +54,7 @@ public function supportsNormalization($data, $format = null)
}

/**
* 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
Expand Down

0 comments on commit 67ceb50

Please sign in to comment.