Yosymfony\Spress\Plugin\CommandDefinition::addArgument PHP Method

addArgument() public method

Adds a new command argument.
public addArgument ( string $name, integer $mode = null, string $description = '', mixed $default = null )
$name string The argument name
$mode integer The argument mode: self::REQUIRED or self::OPTIONAL
$description string A description text
$default mixed The default value (for self::OPTIONAL mode only)
    public function addArgument($name, $mode = null, $description = '', $default = null)
    {
        if (null === $mode) {
            $mode = self::OPTIONAL;
        } elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
            throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
        }
        $this->arguments[] = [$name, $mode, $description, $default];
    }

Usage Example

コード例 #1
0
 public function testBuildCommands()
 {
     $definition = new CommandDefinition('self-update');
     $definition->setDescription('Update spress.phar to the latest version.');
     $definition->setHelp('The self-update command replace your spress.phar by the latest version.');
     $definition->addOption('all');
     $definition->addArgument('dir');
     $input = $this->getMockBuilder('\\Symfony\\Component\\Console\\Input\\InputInterface')->getMock();
     $input->expects($this->once())->method('getArguments')->will($this->returnValue([]));
     $input->expects($this->once())->method('getOptions')->will($this->returnValue([]));
     $output = $this->getMockBuilder('\\Symfony\\Component\\Console\\Output\\OutputInterface')->getMock();
     $commandPluginMock = $this->getMockBuilder('\\Yosymfony\\Spress\\Plugin\\CommandPlugin')->getMock();
     $commandPluginMock->expects($this->once())->method('getCommandDefinition')->will($this->returnValue($definition));
     $commandPluginMock->expects($this->once())->method('executeCommand');
     $pm = new PluginManager(new EventDispatcher());
     $pm->addPlugin('emptyCommandPlugin', $commandPluginMock);
     $builder = new ConsoleCommandBuilder($pm);
     $symfonyConsoleCommands = $builder->buildCommands();
     $this->assertTrue(is_array($symfonyConsoleCommands));
     $this->assertCount(1, $symfonyConsoleCommands);
     $this->assertContainsOnlyInstancesOf('Symfony\\Component\\Console\\Command\\Command', $symfonyConsoleCommands);
     $symfonyConsoleCommand = $symfonyConsoleCommands[0];
     $this->assertCount(1, $symfonyConsoleCommand->getDefinition()->getOptions());
     $this->assertCount(1, $symfonyConsoleCommand->getDefinition()->getArguments());
     $this->assertEquals('Update spress.phar to the latest version.', $symfonyConsoleCommand->getDescription());
     $this->assertEquals('The self-update command replace your spress.phar by the latest version.', $symfonyConsoleCommand->getHelp());
     $symfonyConsoleCommand->run($input, $output);
 }
All Usage Examples Of Yosymfony\Spress\Plugin\CommandDefinition::addArgument