<commit_before><?php

/*
 * This file is part of the PHP Serialization Helpers package.
 *
 * © <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE.md
 * file that was distributed with this source code.
 */

namespace Cs278\SerializationHelpers\Tests;

use Cs278\SerializationHelpers as serialization;

class SerializationTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider dataUnserializeInvalid
     * @expectedException Cs278\SerializationHelpers\Exception\SyntaxError
     */
    public function testUnserializeInvalid($input)
    {
        serialization\unserialize($input);
    }

    public function dataUnserializeInvalid()
    {
        return array(
            array('O:'),
        );
    }

    /**
     * @dataProvider dataUnserialize
     */
    public function testUnserialize($expected, $input)
    {
        $result = serialization\unserialize($input);

        if (is_object($expected)) {
            $this->assertEquals($expected, $result);
        } else {
            $this->assertSame($expected, $result);
        }
    }

    public function dataUnserialize()
    {
        return array(
            array(null, 'N;'),
            array(true, 'b:1;'),
            array('foo', 's:3:"foo";'),
            array((object) array('foo' => 'bar'), 'O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}'),
            array(array(1, 1, 2, 3), 'a:4:{i:0;i:1;i:1;R:2;i:2;i:2;i:3;i:3;}'),
            array(new TestStub(''), 'C:41:"Cs278\SerializationHelpers\Tests\TestStub":0:{}'),
            array(new TestStub('ROBOTS'), 'C:41:"Cs278\SerializationHelpers\Tests\TestStub":6:{ROBOTS}'),
        );
    }

    /**
     * @dataProvider dataIsSerialized<commit_msg>PHP will unserialize rubbish too<commit_after><?php

/*
 * This file is part of the PHP Serialization Helpers package.
 *
 * © <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE.md
 * file that was distributed with this source code.
 */

namespace Cs278\SerializationHelpers\Tests;

use Cs278\SerializationHelpers as serialization;

class SerializationTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider dataUnserializeInvalid
     * @expectedException Cs278\SerializationHelpers\Exception\SyntaxError
     */
    public function testUnserializeInvalid($input)
    {
        serialization\unserialize($input);
    }

    public function dataUnserializeInvalid()
    {
        return array(
            array('O:'),
        );
    }

    /**
     * @dataProvider dataUnserialize
     */
    public function testUnserialize($expected, $input)
    {
        $result = serialization\unserialize($input);

        if (is_object($expected)) {
            $this->assertEquals($expected, $result);
        } else {
            $this->assertSame($expected, $result);
        }
    }

    public function dataUnserialize()
    {
        return array(
            array(null, 'N;'),
            array(true, 'b:1;'),
            array('foo', 's:3:"foo";'),
            array((object) array('foo' => 'bar'), 'O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}'),
            array(array(1, 1, 2, 3), 'a:4:{i:0;i:1;i:1;R:2;i:2;i:2;i:3;i:3;}'),
            array(new TestStub(''), 'C:41:"Cs278\SerializationHelpers\Tests\TestStub":0:{}'),
            array(new TestStub('ROBOTS'), 'C:41:"Cs278\SerializationHelpers\Tests\TestStub":6:{ROBOTS}'),
            array('f', 's:1:"f"'), // PHP doesn't require the trailing semi colon
            array('f', 's:1:"f"GARBAG;E'), // PHP will even accept complete garbage
        );
    }

    /**
     * @dataProvider dataIsSerialized
{'fraction_non_alphanumeric': 0.15278922780983786, 'fraction_numerical': 0.022533663094256664, 'mean_word_length': 2.760330578512397, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 15, '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': '1968491', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1117, 'n_words': 220}