<commit_before><?php

namespace Oro\Bundle\FilterBundle\Tests\Unit\DependencyInjection\CompilerPass;


use Oro\Bundle\FilterBundle\DependencyInjection\CompilerPass\FilterTypesPass;

class FilterTypesPassTest extends \PHPUnit_Framework_TestCase
{
    const TEST_TAG_ATTRIBUTE_TYPE = 'TEST_TAG_ATTRIBUTE_TYPE';
    const TEST_SERVICE_ID = 'TEST_SERVICE_ID';

    /**
     * @var FilterTypesPass
     */
    protected $filterTypePass;

    /**
     * @var PHPUnit_Framework_MockObject_MockObject
     */
    protected $containerMock;

    /**
     * @var PHPUnit_Framework_MockObject_MockObject
     */
    protected $definitionMock;

    public function setUp()
    {
        $this->filterTypePass = new FilterTypesPass();

        $this->definitionMock = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
            ->disableOriginalConstructor()
            ->getMock();

        $this->containerMock = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
            ->disableOriginalConstructor()
            ->getMock();
    }

    public function testProcessOrm()
    {
        $this->containerMock
            ->expects($this->once())
            ->method('findTaggedServiceIds')
            ->with(FilterTypesPass::TAG_NAME)
            ->willReturn([
                self::TEST_SERVICE_ID => [ [
                    'datasource' => 'orm',
                    'type'       =>  self::TEST_TAG_ATTRIBUTE_TYPE,
                ] ]
            ]);

        $this->containerMock
            ->expects($this->once())
            ->method('hasDefinition')
            ->with(self::TEST_SERVICE_ID)
            ->willReturn(true);

        $this->containerMock
            ->expects($this->at(0))
            ->method('getDefinition')
            ->with(FilterTypesPass::FILTER_EXTENSION_ID)
            ->willReturn($this->definitionMock);

        $definitionMock2 = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
            ->disableOriginalConstructor()
            ->getMock();
        $definitionMock2
            ->expects($this->once())
            ->method('setPublic')
            ->with(false);

        $this->containerMock
            ->expects($this->at(3))
            ->method('getDefinition')
            ->with(self::TEST_SERVICE_ID)
            ->willReturn($definitionMock2);

        $this->definitionMock
            ->expects($this->once())
            ->method('addMethodCall');

        $this->filterTypePass->process($this->containerMock);
    }

    public function testProcessNonOrm()
    {
        $this->containerMock
            ->expects($this->once())
            ->method('findTaggedServiceIds')
            ->with(FilterTypesPass::TAG_NAME)<commit_msg>BB-4334: Move OroSearchBundle fixes to separate branch, do code review and merge to master - fix errors in FilterTypesPassTest<commit_after><?php

namespace Oro\Bundle\FilterBundle\Tests\Unit\DependencyInjection\CompilerPass;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

use Oro\Bundle\FilterBundle\DependencyInjection\CompilerPass\FilterTypesPass;

class FilterTypesPassTest extends \PHPUnit_Framework_TestCase
{
    const TEST_TAG_ATTRIBUTE_TYPE = 'TEST_TAG_ATTRIBUTE_TYPE';
    const TEST_SERVICE_ID = 'TEST_SERVICE_ID';

    /**
     * @var FilterTypesPass
     */
    protected $filterTypePass;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder
     */
    protected $containerMock;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject|Definition
     */
    protected $definitionMock;

    public function setUp()
    {
        $this->filterTypePass = new FilterTypesPass();

        $this->definitionMock = $this->getMockBuilder(Definition::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->containerMock = $this->getMockBuilder(ContainerBuilder::class)
            ->disableOriginalConstructor()
            ->getMock();
    }

    public function testProcessOrm()
    {
        $this->containerMock
            ->expects($this->once())
            ->method('findTaggedServiceIds')
            ->with(FilterTypesPass::TAG_NAME)
            ->willReturn([
                self::TEST_SERVICE_ID => [ [
                    'datasource' => 'orm',
                    'type'       =>  self::TEST_TAG_ATTRIBUTE_TYPE,
                ] ]
            ]);

        $this->containerMock
            ->expects($this->once())
            ->method('hasDefinition')
            ->with(self::TEST_SERVICE_ID)
            ->willReturn(true);

        $this->containerMock
            ->expects($this->at(0))
            ->method('getDefinition')
            ->with(FilterTypesPass::FILTER_EXTENSION_ID)
            ->willReturn($this->definitionMock);

        $definitionMock2 = $this->getMockBuilder(ContainerBuilder::class)
            ->disableOriginalConstructor()
            ->getMock();
        $definitionMock2
            ->expects($this->once())
            ->method('setPublic')
            ->with(false);

        $this->containerMock
            ->expects($this->at(3))
            ->method('getDefinition')
            ->with(self::TEST_SERVICE_ID)
            ->willReturn($definitionMock2);

        $this->definitionMock
            ->expects($this->once())
            ->method('addMethodCall');

        $this->filterTypePass->process($this->containerMock);
    }

    public function testProcessNonOrm()
    {
        $this->containerMock
            ->expects($this->once())
            ->method('findTaggedServiceIds')
            ->with(FilterTypesPass::TAG_NAME)
{'fraction_non_alphanumeric': 0.12732701088865472, 'fraction_numerical': 0.0024587284861257463, 'mean_word_length': 2.284313725490196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 115, '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': '6821469', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1497, 'n_words': 196}