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; }