public function testExecute() { $application = new Application(); $commandTester = new CommandTester($application->getCommand('list')); $commandTester->execute(array()); $this->assertRegExp('/help Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands'); $commandTester->execute(array('--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'); }
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'); }
require_once __DIR__.'/../../../../bootstrap.php'; use Symfony\Components\Console\Tester\CommandTester; use Symfony\Components\Console\Command\HelpCommand; use Symfony\Components\Console\Command\ListCommand; use Symfony\Components\Console\Application; $t = new LimeTest(4); // ->execute() $t->diag('->execute()'); $command = new HelpCommand(); $command->setCommand(new ListCommand()); $commandTester = new CommandTester($command); $commandTester->execute(array()); $t->like($commandTester->getDisplay(), '/list \[--xml\] \[namespace\]/', '->execute() returns a text help for the given command'); $commandTester->execute(array('--xml' => true)); $t->like($commandTester->getDisplay(), '/<command/', '->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')); $t->like($commandTester->getDisplay(), '/list \[--xml\] \[namespace\]/', '->execute() returns a text help for the given command'); $commandTester->execute(array('command_name' => 'list', '--xml' => true)); $t->like($commandTester->getDisplay(), '/<command/', '->execute() returns an XML help text if --xml is passed');
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'); }
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__.'/../../../../bootstrap.php'; use Symfony\Components\Console\Tester\CommandTester; use Symfony\Components\Console\Application; $t = new LimeTest(2); $application = new Application(); // ->execute() $t->diag('->execute()'); $commandTester = new CommandTester($application->getCommand('list')); $commandTester->execute(array()); $t->like($commandTester->getDisplay(), '/help Displays help for a command/', '->execute() returns a list of available commands'); $commandTester->execute(array('--xml' => true)); $t->like($commandTester->getDisplay(), '/<command id="list" namespace="_global" name="list">/', '->execute() returns a list of available commands in XML if --xml is passed');
$t->is($commands['foo:bar'], $foo, '->addCommand() registers a command'); $application = new Application(); $application->addCommands(array($foo = new FooCommand(), $foo1 = new Foo1Command())); $commands = $application->getCommands(); $t->is(array($commands['foo:bar'], $commands['foo:bar1']), array($foo, $foo1), '->addCommands() registers an array of commands'); // ->hasCommand() ->getCommand() $t->diag('->hasCommand() ->getCommand()'); $application = new Application(); $t->ok($application->hasCommand('list'), '->hasCommand() returns true if a named command is registered'); $t->ok(!$application->hasCommand('afoobar'), '->hasCommand() returns false if a named command is not registered'); $application->addCommand($foo = new FooCommand()); $t->ok($application->hasCommand('afoobar'), '->hasCommand() returns true if an alias is registered'); $t->is($application->getCommand('foo:bar'), $foo, '->getCommand() returns a command by name'); $t->is($application->getCommand('afoobar'), $foo, '->getCommand() returns a command by alias'); try { $application->getCommand('foofoo'); $t->fail('->getCommand() throws an \InvalidArgumentException if the command does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getCommand() throws an \InvalidArgumentException if the command does not exist'); } class TestApplication extends Application { public function setWantHelps()