public function testSetNameOverwritesPreviousName() { $this->config->setName('command'); $this->config->setName('changed'); $this->assertSame('changed', $this->config->getName()); }
private function validateCommandName(CommandConfig $config) { $name = $config->getName(); if (!$name) { throw CannotAddCommandException::nameEmpty(); } if ($this->commands->contains($name)) { throw CannotAddCommandException::nameExists($name); } }
/** * Creates a new command. * * @param CommandConfig $config The command configuration. * @param Application $application The console application. * @param Command $parentCommand The parent command. * * @throws LogicException If the name of the command configuration is not set. */ public function __construct(CommandConfig $config, Application $application = null, Command $parentCommand = null) { if (!$config->getName()) { throw new LogicException('The name of the command config must be set.'); } $this->name = $config->getName(); $this->shortName = $config instanceof OptionCommandConfig ? $config->getShortName() : null; $this->aliases = $config->getAliases(); $this->config = $config; $this->application = $application; $this->parentCommand = $parentCommand; $this->subCommands = new CommandCollection(); $this->namedSubCommands = new CommandCollection(); $this->defaultSubCommands = new CommandCollection(); $this->argsFormat = $config->buildArgsFormat($this->getBaseFormat()); $this->dispatcher = $application ? $application->getConfig()->getEventDispatcher() : null; foreach ($config->getSubCommandConfigs() as $subConfig) { $this->addSubCommand($subConfig); } }