<commit_before><?php
namespace Gears\Config;

class ParserTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @expectedException \Gears\Exceptions\FileNotReadableException
     */
    public function testfileNotReadable()
    {
        $config = new Parser('notarealfile.json');

        $this->assertNotInstanceOf('\\Gears\\Config\\Parser', $config);
    }

    /**
     * @expectedException \Gears\Exceptions\UnknownTypeException
     */
    public function testUnknownType()
    {
        $config = new Parser(__DIR__ . DIRECTORY_SEPARATOR . 'config.json', 'yaml');

        $this->assertNotInstanceOf('\\Gears\\Config\\Parser', $config);
    }

    /**
     * @dataProvider providerTestConfigFiles
     */
    public function testConfigFileParsing($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        foreach ($expectedArray as $name => $value) {
            $this->assertEquals($value, $config[$name]);
        }
    }

    /**
     * @dataProvider providerTestConfigFiles
     */
    public function testConfigFileIteration($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        foreach ($config as $name => $value) {
            $this->assertEquals($expectedArray[$name], $value);
        }
    }

    /**
     * @dataProvider providerTestConfigFiles
     */
    public function testConfigFileConvertToArray($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        $array = iterator_to_array($config);

        $this->assertInternalType('array', $array);

        $this->assertEquals($expectedArray, $array);
    }

    /**
     * @dataProvider providerTestConfigFiles
     */
    public function testConfigFileCounting($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        $this->assertEquals($expectedArray, iterator_to_array($config));
    }

    public function providerTestConfigFiles()
    {<commit_msg>Added 100% code coverage tests<commit_after><?php
namespace Gears\Config;

class ParserTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @expectedException \Gears\Exceptions\FileNotReadableException
     */
    public function testfileNotReadable()
    {
        $config = new Parser('notarealfile.json');

        $this->assertNotInstanceOf('\\Gears\\Config\\Parser', $config);
    }

    /**
     * @expectedException \Gears\Exceptions\UnknownTypeException
     */
    public function testUnknownType()
    {
        $config = new Parser(__DIR__ . DIRECTORY_SEPARATOR . 'config.json', 'yaml');

        $this->assertNotInstanceOf('\\Gears\\Config\\Parser', $config);
    }

    /**
     * @dataProvider providerTestConfigFiles
     */
    public function testConfigFileParsing($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        foreach ($expectedArray as $name => $value) {
            $this->assertTrue(isset($config[$name]));
            $this->assertEquals($value, $config[$name]);
        }
    }

    /**
     * @dataProvider providerTestConfigFiles
     */
    public function testConfigFileIteration($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        foreach ($config as $name => $value) {
            $this->assertEquals($expectedArray[$name], $value);
        }
    }

    /**
     * @dataProvider providerTestConfigFiles
     */
    public function testConfigFileConvertToArray($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        $array = iterator_to_array($config);

        $this->assertInternalType('array', $array);

        $this->assertEquals($expectedArray, $array);
    }

    /**
     * @dataProvider providerTestConfigFiles
     */
    public function testConfigFileCounting($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        $this->assertEquals(count($expectedArray), count($config));
    }
    
    /**
     * @dataProvider providerTestConfigFiles
     * @expectedException \Gears\Exceptions\ImmutableException
     */
    public function testConfigFileExceptionOnSet($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        $config[key($expectedArray)] = 'testingSetting';
    }
    
    /**
     * @dataProvider providerTestConfigFiles
     * @expectedException \Gears\Exceptions\ImmutableException
     */
    public function testConfigFileExceptionOnUnset($fileName, $fileType, $expectedArray)
    {
        $config = $this->makeConstructor($fileName, $fileType);

        unset($config[key($expectedArray)]);
    }

    public function providerTestConfigFiles()
    {
{'fraction_non_alphanumeric': 0.13393221723152307, 'fraction_numerical': 0.0006124948958758677, 'mean_word_length': 3.025472473294988, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '2342453', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1348, 'n_words': 222}