本文整理匯總了PHP中Symfony\Component\Console\Input\ArrayInput::getArguments方法的典型用法代碼示例。如果您正苦於以下問題:PHP ArrayInput::getArguments方法的具體用法?PHP ArrayInput::getArguments怎麽用?PHP ArrayInput::getArguments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Console\Input\ArrayInput
的用法示例。
在下文中一共展示了ArrayInput::getArguments方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testArguments
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());
}
}
示例2: testArguments
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');
}
示例3: testParse
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::VALUE_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::VALUE_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::VALUE_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');
}
}
示例4: testParseArguments
public function testParseArguments()
{
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
$this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments');
}