Exemplo n.º 1
0
 public function testArguments()
 {
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals('foo', $input->getArgument('name'), '->getArgument() returns the value for the given argument');
     $input->setArgument('name', 'bar');
     $this->assertEquals('bar', $input->getArgument('name'), '->setArgument() sets the value for a given argument');
     $this->assertEquals(array('name' => 'bar'), $input->getArguments(), '->getArguments() returns all argument values');
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
     $this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
     $this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
     try {
         $input->setArgument('foo', 'bar');
         $this->fail('->setArgument() throws a \\InvalidArgumentException if the argument does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->setOption() throws a \\InvalidArgumentException if the option does not exist');
         $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
     }
     try {
         $input->getArgument('foo');
         $this->fail('->getArgument() throws a \\InvalidArgumentException if the argument does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->setOption() throws a \\InvalidArgumentException if the option does not exist');
         $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
     }
 }
Exemplo n.º 2
0
// ->getArgument() ->setArgument() ->getArguments()
$t->diag('->getArgument() ->setArgument() ->getArguments()');
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
$t->is($input->getArgument('name'), 'foo', '->getArgument() returns the value for the given argument');

$input->setArgument('name', 'bar');
$t->is($input->getArgument('name'), 'bar', '->setArgument() sets the value for a given argument');
$t->is($input->getArguments(), array('name' => 'bar'), '->getArguments() returns all argument values');

$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
$t->is($input->getArgument('bar'), 'default', '->getArgument() returns the default value for optional arguments');
$t->is($input->getArguments(), array('name' => 'foo', 'bar' => 'default'), '->getArguments() returns all argument values, even optional ones');

try
{
  $input->setArgument('foo', 'bar');
  $t->fail('->setArgument() throws a \InvalidArgumentException if the argument does not exist');
}
catch (\InvalidArgumentException $e)
{
  $t->pass('->setArgument() throws a \InvalidArgumentException if the argument does not exist');
}

try
{
  $input->getArgument('foo');
  $t->fail('->getArgument() throws a \InvalidArgumentException if the argument does not exist');
}
catch (\InvalidArgumentException $e)
{
  $t->pass('->getArgument() throws a \InvalidArgumentException if the argument does not exist');