Exemplo n.º 1
0
    $application->findNamespace('f');
    $t->fail('->findNamespace() throws an \\InvalidArgumentException if the abbreviation is ambiguous');
} catch (\InvalidArgumentException $e) {
    $t->pass('->findNamespace() throws an \\InvalidArgumentException if the abbreviation is ambiguous');
}
try {
    $application->findNamespace('bar');
    $t->fail('->findNamespace() throws an \\InvalidArgumentException if no command is in the given namespace');
} catch (\InvalidArgumentException $e) {
    $t->pass('->findNamespace() throws an \\InvalidArgumentException if no command is in the given namespace');
}
// ->findCommand()
$t->diag('->findCommand()');
$application = new TestApplication();
$application->addCommand(new FooCommand());
$t->is(get_class($application->findCommand('foo:bar')), 'FooCommand', '->findCommand() returns a command if its name exists');
$t->is(get_class($application->findCommand('h')), 'Symfony\\Components\\CLI\\Command\\HelpCommand', '->findCommand() returns a command if its name exists');
$t->is(get_class($application->findCommand('f:bar')), 'FooCommand', '->findCommand() returns a command if the abbreviation for the namespace exists');
$t->is(get_class($application->findCommand('f:b')), 'FooCommand', '->findCommand() returns a command if the abbreviation for the namespace and the command name exist');
$t->is(get_class($application->findCommand('a')), 'FooCommand', '->findCommand() returns a command if the abbreviation exists for an alias');
$application->addCommand(new Foo1Command());
$application->addCommand(new Foo2Command());
try {
    $application->findCommand('f');
    $t->fail('->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a namespace');
} catch (\InvalidArgumentException $e) {
    $t->pass('->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for a namespace');
}
try {
    $application->findCommand('a');
    $t->fail('->findCommand() throws an \\InvalidArgumentException if the abbreviation is ambiguous for an alias');