Chris@0: getProperty('tokenPairs'); Chris@0: $p->setAccessible(true); Chris@0: $this->assertEquals($tokens, $p->getValue($input), $message); Chris@0: } Chris@0: Chris@0: public function testInputOptionWithGivenString() Chris@0: { Chris@0: $definition = new InputDefinition(array( Chris@0: new InputOption('foo', null, InputOption::VALUE_REQUIRED), Chris@0: new CodeArgument('code', null, InputOption::VALUE_REQUIRED), Chris@0: )); Chris@0: Chris@0: $input = new ShellInput('--foo=bar echo "baz\n";'); Chris@0: $input->bind($definition); Chris@0: $this->assertEquals('bar', $input->getOption('foo')); Chris@0: $this->assertEquals('echo "baz\n";', $input->getArgument('code')); Chris@0: } Chris@0: Chris@0: public function testInputOptionWithoutCodeArguments() Chris@0: { Chris@0: $definition = new InputDefinition(array( Chris@0: new InputOption('foo', null, InputOption::VALUE_REQUIRED), Chris@0: new InputArgument('bar', null, InputOption::VALUE_REQUIRED), Chris@0: new InputArgument('baz', null, InputOption::VALUE_REQUIRED), Chris@0: )); Chris@0: Chris@0: $input = new ShellInput('--foo=foo bar "baz\n"'); Chris@0: $input->bind($definition); Chris@0: $this->assertEquals('foo', $input->getOption('foo')); Chris@0: $this->assertEquals('bar', $input->getArgument('bar')); Chris@0: $this->assertEquals("baz\n", $input->getArgument('baz')); Chris@0: } Chris@0: Chris@0: public function getTokenizeData() Chris@0: { Chris@0: // Test all the cases from StringInput test, ensuring they have an appropriate $rest token. Chris@0: return array( Chris@0: array( Chris@0: '', Chris@0: array(), Chris@0: '->tokenize() parses an empty string', Chris@0: ), Chris@0: array( Chris@0: 'foo', Chris@0: array(array('foo', 'foo')), Chris@0: '->tokenize() parses arguments', Chris@0: ), Chris@0: array( Chris@0: ' foo bar ', Chris@0: array(array('foo', 'foo bar '), array('bar', 'bar ')), Chris@0: '->tokenize() ignores whitespaces between arguments', Chris@0: ), Chris@0: array( Chris@0: '"quoted"', Chris@0: array(array('quoted', '"quoted"')), Chris@0: '->tokenize() parses quoted arguments', Chris@0: ), Chris@0: array( Chris@0: "'quoted'", Chris@0: array(array('quoted', "'quoted'")), Chris@0: '->tokenize() parses quoted arguments', Chris@0: ), Chris@0: array( Chris@0: "'a\rb\nc\td'", Chris@0: array(array("a\rb\nc\td", "'a\rb\nc\td'")), Chris@0: '->tokenize() parses whitespace chars in strings', Chris@0: ), Chris@0: array( Chris@0: "'a'\r'b'\n'c'\t'd'", Chris@0: array( Chris@0: array('a', "'a'\r'b'\n'c'\t'd'"), Chris@0: array('b', "'b'\n'c'\t'd'"), Chris@0: array('c', "'c'\t'd'"), Chris@0: array('d', "'d'"), Chris@0: ), Chris@0: '->tokenize() parses whitespace chars between args as spaces', Chris@0: ), Chris@0: array( Chris@0: '\"quoted\"', Chris@0: array(array('"quoted"', '\"quoted\"')), Chris@0: '->tokenize() parses escaped-quoted arguments', Chris@0: ), Chris@0: array( Chris@0: "\'quoted\'", Chris@0: array(array('\'quoted\'', "\'quoted\'")), Chris@0: '->tokenize() parses escaped-quoted arguments', Chris@0: ), Chris@0: array( Chris@0: '-a', Chris@0: array(array('-a', '-a')), Chris@0: '->tokenize() parses short options', Chris@0: ), Chris@0: array( Chris@0: '-azc', Chris@0: array(array('-azc', '-azc')), Chris@0: '->tokenize() parses aggregated short options', Chris@0: ), Chris@0: array( Chris@0: '-awithavalue', Chris@0: array(array('-awithavalue', '-awithavalue')), Chris@0: '->tokenize() parses short options with a value', Chris@0: ), Chris@0: array( Chris@0: '-a"foo bar"', Chris@0: array(array('-afoo bar', '-a"foo bar"')), Chris@0: '->tokenize() parses short options with a value', Chris@0: ), Chris@0: array( Chris@0: '-a"foo bar""foo bar"', Chris@0: array(array('-afoo barfoo bar', '-a"foo bar""foo bar"')), Chris@0: '->tokenize() parses short options with a value', Chris@0: ), Chris@0: array( Chris@0: '-a\'foo bar\'', Chris@0: array(array('-afoo bar', '-a\'foo bar\'')), Chris@0: '->tokenize() parses short options with a value', Chris@0: ), Chris@0: array( Chris@0: '-a\'foo bar\'\'foo bar\'', Chris@0: array(array('-afoo barfoo bar', '-a\'foo bar\'\'foo bar\'')), Chris@0: '->tokenize() parses short options with a value', Chris@0: ), Chris@0: array( Chris@0: '-a\'foo bar\'"foo bar"', Chris@0: array(array('-afoo barfoo bar', '-a\'foo bar\'"foo bar"')), Chris@0: '->tokenize() parses short options with a value', Chris@0: ), Chris@0: array( Chris@0: '--long-option', Chris@0: array(array('--long-option', '--long-option')), Chris@0: '->tokenize() parses long options', Chris@0: ), Chris@0: array( Chris@0: '--long-option=foo', Chris@0: array(array('--long-option=foo', '--long-option=foo')), Chris@0: '->tokenize() parses long options with a value', Chris@0: ), Chris@0: array( Chris@0: '--long-option="foo bar"', Chris@0: array(array('--long-option=foo bar', '--long-option="foo bar"')), Chris@0: '->tokenize() parses long options with a value', Chris@0: ), Chris@0: array( Chris@0: '--long-option="foo bar""another"', Chris@0: array(array('--long-option=foo baranother', '--long-option="foo bar""another"')), Chris@0: '->tokenize() parses long options with a value', Chris@0: ), Chris@0: array( Chris@0: '--long-option=\'foo bar\'', Chris@0: array(array('--long-option=foo bar', '--long-option=\'foo bar\'')), Chris@0: '->tokenize() parses long options with a value', Chris@0: ), Chris@0: array( Chris@0: "--long-option='foo bar''another'", Chris@0: array(array('--long-option=foo baranother', "--long-option='foo bar''another'")), Chris@0: '->tokenize() parses long options with a value', Chris@0: ), Chris@0: array( Chris@0: "--long-option='foo bar'\"another\"", Chris@0: array(array('--long-option=foo baranother', "--long-option='foo bar'\"another\"")), Chris@0: '->tokenize() parses long options with a value', Chris@0: ), Chris@0: array( Chris@0: 'foo -a -ffoo --long bar', Chris@0: array( Chris@0: array('foo', 'foo -a -ffoo --long bar'), Chris@0: array('-a', '-a -ffoo --long bar'), Chris@0: array('-ffoo', '-ffoo --long bar'), Chris@0: array('--long', '--long bar'), Chris@0: array('bar', 'bar'), Chris@0: ), Chris@0: '->tokenize() parses when several arguments and options', Chris@0: ), Chris@0: ); Chris@0: } Chris@0: }