public function testConstructor() { $application = new Application(); try { $command = new Command(); $this->fail('__construct() throws a \\LogicException if the name is null'); } catch (\LogicException $e) { } $command = new Command('foo:bar'); $this->assertEquals($command->getFullName(), 'foo:bar', '__construct() takes the command name as its first argument'); }
public function testConstructor() { try { $command = new Command(); $this->fail('__construct() throws a \\LogicException if the name is null'); } catch (\Exception $e) { $this->assertInstanceOf('\\LogicException', $e, '__construct() throws a \\LogicException if the name is null'); $this->assertEquals('The command name cannot be empty.', $e->getMessage(), '__construct() throws a \\LogicException if the name is null'); } $command = new Command('foo:bar'); $this->assertEquals('foo:bar', $command->getFullName(), '__construct() takes the command name as its first argument'); }
/** * Adds a command object. * * If a command with the same name already exists, it will be overridden. * * @param Command $command A Command object * * @return Command The registered command */ public function addCommand(Command $command) { $command->setApplication($this); $this->commands[$command->getFullName()] = $command; foreach ($command->getAliases() as $alias) { $this->aliases[$alias] = $command; } return $command; }
$application = new Application(); // __construct() $t->diag('__construct()'); try { $command = new Command(); $t->fail('__construct() throws a \LogicException if the name is null'); } catch (\LogicException $e) { $t->pass('__construct() throws a \LogicException if the name is null'); } $command = new Command('foo:bar'); $t->is($command->getFullName(), 'foo:bar', '__construct() takes the command name as its first argument'); // ->setApplication() $t->diag('->setApplication()'); $command = new TestCommand(); $command->setApplication($application); $t->is($command->getApplication(), $application, '->setApplication() sets the current application'); // ->setDefinition() ->getDefinition() $t->diag('->setDefinition() ->getDefinition()'); $ret = $command->setDefinition($definition = new InputDefinition()); $t->is($ret, $command, '->setDefinition() implements a fluent interface'); $t->is($command->getDefinition(), $definition, '->setDefinition() sets the current InputDefinition instance'); $command->setDefinition(array(new InputArgument('foo'), new InputOption('bar'))); $t->ok($command->getDefinition()->hasArgument('foo'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument'); $t->ok($command->getDefinition()->hasOption('bar'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument');