<commit_before><?php

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

namespace ONGR\ApiBundle\Tests\Functional\DependencyInjection;

use ONGR\ApiBundle\DependencyInjection\ONGRApiExtension;
use ONGR\ApiBundle\Service\DataRequestService;
use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Tests for ONGRApiExtension.
 */
class ONGRApiExtensionTest extends AbstractElasticsearchTestCase
{
    /**
     * @var string
     *
     * Root name of the configuration.
     */
    private $root = 'ongr_api';

    /**
     * {@inheritdoc}
     */
    protected function setUp()
    {
        parent::setUp();

        $this->getManager('not_default');
    }

    /**
     * @return ONGRApiExtension
     */
    protected function getExtension()
    {
        return new ONGRApiExtension();
    }

    /**
     * @return ContainerBuilder
     */
    private function getDIContainer()
    {
        $container = new ContainerBuilder();

        return $container;
    }

    /**
     * Test that config is loaded properly.
     */
    public function testGetConfig()
    {
        $config = [
            'versions' => [
                'v1' => [
                    'endpoints' => [
                        'persons' => [
                            'manager' => 'es.manager.default',
                            'document' => 'AcmeTestBundle:PersonDocument',
                        ],
                        'people' => [
                            'document' => 'AcmeTestBundle:PersonDocument',
                            'manager' => 'es.manager.default',
                            'controller' => [
                                'name' => 'CustomApi',
                            ],
                        ],
                    ],
                ],
                'v2' => [
                    'endpoints' => [
                        'people_names' => [
                            'manager' => 'es.manager.default',
                            'document' => 'AcmeTestBundle:PersonDocument',
                            'include_fields' => ['name'],
                        ],
                        'people_surnames' => [
                            'manager' => 'es.manager.default',
                            'document' => 'AcmeTestBundle:PersonDocument',
                            'exclude_fields' => ['name'],
                        ],
                    ],
                ],
            ],
        ];

        $extension = $this->getExtension();
        $container = $this->getDIContainer();
        $extension->load([$config], $container);

        $parameterKey = '.versions';
        $this->assertTrue($container->hasParameter($this->root . $parameterKey));
        $this->assertEquals(['v1', 'v2'], $container->getParameter($this->root . $parameterKey));

        $parameterKey = '.v1.endpoints';
        $this->assertTrue($container->hasParameter($this->root . $parameterKey));
        $this->assertEquals(['persons', 'people'], $container->getParameter($this->root . $parameterKey));

        $parameterKey = '.v1.persons.controller';
        $this->assertTrue($container->hasParameter($this->root . $parameterKey));
        $controller = $container->getParameter($this->root . $parameterKey);
        $this->assertEquals('default', $controller['name']);

        $parameterKey = '.v1.people.controller';
        $this->assertTrue($container->hasParameter($this->root . $parameterKey));
        $controller = $container->getParameter($this->root . $parameterKey);
        $this->assertEquals('CustomApi', $controller['name']);

        $parameterKey = '.v2.endpoints';
        $this->assertTrue($container->hasParameter($this->root . $parameterKey));
        $this->assertEquals(['people_names', 'people_surnames'], $container->getParameter($this->root . $parameterKey));

        $parameterKey = '.v2.people_names.controller';
        $this->assertTrue($container->hasParameter($this->root . $parameterKey));
        $controller = $container->getParameter($this->root . $parameterKey);
        $this->assertEquals('default', $controller['name']);

        $parameterKey = '.v2.people_surnames.controller';
        $this->assertTrue($container->hasParameter($this->root . $parameterKey));
        $controller = $container->getParameter($this->root . $parameterKey);
        $this->assertEquals('default', $controller['name']);
    }

    /**
     * Check services are created.
     */
    public function testDataRequestService()
    {<commit_msg>Updated and refactored functional DI extension test.<commit_after><?php

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

namespace ONGR\ApiBundle\Tests\Functional\DependencyInjection;

use ONGR\ApiBundle\DependencyInjection\ONGRApiExtension;
use ONGR\ApiBundle\Service\DataRequestService;
use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Tests for ONGRApiExtension.
 */
class ONGRApiExtensionTest extends AbstractElasticsearchTestCase
{
    /**
     * @var string
     *
     * Root name of the configuration.
     */
    private $root = 'ongr_api';

    /**
     * {@inheritdoc}
     */
    protected function setUp()
    {
        parent::setUp();

        $this->getManager('not_default');
    }

    /**
     * @return ONGRApiExtension
     */
    protected function getExtension()
    {
        return new ONGRApiExtension();
    }

    /**
     * @return ContainerBuilder
     */
    private function getDIContainer()
    {
        $container = new ContainerBuilder();

        return $container;
    }

    /**
     * Test that config is loaded properly.
     */
    public function testGetConfig()
    {
        $config = [
            'versions' => [
                'v1' => [
                    'endpoints' => [
                        'persons' => [
                            'manager' => 'es.manager.default',
                            'document' => 'AcmeTestBundle:PersonDocument',
                        ],
                        'people' => [
                            'document' => 'AcmeTestBundle:PersonDocument',
                            'manager' => 'es.manager.default',
                            'controller' => [
                                'name' => 'CustomApi',
                                'params' => [
                                    'service' => 'test_service',
                                ],
                            ],
                        ],
                    ],
                ],
                'v2' => [
                    'endpoints' => [
                        'people_names' => [
                            'manager' => 'es.manager.default',
                            'document' => 'AcmeTestBundle:PersonDocument',
                            'include_fields' => ['name'],
                        ],
                        'people_surnames' => [
                            'manager' => 'es.manager.default',
                            'document' => 'AcmeTestBundle:PersonDocument',
                            'exclude_fields' => ['name'],
                        ],
                        'person' => [
                            'manager' => 'es.manager.default',
                            'document' => 'AcmeTestBundle:PersonDocument',
                            'controller' => [
                                'name' => 'CustomPersonApi',
                                'path' => 'person/{id}',
                                'defaults' => [
                                    'id' => null,
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ];

        $expected = [
            '.versions' => ['v1', 'v2'],
            '.v1.endpoints' => ['persons', 'people'],
            '.v1.persons.controller' => ['name' => 'default'],
            '.v1.people.controller' => [
                'name' => 'CustomApi',
                'params' => [
                    'service' => 'test_service',
                ],
                'defaults' => [],
                'requirements' => [],
                'options' => [],
            ],
            '.v2.endpoints' => ['people_names', 'people_surnames', 'person'],
            '.v2.people_names.controller' => ['name' => 'default'],
            '.v2.people_surnames.controller' => ['name' => 'default'],
            '.v1.people' => [
                'manager' => 'es.manager.default',
                'document' => 'AcmeTestBundle:PersonDocument',
                'include_fields' => [],
                'exclude_fields' => [],
                'controller' => [
                    'name' => 'CustomApi',
                    'params' => [
                        'service' => 'test_service',
                    ],
                    'defaults' => [],
                    'requirements' => [],
                    'options' => [],
                ],
            ],
            '.v2.person' => [
                'manager' => 'es.manager.default',
                'document' => 'AcmeTestBundle:PersonDocument',
                'include_fields' => [],
                'exclude_fields' => [],
                'controller' => [
                    'name' => 'CustomPersonApi',
                    'path' => '/person/{id}',
                    'defaults' => ['id' => null],
                    'params' => [],
                    'requirements' => [],
                    'options' => [],
                ],
            ],
            '.v2.people_surnames' => [
                'manager' => 'es.manager.default',
                'document' => 'AcmeTestBundle:PersonDocument',
                'include_fields' => [],
                'exclude_fields' => ['name'],
                'controller' => ['name' => 'default'],
            ],
        ];

        $extension = $this->getExtension();
        $container = $this->getDIContainer();
        $extension->load([$config], $container);

        foreach ($expected as $key => $value) {
            $parameter = $this->root . $key;
            $this->assertTrue($container->hasParameter($parameter));
            $this->assertEquals($value, $container->getParameter($parameter));
        }
    }

    /**
     * Check services are created.
     */
    public function testDataRequestService()
    {
{'fraction_non_alphanumeric': 0.14170927684441198, 'fraction_numerical': 0.002100073046018992, 'mean_word_length': 1.4492397137745976, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3833165', 'n_tokens_mistral': 2750, 'n_tokens_neox': 2682, 'n_words': 453}