本文整理汇总了PHP中Symfony\Component\Console\Application::hasCommand方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::hasCommand方法的具体用法?PHP Application::hasCommand怎么用?PHP Application::hasCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Application
的用法示例。
在下文中一共展示了Application::hasCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHasGetCommand
public function testHasGetCommand()
{
$application = new Application();
$this->assertTrue($application->hasCommand('list'), '->hasCommand() returns true if a named command is registered');
$this->assertFalse($application->hasCommand('afoobar'), '->hasCommand() returns false if a named command is not registered');
$application->addCommand($foo = new \FooCommand());
$this->assertTrue($application->hasCommand('afoobar'), '->hasCommand() returns true if an alias is registered');
$this->assertEquals($foo, $application->getCommand('foo:bar'), '->getCommand() returns a command by name');
$this->assertEquals($foo, $application->getCommand('afoobar'), '->getCommand() returns a command by alias');
try {
$application->getCommand('foofoo');
$this->fail('->getCommand() throws an \\InvalidArgumentException if the command does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\\InvalidArgumentException', $e, '->getCommand() throws an \\InvalidArgumentException if the command does not exist');
$this->assertEquals('The command "foofoo" does not exist.', $e->getMessage(), '->getCommand() throws an \\InvalidArgumentException if the command does not exist');
}
$application = new TestApplication();
$application->addCommand($foo = new \FooCommand());
$application->setWantHelps();
$command = $application->getCommand('foo:bar');
$this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($command), '->getCommand() returns the help command if --help is provided as the input');
}