Ejemplo 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());
     }
 }
Ejemplo n.º 2
0
 public function testParse()
 {
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals($input->getArguments(), array('name' => 'foo'), '->parse() parses required arguments');
     try {
         $input = new ArrayInput(array('foo' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
         $this->fail('->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed');
     } catch (\RuntimeException $e) {
     }
     $input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo'))));
     $this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options');
     $input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
     $this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options with a default value');
     $input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
     $this->assertEquals($input->getOptions(), array('foo' => 'default'), '->parse() parses long options with a default value');
     try {
         $input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
         $this->fail('->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value');
     } catch (\RuntimeException $e) {
     }
     try {
         $input = new ArrayInput(array('--foo' => 'foo'), new InputDefinition());
         $this->fail('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     } catch (\RuntimeException $e) {
     }
     $input = new ArrayInput(array('-f' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f'))));
     $this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses short options');
     try {
         $input = new ArrayInput(array('-o' => 'foo'), new InputDefinition());
         $this->fail('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     } catch (\RuntimeException $e) {
     }
 }
Ejemplo n.º 3
0
 public function testParse()
 {
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments');
     try {
         $input = new ArrayInput(array('foo' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
         $this->fail('->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed');
         $this->assertEquals('The "foo" argument does not exist.', $e->getMessage(), '->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed');
     }
     $input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo'))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options');
     $input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a default value');
     $input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
     $this->assertEquals(array('foo' => 'default'), $input->getOptions(), '->parse() parses long options with a default value');
     try {
         $input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
         $this->fail('->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value');
         $this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value');
     }
     try {
         $input = new ArrayInput(array('--foo' => 'foo'), new InputDefinition());
         $this->fail('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
         $this->assertEquals('The "--foo" option does not exist.', $e->getMessage(), '->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     }
     $input = new ArrayInput(array('-f' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f'))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options');
     try {
         $input = new ArrayInput(array('-o' => 'foo'), new InputDefinition());
         $this->fail('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
         $this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     }
 }
Ejemplo n.º 4
0
{
  $t->pass('->getOption() throws a \InvalidArgumentException if the option does not exist');
}

// ->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');
Ejemplo n.º 5
0
$input = new ArrayInput(array('--foo' => 'bar', 'name' => 'Fabien'));
$t->is($input->getFirstArgument(), 'Fabien', '->getFirstArgument() returns the first passed argument');

// ->hasParameterOption()
$t->diag('->hasParameterOption()');
$input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar'));
$t->ok($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
$t->ok(!$input->hasParameterOption('--bar'), '->hasParameterOption() returns false if an option is not present in the passed parameters');

$input = new ArrayInput(array('--foo'));
$t->ok($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');

// ->parse()
$t->diag('->parse()');
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
$t->is($input->getArguments(), array('name' => 'foo'), '->parse() parses required arguments');

try
{
  $input = new ArrayInput(array('foo' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
  $t->fail('->parse() throws an \InvalidArgumentException exception if an invalid argument is passed');
}
catch (\RuntimeException $e)
{
  $t->pass('->parse() throws an \InvalidArgumentException exception if an invalid argument is passed');
}

$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo'))));
$t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options');

$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL, '', 'default'))));