<commit_before><?php

/**
 * @group ContainerManipulator_SetWhitespaceAfterToken
 */
class PHP_Formatter_ContainerManipulator_SetWhitespaceAfterTokenTest extends PHPFormatterTestCase
{

    /**
     * @return array
     */
    public function manipulateProvider()
    {
        $data = array();

        $path = '/ContainerManipulator/SetWhitespaceAfterToken/';

        #0
        $data[] = array(
            $inputContainer = $this->getContainerFromFixture($path . 'input0'),
            $this->getContainerFromFixture($path . 'output0'),
            array(
                'tokens' => array($inputContainer[3]),
                'whitespace' => array(T_CONCAT_EQUAL => ' '),
            ),
            false
        );

        #1
        $data[] = array(
            $inputContainer = $this->getContainerFromFixture($path . 'input1'),
            $this->getContainerFromFixture($path . 'output1'),
            array(
                'tokens' => array($inputContainer[3]),
                'whitespace' => array(T_CONCAT_EQUAL => '  '),
            ),
            false
        );

        #2
        $data[] = array(
            $inputContainer = $this->getContainerFromFixture($path . 'input2'),
            $this->getContainerFromFixture($path . 'output2'),
            array(
                'tokens' => array($inputContainer[3]),
                'whitespace' => array(T_CONCAT_EQUAL => ''),
            ),
            false
        );

        #3
        $data[] = array(
            $inputContainer = $this->getContainerFromFixture($path . 'input3'),
            $this->getContainerFromFixture($path . 'output3'),
            array(
                'tokens' => array($inputContainer[3]),
                'whitespace' => array('=' => ' '),
            ),
            false
        );

        return $data;
    }

    /**
     * @dataProvider manipulateProvider
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken
     */
    public function testManipulate($container, $expectedContainer, $params, $strict)
    {
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        $manipulator->manipulate($container, $params);
        $this->assertTokenContainerMatch($expectedContainer, $container, $strict);
    }

    /**
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken::manipulate
     * @covers PHP_Formatter_Exception
     */
    public function testMissingWhitespaceThrowsException()
    {
        $container = PHP_Formatter_TokenContainer::createFromCode("<?php echo 'hellow world'; ?>");
        $params = array('tokens' => array($container[5], $container[6]));
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        try {
            $manipulator->manipulate($container, $params);
            $this->fail('Expected exception not thrown');
        } catch (PHP_Formatter_Exception $e) {
            $this->assertEquals("key 'whitespace' not found in \$params", $e->getMessage(), 'Wrong exception message');
        }
    }

    /**
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken::manipulate
     * @covers PHP_Formatter_Exception
     */
    public function testMissingTokensThrowsException()
    {
        $container = PHP_Formatter_TokenContainer::createFromCode("<?php echo 'hellow world'; ?>");
        $params = array('whitespace' => array(T_ECHO => 'blub'));
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        try {
            $manipulator->manipulate($container, $params);
            $this->fail('Expected exception not thrown');
        } catch (PHP_Formatter_Exception $e) {
            $this->assertEquals("key 'tokens' not found in \$params", $e->getMessage(), 'Wrong exception message');
        }
    }

    /**
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken::manipulate
     * @covers PHP_Formatter_Exception
     */
    public function testParamIsNotArrayThrowsException()
    {
        $container = PHP_Formatter_TokenContainer::createFromCode("<?php echo 'hellow world'; ?>");
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        try {
            $manipulator->manipulate($container);
            $this->fail('Expected exception not thrown');
        } catch (PHP_Formatter_Exception $e) {
            $this->assertEquals("invalid input \$params should be an array", $e->getMessage(), 'Wrong exception message');
        }
    }

    /**
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken::getWhitespaceForToken
     * @covers PHP_Formatter_Exception
     */
    public function testNonExistingTokenInWhitespaceListThrowsExceptionInGetWhitespaceForToken()
    {
        $container = PHP_Formatter_TokenContainer::createFromCode("<?php echo 'hellow world'; ?>");
        $params = array('tokens' => array($container[2], $container[3]), 'whitespace' => array(T_ECHO => 'blub'));
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        try {
            $manipulator->manipulate($container, $params);
            $this->fail('Expected exception not thrown');
        } catch (PHP_Formatter_Exception $e) {
            $this->assertEquals('No option found for: T_WHITESPACE (371)', $e->getMessage(), 'Wrong exception message');
        }
    }
}<commit_msg>Fixed Bug with different values of T_WHITESPACE under php 5.2 and 5.3<commit_after><?php

/**
 * @group ContainerManipulator_SetWhitespaceAfterToken
 */
