Example #1
0
// __construct()
$t->diag('__construct()');
$input = new ArrayInput(array('name' => 'foo'), new Definition(array(new Argument('name'))));
$t->is($input->getArgument('name'), 'foo', '->__construct() takes a Definition as an argument');
// ->getOption() ->setOption() ->getOptions()
$t->diag('->getOption() ->setOption() ->getOptions()');
$input = new ArrayInput(array('--name' => 'foo'), new Definition(array(new Option('name'))));
$t->is($input->getOption('name'), 'foo', '->getOption() returns the value for the given option');
$input->setOption('name', 'bar');
$t->is($input->getOption('name'), 'bar', '->setOption() sets the value for a given option');
$t->is($input->getOptions(), array('name' => 'bar'), '->getOptions() returns all option values');
$input = new ArrayInput(array('--name' => 'foo'), new Definition(array(new Option('name'), new Option('bar', '', Option::PARAMETER_OPTIONAL, '', 'default'))));
$t->is($input->getOption('bar'), 'default', '->getOption() returns the default value for optional options');
$t->is($input->getOptions(), array('name' => 'foo', 'bar' => 'default'), '->getOptions() returns all option values, even optional ones');
try {
    $input->setOption('foo', 'bar');
    $t->fail('->setOption() throws a \\InvalidArgumentException if the option does not exist');
} catch (\InvalidArgumentException $e) {
    $t->pass('->setOption() throws a \\InvalidArgumentException if the option does not exist');
}
try {
    $input->getOption('foo');
    $t->fail('->getOption() throws a \\InvalidArgumentException if the option does not exist');
} catch (\InvalidArgumentException $e) {
    $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 Definition(array(new Argument('name'))));
$t->is($input->getArgument('name'), 'foo', '->getArgument() returns the value for the given argument');
$input->setArgument('name', 'bar');