<commit_before><?php

/*
 * This file is part of the Yosymfony\Config-loader.
 *
 * (c) YoSymfony <http://github.com/yosymfony>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Yosymfony\ConfigLoader\Tests;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Yosymfony\ConfigLoader\Config;
use Yosymfony\ConfigLoader\Repository;
use Yosymfony\ConfigLoader\Loaders\TomlLoader;
use Yosymfony\ConfigLoader\Loaders\YamlLoader;
use Yosymfony\ConfigLoader\Loaders\JsonLoader;

class ConfigTest extends \PHPUnit_Framework_TestCase
{
    protected $config;

    public function setUp()
    {
        $locator = new FileLocator(array(__dir__.'/Fixtures'));

        $this->config = new Config(array(
            new TomlLoader($locator),
            new YamlLoader($locator),
            new JsonLoader($locator),
        ));
    }

    public function provideFileFormats()
    {
        return array(
            array('json'),
            array('toml'),
            array('yml')
        );
    }

    public function testJsonInline()
    {
        $repository = $this->config->load('{ "var": "my value" }', Config::TYPE_JSON);
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('var'), 'my value');
        $this->assertEquals($repository['var'], 'my value');
        $this->assertTrue(is_array($repository->getArray()));
    }

    public function testTomlInline()
    {
        $repository = $this->config->load('var = "my value"', Config::TYPE_TOML);
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('var'), 'my value');
        $this->assertEquals($repository['var'], 'my value');
        $this->assertEquals($repository->get('key_not_exist', 'default'), 'default');
        $this->assertTrue(is_array($repository->getArray()));
    }

    public function testYamlInline()
    {
        $repository = $this->config->load('var: "my value"', Config::TYPE_YAML);
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('var'), 'my value');
        $this->assertEquals($repository['var'], 'my value');
        $this->assertEquals($repository->get('key_not_exist', 'default'), 'default');
        $this->assertTrue(is_array($repository->getArray()));
    }

    public function testOnlyDistFile()
    {
        $repository = $this->config->load('config-server.yml');
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('port'), 80);
        $this->assertEquals($repository['port'], 80);
        $this->assertEquals($repository->get('host'), 'yourname.com');
        $this->assertEquals($repository['host'], 'yourname.com');
    }

    public function testLoadFileWithAbsolutePath()
    {
        $repository = $this->config->load(__dir__.'/Fixtures/config.yml');
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('port'), 25);
        $this->assertEquals($repository['port'], 25);
        $this->assertEquals($repository->get('server'), 'mail.yourname.com');
        $this->assertEquals($repository['server'], 'mail.yourname.com');
    }

    /**
     * @expectedException \RuntimeException
     */
    public function testJsonInlineFail()
    {
        $repository = $this->config->load('{ "var": "value"', Config::TYPE_TOML);
    }

    /**
     * @expectedException Yosymfony\Toml\Exception\ParseException
     */
    public function testTomlInlineFail()
    {
        $repository = $this->config->load('var = "my value', Config::TYPE_TOML);
    }

    /**
     * @expectedException Symfony\Component\Yaml\Exception\ParseException
     */
    public function testYamlInlineFail()
    {
        $repository = $this->config->load('var : [ elemnt', Config::TYPE_YAML);
    }

    /**<commit_msg>*fix type in testJsonInlineFail<commit_after><?php

/*
 * This file is part of the Yosymfony\Config-loader.
 *
 * (c) YoSymfony <http://github.com/yosymfony>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Yosymfony\ConfigLoader\Tests;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Yosymfony\ConfigLoader\Config;
use Yosymfony\ConfigLoader\Repository;
use Yosymfony\ConfigLoader\Loaders\TomlLoader;
use Yosymfony\ConfigLoader\Loaders\YamlLoader;
use Yosymfony\ConfigLoader\Loaders\JsonLoader;

class ConfigTest extends \PHPUnit_Framework_TestCase
{
    protected $config;

    public function setUp()
    {
        $locator = new FileLocator(array(__dir__.'/Fixtures'));

        $this->config = new Config(array(
            new TomlLoader($locator),
            new YamlLoader($locator),
            new JsonLoader($locator),
        ));
    }

    public function provideFileFormats()
    {
        return array(
            array('json'),
            array('toml'),
            array('yml')
        );
    }

    public function testJsonInline()
    {
        $repository = $this->config->load('{ "var": "my value" }', Config::TYPE_JSON);
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('var'), 'my value');
        $this->assertEquals($repository['var'], 'my value');
        $this->assertTrue(is_array($repository->getArray()));
    }

    public function testTomlInline()
    {
        $repository = $this->config->load('var = "my value"', Config::TYPE_TOML);
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('var'), 'my value');
        $this->assertEquals($repository['var'], 'my value');
        $this->assertEquals($repository->get('key_not_exist', 'default'), 'default');
        $this->assertTrue(is_array($repository->getArray()));
    }

    public function testYamlInline()
    {
        $repository = $this->config->load('var: "my value"', Config::TYPE_YAML);
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('var'), 'my value');
        $this->assertEquals($repository['var'], 'my value');
        $this->assertEquals($repository->get('key_not_exist', 'default'), 'default');
        $this->assertTrue(is_array($repository->getArray()));
    }

    public function testOnlyDistFile()
    {
        $repository = $this->config->load('config-server.yml');
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('port'), 80);
        $this->assertEquals($repository['port'], 80);
        $this->assertEquals($repository->get('host'), 'yourname.com');
        $this->assertEquals($repository['host'], 'yourname.com');
    }

    public function testLoadFileWithAbsolutePath()
    {
        $repository = $this->config->load(__dir__.'/Fixtures/config.yml');
        $this->assertNotNull($repository);
        $this->assertEquals($repository->get('port'), 25);
        $this->assertEquals($repository['port'], 25);
        $this->assertEquals($repository->get('server'), 'mail.yourname.com');
        $this->assertEquals($repository['server'], 'mail.yourname.com');
    }

    /**
     * @expectedException \RuntimeException
     */
    public function testJsonInlineFail()
    {
        $repository = $this->config->load('{ "var": "value"', Config::TYPE_JSON);
    }

    /**
     * @expectedException Yosymfony\Toml\Exception\ParseException
     */
    public function testTomlInlineFail()
    {
        $repository = $this->config->load('var = "my value', Config::TYPE_TOML);
    }

    /**
     * @expectedException Symfony\Component\Yaml\Exception\ParseException
     */
    public function testYamlInlineFail()
    {
        $repository = $this->config->load('var : [ elemnt', Config::TYPE_YAML);
    }

    /**
{'fraction_non_alphanumeric': 0.16362043064596896, 'fraction_numerical': 0.00200300450676014, 'mean_word_length': 3.309061488673139, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 111, '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': '4585826', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2252, 'n_words': 381}