$this->assertEquals(array(), $definition->getArguments(), '__construct() creates a new InputDefinition object');
$definition = new InputDefinition(array($this->foo, $this->bar));
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '__construct() takes an array of InputArgument objects as its first argument');
}
public function testConstructorOptions()
{
$this->initializeOptions();
$definition = new InputDefinition();
$this->assertEquals(array(), $definition->getOptions(), '__construct() creates a new InputDefinition object');
$definition = new InputDefinition(array($this->foo, $this->bar));
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '__construct() takes an array of InputOption objects as its first argument');
}
public function testSetArguments()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->setArguments(array($this->foo));
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->setArguments() sets the array of InputArgument objects');
$definition->setArguments(array($this->bar));
$this->assertEquals(array('bar' => $this->bar), $definition->getArguments(), '->setArguments() clears all InputArgument objects');
}
public function testAddArguments()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArguments(array($this->foo));
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->addArguments() adds an array of InputArgument objects');
$definition->addArguments(array($this->bar));
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '->addArguments() does not clear existing InputArgument objects');
}
public function testAddArgument()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArgument($this->foo);
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->addArgument() adds a InputArgument object');
* @expectedExceptionMessage Cannot add a required argument after an optional one.
*/
public function testRequiredArgumentCannotFollowAnOptionalOne()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArgument($this->foo);
$definition->addArgument($this->foo2);
}
public function testGetArgument()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArguments(array($this->foo));
$this->assertEquals($this->foo, $definition->getArgument('foo'), '->getArgument() returns a InputArgument by its name');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The "bar" argument does not exist.
*/
public function testGetInvalidArgument()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArguments(array($this->foo));
$definition->getArgument('bar');
}
public function testHasArgument()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArguments(array($this->foo));
$this->assertTrue($definition->hasArgument('foo'), '->hasArgument() returns true if a InputArgument exists for the given name');
$this->assertFalse($definition->hasArgument('bar'), '->hasArgument() returns false if a InputArgument exists for the given name');
}
public function testGetArgumentRequiredCount()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArgument($this->foo2);
$this->assertEquals(1, $definition->getArgumentRequiredCount(), '->getArgumentRequiredCount() returns the number of required arguments');
$definition->addArgument($this->foo);
$this->assertEquals(1, $definition->getArgumentRequiredCount(), '->getArgumentRequiredCount() returns the number of required arguments');
}
public function testGetArgumentCount()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArgument($this->foo2);
$this->assertEquals(1, $definition->getArgumentCount(), '->getArgumentCount() returns the number of arguments');
$definition->addArgument($this->foo);
$this->assertEquals(2, $definition->getArgumentCount(), '->getArgumentCount() returns the number of arguments');
}
public function testGetArgumentDefaults()
{
$definition = new InputDefinition(array(
new InputArgument('foo1', InputArgument::OPTIONAL),
new InputArgument('foo2', InputArgument::OPTIONAL, '', 'default'),
new InputArgument('foo3', InputArgument::OPTIONAL | InputArgument::IS_ARRAY),
// new InputArgument('foo4', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, '', array(1, 2)),
));
$this->assertEquals(array('foo1' => null, 'foo2' => 'default', 'foo3' => array()), $definition->getArgumentDefaults(), '->getArgumentDefaults() return the default values for each argument');
$definition = new InputDefinition(array(
new InputArgument('foo4', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, '', array(1, 2)),
));
$this->assertEquals(array('foo4' => array(1, 2)), $definition->getArgumentDefaults(), '->getArgumentDefaults() return the default values for each argument');
}
public function testSetOptions()
{
$this->initializeOptions();
$definition = new InputDefinition(array($this->foo));
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->setOptions() sets the array of InputOption objects');
$definition->setOptions(array($this->bar));
$this->assertEquals(array('bar' => $this->bar), $definition->getOptions(), '->setOptions() clears all InputOption objects');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The "-f" option does not exist.
*/
public function testSetOptionsClearsOptions()
{
$this->initializeOptions();
$definition = new InputDefinition(array($this->foo));
$definition->setOptions(array($this->bar));
$definition->getOptionForShortcut('f');
}
public function testAddOptions()
{
$this->initializeOptions();
$definition = new InputDefinition(array($this->foo));
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->addOptions() adds an array of InputOption objects');
$definition->addOptions(array($this->bar));
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '->addOptions() does not clear existing InputOption objects');
}
public function testAddOption()
{
$this->initializeOptions();
$definition = new InputDefinition();
$definition->addOption($this->foo);
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->addOption() adds a InputOption object');
array(new InputDefinition(array(new InputOption('foo'), new InputArgument('foo', InputArgument::REQUIRED))), '[--foo] [--] <foo>', 'puts [--] between options and arguments'),
);
}
public function testGetShortSynopsis()
{
$definition = new InputDefinition(array(new InputOption('foo'), new InputOption('bar'), new InputArgument('cat')));
$this->assertEquals('[options] [--] [<cat>]', $definition->getSynopsis(true), '->getSynopsis(true) groups options in [options]');
}
protected function initializeArguments()
{
$this->foo = new InputArgument('foo');
$this->bar = new InputArgument('bar');
$this->foo1 = new InputArgument('foo');
$this->foo2 = new InputArgument('foo2', InputArgument::REQUIRED);
}
protected function initializeOptions()
{
$this->foo = new InputOption('foo', 'f');
$this->bar = new InputOption('bar', 'b');
$this->foo1 = new InputOption('fooBis', 'f');
$this->foo2 = new InputOption('foo', 'p');
$this->multi = new InputOption('multi', 'm|mm|mmm');