12 namespace Symfony\Component\Console\Tests\Input;
23 $_SERVER[
'argv'] = array(
'cli.php',
'foo');
25 $r = new \ReflectionObject($input);
26 $p = $r->getProperty(
'tokens');
27 $p->setAccessible(
true);
29 $this->assertEquals(array(
'foo'), $p->getValue($input),
'__construct() automatically get its input from the argv server variable');
34 $input =
new ArgvInput(array(
'cli.php',
'foo'));
36 $this->assertEquals(array(
'name' =>
'foo'), $input->getArguments(),
'->parse() parses required arguments');
39 $this->assertEquals(array(
'name' =>
'foo'), $input->getArguments(),
'->parse() is stateless');
50 $this->assertEquals($expectedOptions, $input->getOptions(), $message);
57 array(
'cli.php',
'--foo'),
60 '->parse() parses long options without a value',
63 array(
'cli.php',
'--foo=bar'),
65 array(
'foo' =>
'bar'),
66 '->parse() parses long options with a required value (with a = separator)',
69 array(
'cli.php',
'--foo',
'bar'),
71 array(
'foo' =>
'bar'),
72 '->parse() parses long options with a required value (with a space separator)',
75 array(
'cli.php',
'-f'),
78 '->parse() parses short options without a value',
81 array(
'cli.php',
'-fbar'),
83 array(
'foo' =>
'bar'),
84 '->parse() parses short options with a required value (with no separator)',
87 array(
'cli.php',
'-f',
'bar'),
89 array(
'foo' =>
'bar'),
90 '->parse() parses short options with a required value (with a space separator)',
93 array(
'cli.php',
'-f',
''),
96 '->parse() parses short options with an optional empty value',
99 array(
'cli.php',
'-f',
'',
'foo'),
102 '->parse() parses short options with an optional empty value followed by an argument',
105 array(
'cli.php',
'-f',
'',
'-b'),
107 array(
'foo' =>
'',
'bar' =>
true),
108 '->parse() parses short options with an optional empty value followed by an option',
111 array(
'cli.php',
'-f',
'-b',
'foo'),
113 array(
'foo' => null,
'bar' =>
true),
114 '->parse() parses short options with an optional value which is not present',
117 array(
'cli.php',
'-fb'),
119 array(
'foo' =>
true,
'bar' =>
true),
120 '->parse() parses short options when they are aggregated as a single one',
123 array(
'cli.php',
'-fb',
'bar'),
125 array(
'foo' =>
true,
'bar' =>
'bar'),
126 '->parse() parses short options when they are aggregated as a single one and the last one has a required value',
129 array(
'cli.php',
'-fb',
'bar'),
131 array(
'foo' =>
true,
'bar' =>
'bar'),
132 '->parse() parses short options when they are aggregated as a single one and the last one has an optional value',
135 array(
'cli.php',
'-fbbar'),
137 array(
'foo' =>
true,
'bar' =>
'bar'),
138 '->parse() parses short options when they are aggregated as a single one and the last one has an optional value with no separator',
141 array(
'cli.php',
'-fbbar'),
143 array(
'foo' =>
'bbar',
'bar' => null),
144 '->parse() parses short options when they are aggregated as a single one and one of them takes a value',
154 $this->setExpectedException(
'RuntimeException', $expectedExceptionMessage);
157 $input->bind($definition);
164 array(
'cli.php',
'--foo'),
166 'The "--foo" option requires a value.',
169 array(
'cli.php',
'-f'),
171 'The "--foo" option requires a value.',
174 array(
'cli.php',
'-ffoo'),
176 'The "-o" option does not exist.',
179 array(
'cli.php',
'--foo=bar'),
181 'The "--foo" option does not accept a value.',
184 array(
'cli.php',
'foo',
'bar'),
186 'Too many arguments.',
189 array(
'cli.php',
'--foo'),
191 'The "--foo" option does not exist.',
194 array(
'cli.php',
'-f'),
196 'The "-f" option does not exist.',
199 array(
'cli.php',
'-1'),
201 'The "-1" option does not exist.',
208 $input =
new ArgvInput(array(
'cli.php',
'foo',
'bar',
'baz',
'bat'));
211 $this->assertEquals(array(
'name' => array(
'foo',
'bar',
'baz',
'bat')), $input->getArguments(),
'->parse() parses array arguments');
216 $input =
new ArgvInput(array(
'cli.php',
'--name=foo',
'--name=bar',
'--name=baz'));
219 $this->assertEquals(array(
'name' => array(
'foo',
'bar',
'baz')), $input->getOptions(),
'->parse() parses array options ("--option=value" syntax)');
221 $input =
new ArgvInput(array(
'cli.php',
'--name',
'foo',
'--name',
'bar',
'--name',
'baz'));
223 $this->assertEquals(array(
'name' => array(
'foo',
'bar',
'baz')), $input->getOptions(),
'->parse() parses array options ("--option value" syntax)');
225 $input =
new ArgvInput(array(
'cli.php',
'--name=foo',
'--name=bar',
'--name='));
227 $this->assertSame(array(
'name' => array(
'foo',
'bar', null)), $input->getOptions(),
'->parse() parses empty array options as null ("--option=value" syntax)');
229 $input =
new ArgvInput(array(
'cli.php',
'--name',
'foo',
'--name',
'bar',
'--name',
'--anotherOption'));
234 $this->assertSame(array(
'name' => array(
'foo',
'bar', null),
'anotherOption' =>
true), $input->getOptions(),
'->parse() parses empty array options as null ("--option value" syntax)');
239 $input =
new ArgvInput(array(
'cli.php',
'--',
'-1'));
241 $this->assertEquals(array(
'number' =>
'-1'), $input->getArguments(),
'->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');
243 $input =
new ArgvInput(array(
'cli.php',
'-f',
'bar',
'--',
'-1'));
245 $this->assertEquals(array(
'foo' =>
'bar'), $input->getOptions(),
'->parse() parses arguments with leading dashes as options before having encountered a double-dash sequence');
246 $this->assertEquals(array(
'number' =>
'-1'), $input->getArguments(),
'->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');
251 $input =
new ArgvInput(array(
'cli.php',
'-f',
'bar',
''));
254 $this->assertEquals(array(
'empty' =>
''), $input->getArguments(),
'->parse() parses empty string arguments');
259 $input =
new ArgvInput(array(
'cli.php',
'-fbbar'));
260 $this->assertNull($input->getFirstArgument(),
'->getFirstArgument() returns null when there is no arguments');
262 $input =
new ArgvInput(array(
'cli.php',
'-fbbar',
'foo'));
263 $this->assertEquals(
'foo', $input->getFirstArgument(),
'->getFirstArgument() returns the first argument from the raw input');
268 $input =
new ArgvInput(array(
'cli.php',
'-f',
'foo'));
269 $this->assertTrue($input->hasParameterOption(
'-f'),
'->hasParameterOption() returns true if the given short option is in the raw input');
271 $input =
new ArgvInput(array(
'cli.php',
'--foo',
'foo'));
272 $this->assertTrue($input->hasParameterOption(
'--foo'),
'->hasParameterOption() returns true if the given short option is in the raw input');
274 $input =
new ArgvInput(array(
'cli.php',
'foo'));
275 $this->assertFalse($input->hasParameterOption(
'--foo'),
'->hasParameterOption() returns false if the given short option is not in the raw input');
277 $input =
new ArgvInput(array(
'cli.php',
'--foo=bar'));
278 $this->assertTrue($input->hasParameterOption(
'--foo'),
'->hasParameterOption() returns true if the given option with provided value is in the raw input');
283 $input =
new ArgvInput(array(
'cli.php',
'-f',
'foo'));
284 $this->assertEquals(
'-f foo', (
string) $input);
286 $input =
new ArgvInput(array(
'cli.php',
'-f',
'--bar=foo',
'a b c d',
"A\nB'C"));
287 $this->assertEquals(
'-f --bar=foo '.escapeshellarg(
'a b c d').
' '.escapeshellarg(
"A\nB'C"), (
string) $input);
296 $this->assertEquals($expected, $input->getParameterOption($key),
'->getParameterOption() returns the expected value');
302 array(array(
'app/console',
'foo:bar',
'-e',
'dev'),
'-e',
'dev'),
303 array(array(
'app/console',
'foo:bar',
'--env=dev'),
'--env',
'dev'),
304 array(array(
'app/console',
'foo:bar',
'-e',
'dev'), array(
'-e',
'--env'),
'dev'),
305 array(array(
'app/console',
'foo:bar',
'--env=dev'), array(
'-e',
'--env'),
'dev'),
306 array(array(
'app/console',
'foo:bar',
'--env=dev',
'--en=1'), array(
'--en'),
'1'),
307 array(array(
'app/console',
'foo:bar',
'--env=dev',
'',
'--en=1'), array(
'--en'),
'1'),
313 $input =
new ArgvInput(array(
'cli.php',
'-'));
315 $this->assertEquals(array(
'file' =>
'-'), $input->getArguments(),
'->parse() parses single dash as an argument');