class PHP_Formatter_ContainerManipulator_SetWhitespaceAfterTokenTest extends PHPFormatterTestCase
{

    /**
     * @return array
     */
    public function manipulateProvider()
    {
        $data = array();

        $path = '/ContainerManipulator/SetWhitespaceAfterToken/';

        #0
        $data[] = array(
            $inputContainer = $this->getContainerFromFixture($path . 'input0'),
            $this->getContainerFromFixture($path . 'output0'),
            array(
                'tokens' => array($inputContainer[3]),
                'whitespace' => array(T_CONCAT_EQUAL => ' '),
            ),
            false
        );

        #1
        $data[] = array(
            $inputContainer = $this->getContainerFromFixture($path . 'input1'),
            $this->getContainerFromFixture($path . 'output1'),
            array(
                'tokens' => array($inputContainer[3]),
                'whitespace' => array(T_CONCAT_EQUAL => '  '),
            ),
            false
        );

        #2
        $data[] = array(
            $inputContainer = $this->getContainerFromFixture($path . 'input2'),
            $this->getContainerFromFixture($path . 'output2'),
            array(
                'tokens' => array($inputContainer[3]),
                'whitespace' => array(T_CONCAT_EQUAL => ''),
            ),
            false
        );

        #3
        $data[] = array(
            $inputContainer = $this->getContainerFromFixture($path . 'input3'),
            $this->getContainerFromFixture($path . 'output3'),
            array(
                'tokens' => array($inputContainer[3]),
                'whitespace' => array('=' => ' '),
            ),
            false
        );

        return $data;
    }

    /**
     * @dataProvider manipulateProvider
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken
     */
    public function testManipulate($container, $expectedContainer, $params, $strict)
    {
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        $manipulator->manipulate($container, $params);
        $this->assertTokenContainerMatch($expectedContainer, $container, $strict);
    }

    /**
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken::manipulate
     * @covers PHP_Formatter_Exception
     */
    public function testMissingWhitespaceThrowsException()
    {
        $container = PHP_Formatter_TokenContainer::createFromCode("<?php echo 'hellow world'; ?>");
        $params = array('tokens' => array($container[5], $container[6]));
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        try {
            $manipulator->manipulate($container, $params);
            $this->fail('Expected exception not thrown');
        } catch (PHP_Formatter_Exception $e) {
            $this->assertEquals("key 'whitespace' not found in \$params", $e->getMessage(), 'Wrong exception message');
        }
    }

    /**
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken::manipulate
     * @covers PHP_Formatter_Exception
     */
    public function testMissingTokensThrowsException()
    {
        $container = PHP_Formatter_TokenContainer::createFromCode("<?php echo 'hellow world'; ?>");
        $params = array('whitespace' => array(T_ECHO => 'blub'));
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        try {
            $manipulator->manipulate($container, $params);
            $this->fail('Expected exception not thrown');
        } catch (PHP_Formatter_Exception $e) {
            $this->assertEquals("key 'tokens' not found in \$params", $e->getMessage(), 'Wrong exception message');
        }
    }

    /**
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken::manipulate
     * @covers PHP_Formatter_Exception
     */
    public function testParamIsNotArrayThrowsException()
    {
        $container = PHP_Formatter_TokenContainer::createFromCode("<?php echo 'hellow world'; ?>");
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        try {
            $manipulator->manipulate($container);
            $this->fail('Expected exception not thrown');
        } catch (PHP_Formatter_Exception $e) {
            $this->assertEquals("invalid input \$params should be an array", $e->getMessage(), 'Wrong exception message');
        }
    }

    /**
     * @covers PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken::getWhitespaceForToken
     * @covers PHP_Formatter_Exception
     */
    public function testNonExistingTokenInWhitespaceListThrowsExceptionInGetWhitespaceForToken()
    {
        $container = PHP_Formatter_TokenContainer::createFromCode("<?php echo 'hellow world'; ?>");
        $params = array('tokens' => array($container[2], $container[3]), 'whitespace' => array(T_ECHO => 'blub'));
        $manipulator = new PHP_Formatter_ContainerManipulator_SetWhitespaceAfterToken();
        try {
            $manipulator->manipulate($container, $params);
            $this->fail('Expected exception not thrown');
        } catch (PHP_Formatter_Exception $e) {
            $this->assertEquals('No option found for: T_WHITESPACE (' . T_WHITESPACE . ')', $e->getMessage(), 'Wrong exception message');
        }
    }
}
{'fraction_non_alphanumeric': 0.12615751352342533, 'fraction_numerical': 0.004309159255523975, 'mean_word_length': 2.710204081632653, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4825612', 'n_tokens_mistral': 3020, 'n_tokens_neox': 2967, 'n_words': 505}