use Symfony\Components\CLI\Input\Option; $t = new LimeTest(19); // __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'))));
$input = new ArrayInput(array('foo' => 'foo'), new Definition(array(new Argument('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 Definition(array(new Option('foo')))); $t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options'); $input = new ArrayInput(array('--foo' => 'bar'), new Definition(array(new Option('foo', 'f', Option::PARAMETER_OPTIONAL, '', 'default')))); $t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options with a default value'); $input = new ArrayInput(array('--foo' => null), new Definition(array(new Option('foo', 'f', Option::PARAMETER_OPTIONAL, '', 'default')))); $t->is($input->getOptions(), array('foo' => 'default'), '->parse() parses long options with a default value'); try { $input = new ArrayInput(array('--foo' => null), new Definition(array(new Option('foo', 'f', Option::PARAMETER_REQUIRED)))); $t->fail('->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value'); } catch (\RuntimeException $e) { $t->pass('->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value'); } try { $input = new ArrayInput(array('--foo' => 'foo'), new Definition()); $t->fail('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed'); } catch (\RuntimeException $e) { $t->pass('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed'); } $input = new ArrayInput(array('-f' => 'bar'), new Definition(array(new Option('foo', 'f')))); $t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses short options'); try { $input = new ArrayInput(array('-o' => 'foo'), new Definition()); $t->fail('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed'); } catch (\RuntimeException $e) { $t->pass('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed'); }