Exemplo n.º 1
0
 public function testAddArgument()
 {
     $this->initializeArguments();
     $definition = new InputDefinition();
     $definition->addArgument($this->foo);
     $this->assertEquals($definition->getArguments(), array('foo' => $this->foo), '->addArgument() adds a InputArgument object');
     $definition->addArgument($this->bar);
     $this->assertEquals($definition->getArguments(), array('foo' => $this->foo, 'bar' => $this->bar), '->addArgument() adds a InputArgument object');
     // arguments must have different names
     try {
         $definition->addArgument($this->foo1);
         $this->fail('->addArgument() throws a Exception if another argument is already registered with the same name');
     } catch (\Exception $e) {
     }
     // cannot add a parameter after an array parameter
     $definition->addArgument(new InputArgument('fooarray', InputArgument::IS_ARRAY));
     try {
         $definition->addArgument(new InputArgument('anotherbar'));
         $this->fail('->addArgument() throws a Exception if there is an array parameter already registered');
     } catch (\Exception $e) {
     }
     // cannot add a required argument after an optional one
     $definition = new InputDefinition();
     $definition->addArgument($this->foo);
     try {
         $definition->addArgument($this->foo2);
         $this->fail('->addArgument() throws an exception if you try to add a required argument after an optional one');
     } catch (\Exception $e) {
     }
 }
Exemplo n.º 2
0
$t->is($definition->getArguments(), array('bar' => $bar), '->setArguments() clears all InputArgument objects');

// ->addArguments()
$t->diag('->addArguments()');
$definition = new InputDefinition();
$definition->addArguments(array($foo));
$t->is($definition->getArguments(), array('foo' => $foo), '->addArguments() adds an array of InputArgument objects');
$definition->addArguments(array($bar));
$t->is($definition->getArguments(), array('foo' => $foo, 'bar' => $bar), '->addArguments() does not clear existing InputArgument objects');

// ->addArgument()
$t->diag('->addArgument()');
$definition = new InputDefinition();
$definition->addArgument($foo);
$t->is($definition->getArguments(), array('foo' => $foo), '->addArgument() adds a InputArgument object');
$definition->addArgument($bar);
$t->is($definition->getArguments(), array('foo' => $foo, 'bar' => $bar), '->addArgument() adds a InputArgument object');

// arguments must have different names
try
{
  $definition->addArgument($foo1);
  $t->fail('->addArgument() throws a Exception if another argument is already registered with the same name');
}
catch (\Exception $e)
{
  $t->pass('->addArgument() throws a Exception if another argument is already registered with the same name');
}

// cannot add a parameter after an array parameter