$this->assertEquals('<info>foo</info> version <comment>bar</comment>',$application->getLongVersion(),'->getLongVersion() returns the long version of the application');
$this->assertEquals('Symfony\\Components\\Console\\Command\\HelpCommand',get_class($commands['help']),'->getCommands() returns the registered commands');
$application->addCommand(new\FooCommand());
$commands=$application->getCommands('foo');
$this->assertEquals(1,count($commands),'->getCommands() takes a namespace as its first argument');
$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=newTestApplication();
$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');
$this->assertEquals('foo',$application->findNamespace('foo'),'->findNamespace() returns the given namespace if it exists');
$this->assertEquals('foo',$application->findNamespace('f'),'->findNamespace() finds a namespace given an abbreviation');
$application->addCommand(new\Foo2Command());
$this->assertEquals('foo',$application->findNamespace('foo'),'->findNamespace() returns the given namespace if it exists');
try
{
$application->findNamespace('f');
$this->fail('->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
}
catch(\Exception$e)
{
$this->assertInstanceOf('\InvalidArgumentException',$e,'->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
$this->assertEquals('The namespace "f" is ambiguous (foo, foo1).',$e->getMessage(),'->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
}
try
{
$application->findNamespace('bar');
$this->fail('->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
}
catch(\Exception$e)
{
$this->assertInstanceOf('\InvalidArgumentException',$e,'->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
$this->assertEquals('There are no commands defined in the "bar" namespace.',$e->getMessage(),'->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
$this->assertEquals('FooCommand',get_class($application->findCommand('foo:bar')),'->findCommand() returns a command if its name exists');
$this->assertEquals('Symfony\Components\Console\Command\HelpCommand',get_class($application->findCommand('h')),'->findCommand() returns a command if its name exists');
$this->assertEquals('FooCommand',get_class($application->findCommand('f:bar')),'->findCommand() returns a command if the abbreviation for the namespace exists');
$this->assertEquals('FooCommand',get_class($application->findCommand('f:b')),'->findCommand() returns a command if the abbreviation for the namespace and the command name exist');
$this->assertEquals('FooCommand',get_class($application->findCommand('a')),'->findCommand() returns a command if the abbreviation exists for an alias');
$application->addCommand(new\Foo1Command());
$application->addCommand(new\Foo2Command());
try
{
$application->findCommand('f');
$this->fail('->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
}
catch(\Exception$e)
{
$this->assertInstanceOf('\InvalidArgumentException',$e,'->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
$this->assertEquals('Command "f" is not defined.',$e->getMessage(),'->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
}
try
{
$application->findCommand('a');
$this->fail('->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
}
catch(\Exception$e)
{
$this->assertInstanceOf('\InvalidArgumentException',$e,'->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
$this->assertEquals('Command "a" is ambiguous (afoobar, afoobar1 and 1 more).',$e->getMessage(),'->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
}
try
{
$application->findCommand('foo:b');
$this->fail('->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
}
catch(\Exception$e)
{
$this->assertInstanceOf('\InvalidArgumentException',$e,'->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
$this->assertEquals('Command "foo:b" is ambiguous (foo:bar, foo:bar1).',$e->getMessage(),'->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt',$application->asText(),'->asText() returns a text representation of the application');
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt',$application->asText('foo'),'->asText() returns a text representation of the application');
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt',$application->asXml(),'->asXml() returns an XML representation of the application');
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt',$application->asXml('foo'),'->asXml() returns an XML representation of the application');
}
publicfunctiontestRenderException()
{
$application=newApplication();
$application->setAutoExit(false);
$tester=newApplicationTester($application);
$tester->run(array('command'=>'foo'));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt',$tester->getDisplay(),'->renderException() renders a pretty exception');
$this->assertRegExp('/Exception trace/',$tester->getDisplay(),'->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt',$tester->getDisplay(),'->renderException() renders the command synopsis when an exception occurs in the context of a command');
$this->assertEquals('Symfony\Components\Console\Input\ArgvInput',get_class($command->input),'->run() creates an ArgvInput by default if none is given');
$this->assertEquals('Symfony\Components\Console\Output\ConsoleOutput',get_class($command->output),'->run() creates a ConsoleOutput by default if none is given');
$application=newApplication();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$tester=newApplicationTester($application);
$tester->run(array());
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt',$tester->getDisplay(),'->run() runs the list command if no argument is passed');
$tester->run(array('--help'=>true));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt',$tester->getDisplay(),'->run() runs the help command if --help is passed');
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt',$tester->getDisplay(),'->run() displays the help if --help is passed');
$application=newApplication();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$tester=newApplicationTester($application);
$tester->run(array('--color'=>true));
$this->assertTrue($tester->getOutput()->isDecorated(),'->run() forces color output if --color is passed');
$application=newApplication();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$tester=newApplicationTester($application);
$tester->run(array('--version'=>true));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt',$tester->getDisplay(),'->run() displays the program version if --version is passed');