Exemple #1
0
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\CLI\Input\ArrayInput;
use Symfony\Components\CLI\Input\Definition;
use Symfony\Components\CLI\Input\Argument;
use Symfony\Components\CLI\Input\Option;
$t = new LimeTest(15);
// ->getFirstArgument()
$t->diag('->getFirstArgument()');
$input = new ArrayInput(array());
$t->is($input->getFirstArgument(), null, '->getFirstArgument() returns null if no argument were passed');
$input = new ArrayInput(array('name' => 'Fabien'));
$t->is($input->getFirstArgument(), 'Fabien', '->getFirstArgument() returns the first passed argument');
$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 Definition(array(new Argument('name'))));
$t->is($input->getArguments(), array('name' => 'foo'), '->parse() parses required arguments');
try {
    $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) {