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\\Components\\Console\\Command\\HelpCommand', get_class($command), '->getCommand() returns the help command if --help is provided as the input'); }