Sort alternatives alphabetically when a command is not found
This commit is contained in:
parent
e7c12d3f2e
commit
f04b1bd72f
@ -1019,7 +1019,7 @@ class Application
|
||||
}
|
||||
|
||||
$alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; });
|
||||
asort($alternatives);
|
||||
ksort($alternatives);
|
||||
|
||||
return array_keys($alternatives);
|
||||
}
|
||||
|
@ -477,6 +477,36 @@ class ApplicationTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testFindAlternativesOutput()
|
||||
{
|
||||
$application = new Application();
|
||||
|
||||
$application->add(new \FooCommand());
|
||||
$application->add(new \Foo1Command());
|
||||
$application->add(new \Foo2Command());
|
||||
$application->add(new \Foo3Command());
|
||||
|
||||
$expectedAlternatives = array(
|
||||
'afoobar',
|
||||
'afoobar1',
|
||||
'afoobar2',
|
||||
'foo1:bar',
|
||||
'foo3:bar',
|
||||
'foo:bar',
|
||||
'foo:bar1',
|
||||
);
|
||||
|
||||
try {
|
||||
$application->find('foo');
|
||||
$this->fail('->find() throws a CommandNotFoundException if command is not defined');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command is not defined');
|
||||
$this->assertSame($expectedAlternatives, $e->getAlternatives());
|
||||
|
||||
$this->assertRegExp('/Command "foo" is not defined\..*Did you mean one of these\?.*/Ums', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces()
|
||||
{
|
||||
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(array('getNamespaces'))->getMock();
|
||||
|
Reference in New Issue
Block a user