当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::getCommand方法代码示例

本文整理汇总了PHP中Symfony\Component\Console\Application::getCommand方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getCommand方法的具体用法?PHP Application::getCommand怎么用?PHP Application::getCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Console\Application的用法示例。


在下文中一共展示了Application::getCommand方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testExecute

 public function testExecute()
 {
     $application = new Application();
     $commandTester = new CommandTester($command = $application->getCommand('list'));
     $commandTester->execute(array('command' => $command->getFullName()));
     $this->assertRegExp('/help   Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
     $commandTester->execute(array('command' => $command->getFullName(), '--xml' => true));
     $this->assertRegExp('/<command id="list" namespace="_global" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
 }
开发者ID:netixpro,项目名称:symfony,代码行数:9,代码来源:ListCommandTest.php

示例2: testExecute

 public function testExecute()
 {
     $command = new HelpCommand();
     $command->setCommand(new ListCommand());
     $commandTester = new CommandTester($command);
     $commandTester->execute(array());
     $this->assertRegExp('/list \\[--xml\\] \\[namespace\\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
     $commandTester->execute(array('--xml' => true));
     $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
     $application = new Application();
     $commandTester = new CommandTester($application->getCommand('help'));
     $commandTester->execute(array('command_name' => 'list'));
     $this->assertRegExp('/list \\[--xml\\] \\[namespace\\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
     $commandTester->execute(array('command_name' => 'list', '--xml' => true));
     $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
 }
开发者ID:netixpro,项目名称:symfony,代码行数:16,代码来源:HelpCommandTest.php

示例3: 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');
 }
开发者ID:netixpro,项目名称:symfony,代码行数:22,代码来源:ApplicationTest.php


注:本文中的Symfony\Component\Console\Application::getCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。