<commit_before><?php

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

namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Configuration;
use Symfony\Component\Yaml\Yaml;

use Symfony\Component\Config\Definition\Processor;

class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
    public function testDefaults()
    {
        $processor = new Processor();
        $configuration = new Configuration();
        $options = $processor->process($configuration->getConfigTree(), array());

        $defaults = array(
            'auto_generate_hydrator_classes'    => false,
            'auto_generate_proxy_classes'       => false,
            'default_document_manager'          => 'default',
            'default_database'                  => 'default',
            'mappings'                          => array(),
            'document_managers'                 => array(),
            'default_connection'                => 'default',
            'server'                            => null,
            'options'                           => array(),
            'connections'                       => array(),
            'proxy_namespace'                   => 'Proxies',
            'hydrator_namespace'                => 'Hydrators',
        );

        foreach ($defaults as $key => $default) {
            $this->assertTrue(array_key_exists($key, $options), sprintf('The default "%s" exists', $key));
            $this->assertEquals($default, $options[$key]);

            unset($options[$key]);
        }

        if (count($options)) {
            $this->fail('Extra defaults were returned: '. print_r($options, true));
        }
    }

    /**
     * Tests a full configuration.
     *
     * @dataProvider fullConfigurationProvider
     */
    public function testFullConfiguration($config)
    {
        $processor = new Processor();
        $configuration = new Configuration();
        $options = $processor->process($configuration->getConfigTree(), array($config));

        $expected = array(
            'proxy_namespace'                   => 'Test_Proxies',
            'auto_generate_proxy_classes'       => true,
            'hydrator_namespace'                => 'Test_Hydrators',
            'auto_generate_hydrator_classes'    => true,
            'default_document_manager'          => 'default_dm_name',
            'default_database'                  => 'default_db_name',
            'metadata_cache_driver' => array(
                'type'      => 'memcache',
                'class'     => 'fooClass',
                'host'      => 'host_val',
                'port'      => 1234,
                'instance_class' => 'instance_val',
            ),
            'default_connection'                => 'conn1',
            'server'                            => 'http://server',
            'options'       => array(
                'connect'   => true,
                'persist'   => 'persist_val',
                'timeout'   => 500,
                'replicaSet' => true,
                'username'  => 'username_val',
                'password'  => '<PASSWORD>',
            ),
            'connections'   => array(
                'conn1'         => array(
                    'server'    => null,
                    'options'   => array(),
                ),
                'conn2'         => array(
                    'server'    => 'http://server2',
                    'options'   => array(),
                ),
            ),
            'mappings'      => array(
                'FooBundle'     => array(
                    'type' => 'annotations',
                ),
            ),
            'document_managers' => array(
                'dm1' => array(
                    'mappings' => array(),
                ),
                'dm2' => array(
                    'default_database' => 'dm2_default_db',
                    'connection' => 'dm2_connection',
                    'database' => 'db1',
                    'mappings' => array(
                        'BarBundle' => array(
                            'type'      => 'yml',
                            'dir'       => '%kernel.cache_dir%',
                            'prefix'    => 'prefix_val',
                            'alias'     => 'alias_val',
                        )
                    ),
                    'metadata_cache_driver' => array(
                        'type' => 'apc',
                    )
                )
            )
        );

        //var_dump($options);

        $this->assertEquals($expected, $options);
    }

    public function fullConfigurationProvider()
    {
      $yaml = Yaml::load(__DIR__.'/Fixtures/config/yml/full.yml');
      $yaml = $yaml['doctrine_mongo_db'];

       return array(
           array($yaml),
       );<commit_msg>[DoctrineMongoDBBundle] Removing left-over debug code.<commit_after><?php

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

namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Configuration;
use Symfony\Component\Yaml\Yaml;

use Symfony\Component\Config\Definition\Processor;

class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
    public function testDefaults()
    {
        $processor = new Processor();
        $configuration = new Configuration();
        $options = $processor->process($configuration->getConfigTree(), array());

        $defaults = array(
            'auto_generate_hydrator_classes'    => false,
            'auto_generate_proxy_classes'       => false,
            'default_document_manager'          => 'default',
            'default_database'                  => 'default',
            'mappings'                          => array(),
            'document_managers'                 => array(),
            'default_connection'                => 'default',
            'server'                            => null,
            'options'                           => array(),
            'connections'                       => array(),
            'proxy_namespace'                   => 'Proxies',
            'hydrator_namespace'                => 'Hydrators',
        );

        foreach ($defaults as $key => $default) {
            $this->assertTrue(array_key_exists($key, $options), sprintf('The default "%s" exists', $key));
            $this->assertEquals($default, $options[$key]);

            unset($options[$key]);
        }

        if (count($options)) {
            $this->fail('Extra defaults were returned: '. print_r($options, true));
        }
    }

    /**
     * Tests a full configuration.
     *
     * @dataProvider fullConfigurationProvider
     */
    public function testFullConfiguration($config)
    {
        $processor = new Processor();
        $configuration = new Configuration();
        $options = $processor->process($configuration->getConfigTree(), array($config));

        $expected = array(
            'proxy_namespace'                   => 'Test_Proxies',
            'auto_generate_proxy_classes'       => true,
            'hydrator_namespace'                => 'Test_Hydrators',
            'auto_generate_hydrator_classes'    => true,
            'default_document_manager'          => 'default_dm_name',
            'default_database'                  => 'default_db_name',
            'metadata_cache_driver' => array(
                'type'      => 'memcache',
                'class'     => 'fooClass',
                'host'      => 'host_val',
                'port'      => 1234,
                'instance_class' => 'instance_val',
            ),
            'default_connection'                => 'conn1',
            'server'                            => 'http://server',
            'options'       => array(
                'connect'   => true,
                'persist'   => 'persist_val',
                'timeout'   => 500,
                'replicaSet' => true,
                'username'  => 'username_val',
                'password'  => '<PASSWORD>',
            ),
            'connections'   => array(
                'conn1'         => array(
                    'server'    => null,
                    'options'   => array(),
                ),
                'conn2'         => array(
                    'server'    => 'http://server2',
                    'options'   => array(),
                ),
            ),
            'mappings'      => array(
                'FooBundle'     => array(
                    'type' => 'annotations',
                ),
            ),
            'document_managers' => array(
                'dm1' => array(
                    'mappings' => array(),
                ),
                'dm2' => array(
                    'default_database' => 'dm2_default_db',
                    'connection' => 'dm2_connection',
                    'database' => 'db1',
                    'mappings' => array(
                        'BarBundle' => array(
                            'type'      => 'yml',
                            'dir'       => '%kernel.cache_dir%',
                            'prefix'    => 'prefix_val',
                            'alias'     => 'alias_val',
                        )
                    ),
                    'metadata_cache_driver' => array(
                        'type' => 'apc',
                    )
                )
            )
        );

        $this->assertEquals($expected, $options);
    }

    public function fullConfigurationProvider()
    {
      $yaml = Yaml::load(__DIR__.'/Fixtures/config/yml/full.yml');
      $yaml = $yaml['doctrine_mongo_db'];

       return array(
           array($yaml),
       );
{'fraction_non_alphanumeric': 0.1258809710258418, 'fraction_numerical': 0.0031323414252153485, 'mean_word_length': 1.3089265536723165, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 145, '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': '6965468', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2474, 'n_words': 465}