Webmozart\Console\Api\Config\OptionCommandConfig::setName PHP Method

setName() public method

Contrary to the base implementation, the name of an option command must contain at least two characters.
public setName ( string $name ) : static
$name string The name of the command.
return static The current instance.
    public function setName($name)
    {
        if (null !== $name) {
            Assert::string($name, 'The command name must be a string or null. Got: %s');
            Assert::notEmpty($name, 'The command name must not be empty.');
            Assert::greaterThan(strlen($name), 1, sprintf('The command name should contain at least two characters. Got: "%s"', $name));
        }
        parent::setName($name);
        return $this;
    }

Usage Example

 public function testBuildAnonymousArgsFormat()
 {
     $baseFormat = new ArgsFormat();
     $this->config->setName('command');
     $this->config->setShortName('c');
     $this->config->setAliases(array('alias1', 'alias2'));
     $this->config->addOption('option');
     $this->config->addArgument('argument');
     $this->config->markAnonymous();
     $expected = ArgsFormat::build($baseFormat)->addArgument(new Argument('argument'))->addOption(new Option('option'))->getFormat();
     $this->assertEquals($expected, $this->config->buildArgsFormat($baseFormat));
 }