<commit_before><?php
/**
 * TPSolariumExtensionsExtensionTest.php
 *
 * This file is part of the SolariumExtensionsBundle.
 * Read the LICENSE file in the root of the project for information on copyright.
 *
 * @author <NAME> <<EMAIL>>
 * @since  19.03.13
 */
namespace TP\SolariumExtensionsBundle\Tests;

use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

use TP\SolariumExtensionsBundle\DependencyInjection\Compiler\NelmioConfigSnifferPass;
use TP\SolariumExtensionsBundle\DependencyInjection\TPSolariumExtensionsExtension;

use Nelmio\SolariumBundle\DependencyInjection\NelmioSolariumExtension;

use Solarium\Client;


/**
 * Class TPSolariumExtensionsExtensionTest
 *
 * @package TP\SolariumExtensionsBundle\Tests
 */
class TPSolariumExtensionsExtensionTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Symfony\Component\DependencyInjection\ContainerBuilder
     */
    public $container;

    /**
     * @var array
     */
    public $configNelmio = array(
        'default_client' => 'client1',
        'clients' => array(
            'client1' => array(
                'client_class' => 'TP\SolariumExtensionsBundle\Tests\StubClientOne'
            ),
            'client2' => array(
                'client_class' => 'TP\SolariumExtensionsBundle\Tests\StubClientTwo'
            )
        ),
    );

    /**
     * {@inheritDoc}
     */
    protected function setUp()
    {
        $configTp = array(
            'metadata_cache_dir' => '%kernel.cache_dir%/metadata_test_cache'
        );

        $this->container = $this->getTestContainer($this->configNelmio, $configTp);
    }

    public function testCacheDirOption()
    {
        $this->assertFileExists(__DIR__ . '/metadata_test_cache');

        $configTp = array(
            'metadata_cache_dir' => '%kernel.cache_dir%/metadata_test_cache_two'
        );

        $this->container = $this->getTestContainer($this->configNelmio, $configTp);

        $this->assertFileExists(__DIR__ . '/metadata_test_cache_two');
        rmdir(__DIR__ . '/metadata_test_cache_two');
    }

    public function testDoctrineListenerInitialized()
    {
        $listener = $this->container->get('solarium_extensions.doctrine_listener');

        $this->assertInstanceOf(
            $this->container->getParameter('solarium_extensions.doctrine_listener.class'),
            $listener
        );
    }

    public function testProcessorCreation()
    {
        $processor = $this->container
            ->get('solarium_extensions.doctrine_listener')
            ->getProcessor()
        ;

        $this->assertInstanceOf(
            $this->container->getParameter('solarium_extensions.processor.class'),
            $processor
        );

        $this->assertInstanceOf(
            $this->container->getParameter('solarium_extensions.metadata_factory.class'),
            $processor->getMetadataFactory()
        );

        $this->assertInstanceOf(
            $this->container->getParameter('solarium_extensions.service_manager.class'),
            $processor->getServiceManager()
        );
    }

    public function testClientSniffing()
    {
        $manager = $this->container
            ->get('solarium_extensions.doctrine_listener')
            ->getProcessor()
            ->getServiceManager()
        ;

        $this->assertInstanceOf(
            'TP\SolariumExtensionsBundle\Manager\SolariumServiceManager',
            $manager
        );

        $this->assertInstanceOf(
            'TP\SolariumExtensionsBundle\Tests\StubClientOne',
            $manager->getClient('solarium.client.client1')
        );

        $this->assertInstanceOf(
            'TP\SolariumExtensionsBundle\Tests\StubClientTwo',
            $manager->getClient('solarium.client.client2')
        );

        $this->assertSame(
            $this->container->get('solarium.client.client1'),
            $manager->getClient('solarium.client.client1')
        );

        $this->assertSame(
            $this->container->get('solarium.client.client2'),
            $manager->getClient('solarium.client.client2')
        );
    }

    private function getTestContainer($configNelmio, $configTp)
    {
        $container = $this->createContainer();
        $container->registerExtension(new NelmioSolariumExtension());
        $container->loadFromExtension('nelmio_solarium', $configNelmio);
        $container->registerExtension(new TPSolariumExtensionsExtension());
        $container->loadFromExtension('tp_solarium_extensions', $configTp);

        $container->addCompilerPass(new NelmioConfigSnifferPass());
<commit_msg>Added enpoint assertions to Extension test.<commit_after><?php
/**
 * TPSolariumExtensionsExtensionTest.php
 *
 * This file is part of the SolariumExtensionsBundle.
 * Read the LICENSE file in the root of the project for information on copyright.
 *
 * @author <NAME> <<EMAIL>>
 * @since  19.03.13
 */
namespace TP\SolariumExtensionsBundle\Tests;

use Solarium\Core\Client\Endpoint;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

use TP\SolariumExtensionsBundle\DependencyInjection\Compiler\NelmioConfigSnifferPass;
use TP\SolariumExtensionsBundle\DependencyInjection\TPSolariumExtensionsExtension;

use Nelmio\SolariumBundle\DependencyInjection\NelmioSolariumExtension;

use Solarium\Client;


/**
 * Class TPSolariumExtensionsExtensionTest
 *
 * @package TP\SolariumExtensionsBundle\Tests
 */
class TPSolariumExtensionsExtensionTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Symfony\Component\DependencyInjection\ContainerBuilder
     */
    public $container;

    /**
     * @var array
     */
    public $configNelmio = array(
        'endpoints' => array(
            'default' => array(
                'host' => 'localhost',
                'port' => '8080',
                'path' => 'solr-jobzauberer',
                'core' => 'jobzauberer_test',
                'timeout' => 5
            ),
            'test' => array(
                'host' => 'localhost',
                'port' => '8888',
                'path' => 'test',
                'core' => 'test_core',
                'timeout' => 15
            )
        ),
        'default_client' => 'client1',
        'clients' => array(
            'client1' => array(
                'client_class' => 'TP\SolariumExtensionsBundle\Tests\StubClientOne',
                'endpoints' => array('default')
            ),
            'client2' => array(
                'client_class' => 'TP\SolariumExtensionsBundle\Tests\StubClientTwo',
                'endpoints'    => array('test', 'default')
            )
        ),
    );

    /**
     * {@inheritDoc}
     */
    protected function setUp()
    {
        $configTp = array(
            'metadata_cache_dir' => '%kernel.cache_dir%/metadata_test_cache'
        );

        $this->container = $this->getTestContainer($this->configNelmio, $configTp);
    }

    public function testCacheDirOption()
    {
        $this->assertFileExists(__DIR__ . '/metadata_test_cache');

        $configTp = array(
            'metadata_cache_dir' => '%kernel.cache_dir%/metadata_test_cache_two'
        );

        $this->container = $this->getTestContainer($this->configNelmio, $configTp);

        $this->assertFileExists(__DIR__ . '/metadata_test_cache_two');
        rmdir(__DIR__ . '/metadata_test_cache_two');
    }

    public function testDoctrineListenerInitialized()
    {
        $listener = $this->container->get('solarium_extensions.doctrine_listener');

        $this->assertInstanceOf(
            $this->container->getParameter('solarium_extensions.doctrine_listener.class'),
            $listener
        );
    }

    public function testProcessorCreation()
    {
        $processor = $this->container
            ->get('solarium_extensions.doctrine_listener')
            ->getProcessor()
        ;

        $this->assertInstanceOf(
            $this->container->getParameter('solarium_extensions.processor.class'),
            $processor
        );

        $this->assertInstanceOf(
            $this->container->getParameter('solarium_extensions.metadata_factory.class'),
            $processor->getMetadataFactory()
        );

        $this->assertInstanceOf(
            $this->container->getParameter('solarium_extensions.service_manager.class'),
            $processor->getServiceManager()
        );
    }

    public function testClientSniffing()
    {
        $manager = $this->container
            ->get('solarium_extensions.doctrine_listener')
            ->getProcessor()
            ->getServiceManager()
        ;

        $this->assertInstanceOf(
            'TP\SolariumExtensionsBundle\Manager\SolariumServiceManager',
            $manager
        );

        $this->assertInstanceOf(
            'TP\SolariumExtensionsBundle\Tests\StubClientOne',
            $manager->getClient('solarium.client.client1')
        );

        $endpointDefault = new Endpoint(array(
            'host' => 'localhost',
            'port' => '8080',
            'path' => 'solr-jobzauberer',
            'core' => 'jobzauberer_test',
            'timeout' => 5,
            'key' => 'default'
        ));

        $expected = array(
            'default' => $endpointDefault
        );

        $this->assertEquals(
            $expected,
            $manager->getClient('solarium.client.client1')->getEndpoints()
        );

        $this->assertInstanceOf(
            'TP\SolariumExtensionsBundle\Tests\StubClientTwo',
            $manager->getClient('solarium.client.client2')
        );

        $endpointTest = new Endpoint(array(
            'host' => 'localhost',
            'port' => '8888',
            'path' => 'test',
            'core' => 'test_core',
            'timeout' => 15,
            'key' => 'test'
        ));

        $expected = array(
            'test'    => $endpointTest,
            'default' => $endpointDefault
        );

        $this->assertEquals(
            $expected,
            $manager->getClient('solarium.client.client2')->getEndpoints()
        );

        $this->assertSame(
            $this->container->get('solarium.client.client1'),
            $manager->getClient('solarium.client.client1')
        );

        $this->assertSame(
            $this->container->get('solarium.client.client2'),
            $manager->getClient('solarium.client.client2')
        );
    }

    private function getTestContainer($configNelmio, $configTp)
    {
        $container = $this->createContainer();
        $container->registerExtension(new NelmioSolariumExtension());
        $container->loadFromExtension('nelmio_solarium', $configNelmio);
        $container->registerExtension(new TPSolariumExtensionsExtension());
        $container->loadFromExtension('tp_solarium_extensions', $configTp);

        $container->addCompilerPass(new NelmioConfigSnifferPass());

{'fraction_non_alphanumeric': 0.12588923908149482, 'fraction_numerical': 0.004862674470959028, 'mean_word_length': 2.434137291280148, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 161, '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': '5314334', 'n_tokens_mistral': 3100, 'n_tokens_neox': 3045, 'n_words': 410}