<commit_before><?php

use G4\DataMapper\Engine\Elasticsearch\ElasticsearchSelectionFactory;

class ElasticSearchSelectionFactoryTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var ElasticsearchSelectionFactory
     */
    private $selectionFactory;

    private $identityMock;

    protected function setUp()
    {
        $this->identityMock = $this->getMockBuilder(\G4\DataMapper\Common\Identity::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->selectionFactory = new ElasticsearchSelectionFactory($this->identityMock);
    }

    protected function tearDown()
    {
        $this->identityMock = null;

        $this->selectionFactory = null;
    }

    public function testSort()
    {
        $this->identityMock
            ->expects($this->once())
            ->method('getSorting')
            ->willReturn([
                $this->getMockForSort('id', 'desc'),
                $this->getMockForSort('name', 'asc'),
            ]);

        $this->assertEquals([
            ['id'   => ['order' => 'desc']],
            ['name' => ['order' => 'asc']],
        ], $this->selectionFactory->sort());
    }

    public function testWhere()
    {
        $this->identityMock
            ->expects($this->once())
            ->method('isVoid')
            ->willReturn(false);

        $this->identityMock
            ->expects($this->once())
            ->method('getComparisons')
            ->willReturn([
                $this->getMockForEqualComparison('id', 1),
                $this->getMockForEqualComparison('name', 'Test'),
                $this->getMockForGtComparison('age', 18),
            ]);

        $this->assertEquals(
            ['must' =>
                [
                    ['match' => ['id' => 1]],<commit_msg>000 - Added unit test to check if sort is empty.<commit_after><?php

use G4\DataMapper\Engine\Elasticsearch\ElasticsearchSelectionFactory;

class ElasticSearchSelectionFactoryTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var ElasticsearchSelectionFactory
     */
    private $selectionFactory;

    private $identityMock;

    protected function setUp()
    {
        $this->identityMock = $this->getMockBuilder(\G4\DataMapper\Common\Identity::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->selectionFactory = new ElasticsearchSelectionFactory($this->identityMock);
    }

    protected function tearDown()
    {
        $this->identityMock = null;

        $this->selectionFactory = null;
    }

    public function testSort()
    {
        $this->identityMock
            ->expects($this->once())
            ->method('getSorting')
            ->willReturn([
                $this->getMockForSort('id', 'desc'),
                $this->getMockForSort('name', 'asc'),
            ]);

        $this->assertEquals([
            ['id'   => ['order' => 'desc']],
            ['name' => ['order' => 'asc']],
        ], $this->selectionFactory->sort());
    }

    public function testEmptySort()
    {
        $this->identityMock
            ->expects($this->once())
            ->method('getSorting')
            ->willReturn([]);

        $this->assertEquals([], $this->selectionFactory->sort());
    }

    public function testWhere()
    {
        $this->identityMock
            ->expects($this->once())
            ->method('isVoid')
            ->willReturn(false);

        $this->identityMock
            ->expects($this->once())
            ->method('getComparisons')
            ->willReturn([
                $this->getMockForEqualComparison('id', 1),
                $this->getMockForEqualComparison('name', 'Test'),
                $this->getMockForGtComparison('age', 18),
            ]);

        $this->assertEquals(
            ['must' =>
                [
                    ['match' => ['id' => 1]],
{'fraction_non_alphanumeric': 0.15446313065976713, 'fraction_numerical': 0.0038809831824062097, 'mean_word_length': 1.9466463414634145, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, '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': '377658', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1003, 'n_words': 159}