PHP Classes

File: Console/Tests/Input/StringInputTest.php

Recommend this page to a friend!
  Classes of Mukhamad Ikhsan   Redmine PHP Console Tools   Console/Tests/Input/StringInputTest.php   Download  
File: Console/Tests/Input/StringInputTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Redmine PHP Console Tools
Manage projects hosted in a Redmine installation
Author: By
Last change: Update of Console/Tests/Input/StringInputTest.php
Date: 4 months ago
Size: 3,405 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Tests\Input;

use
Symfony\Component\Console\Input\StringInput;

class
StringInputTest extends \PHPUnit_Framework_TestCase
{
   
/**
     * @dataProvider getTokenizeData
     */
   
public function testTokenize($input, $tokens, $message)
    {
       
$input = new StringInput($input);
       
$r = new \ReflectionClass('Symfony\Component\Console\Input\ArgvInput');
       
$p = $r->getProperty('tokens');
       
$p->setAccessible(true);
       
$this->assertEquals($tokens, $p->getValue($input), $message);
    }

    public function
getTokenizeData()
    {
        return array(
            array(
'', array(), '->tokenize() parses an empty string'),
            array(
'foo', array('foo'), '->tokenize() parses arguments'),
            array(
' foo bar ', array('foo', 'bar'), '->tokenize() ignores whitespaces between arguments'),
            array(
'"quoted"', array('quoted'), '->tokenize() parses quoted arguments'),
            array(
"'quoted'", array('quoted'), '->tokenize() parses quoted arguments'),
            array(
'\"quoted\"', array('"quoted"'), '->tokenize() parses escaped-quoted arguments'),
            array(
"\'quoted\'", array('\'quoted\''), '->tokenize() parses escaped-quoted arguments'),
            array(
'-a', array('-a'), '->tokenize() parses short options'),
            array(
'-azc', array('-azc'), '->tokenize() parses aggregated short options'),
            array(
'-awithavalue', array('-awithavalue'), '->tokenize() parses short options with a value'),
            array(
'-a"foo bar"', array('-afoo bar'), '->tokenize() parses short options with a value'),
            array(
'-a"foo bar""foo bar"', array('-afoo barfoo bar'), '->tokenize() parses short options with a value'),
            array(
'-a\'foo bar\'', array('-afoo bar'), '->tokenize() parses short options with a value'),
            array(
'-a\'foo bar\'\'foo bar\'', array('-afoo barfoo bar'), '->tokenize() parses short options with a value'),
            array(
'-a\'foo bar\'"foo bar"', array('-afoo barfoo bar'), '->tokenize() parses short options with a value'),
            array(
'--long-option', array('--long-option'), '->tokenize() parses long options'),
            array(
'--long-option=foo', array('--long-option=foo'), '->tokenize() parses long options with a value'),
            array(
'--long-option="foo bar"', array('--long-option=foo bar'), '->tokenize() parses long options with a value'),
            array(
'--long-option="foo bar""another"', array('--long-option=foo baranother'), '->tokenize() parses long options with a value'),
            array(
'--long-option=\'foo bar\'', array('--long-option=foo bar'), '->tokenize() parses long options with a value'),
            array(
"--long-option='foo bar''another'", array("--long-option=foo baranother"), '->tokenize() parses long options with a value'),
            array(
"--long-option='foo bar'\"another\"", array("--long-option=foo baranother"), '->tokenize() parses long options with a value'),
            array(
'foo -a -ffoo --long bar', array('foo', '-a', '-ffoo', '--long', 'bar'), '->tokenize() parses when several arguments and options'),
        );
    }
}