<commit_before><?php

use G4\DataMapper\Engine\Elasticsearch\ElasticsearchComparisonFormatter;
use G4\DataMapper\Common\Selection\Operator;
use G4\DataMapper\Common\SingleValue;

class ElasticsearchComparisonFormatterTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var ElasticsearchComparisonFormatter
     */
    private $comparisonFormatter;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    private $operatorMock;

    protected function setUp()
    {
        $this->comparisonFormatter = new ElasticsearchComparisonFormatter();

        $this->operatorMock = $this->getMockBuilder(\G4\DataMapper\Common\Selection\Operator::class)
            ->disableOriginalConstructor()
            ->getMock();
    }

    public function tearDown()
    {
        $this->comparisonFormatter = null;
        $this->operatorMock        = null;
    }

    public function testEqual()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::EQUAL);

        $this->assertEquals(['match' => ['age' => '15']], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('15')));
    }

    public function testGreaterThan()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::GRATER_THAN);

        $this->assertEquals(['range' => ['age' => ['gt' => '18']]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18')));
    }

    public function testLessThan()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::LESS_THAN);

        $this->assertEquals(['range' => ['age' => ['lt' => '18']]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18')));
    }

    public function testGreaterThanOrEqual()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::GRATER_THAN_OR_EQUAL);

        $this->assertEquals(['range' => ['age' => ['gte' => '18']]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18')));
    }

    public function testLessThanOrEqual()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::LESS_THAN_OR_EQUAL);

        $this->assertEquals(['range' => ['age' => ['lte' => '18']]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18')));
    }

    public function testIn()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::IN);

        $this->assertEquals(['terms' => ['age' => [18, 19, 20]]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18, 19, 20')));
    }

    public function testBetween()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::BETWEEN);

        $this->assertEquals(['range' => ['age' => ['gt' => 12, 'lt' => 20]]], $this->comparisonFormatter->format('age', $this->operatorMock, new \G4\DataMapper\Common\RangeValue(12, 20)));
    }

    public function testTimeFromInMinutes()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::TIME_FROM_IN_MINUTES);

        $this->assertEquals(['range' => ['online' => ['gt' => 'now-15m']]], $this->comparisonFormatter->format('online', $this->operatorMock, new SingleValue(15)));
    }

    public function testLike()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::LIKE);

        $this->assertEquals(['wildcard' => ['name' => '*lada*']], $this->comparisonFormatter->format('name', $this->operatorMock, new SingleValue('lada')));
    }
}<commit_msg>000 - Modified unit test for TimeFromInMinutesOperator class to test changed query.<commit_after><?php

use G4\DataMapper\Engine\Elasticsearch\ElasticsearchComparisonFormatter;
use G4\DataMapper\Common\Selection\Operator;
use G4\DataMapper\Common\SingleValue;

class ElasticsearchComparisonFormatterTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var ElasticsearchComparisonFormatter
     */
    private $comparisonFormatter;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    private $operatorMock;

    protected function setUp()
    {
        $this->comparisonFormatter = new ElasticsearchComparisonFormatter();

        $this->operatorMock = $this->getMockBuilder(\G4\DataMapper\Common\Selection\Operator::class)
            ->disableOriginalConstructor()
            ->getMock();
    }

    public function tearDown()
    {
        $this->comparisonFormatter = null;
        $this->operatorMock        = null;
    }

    public function testEqual()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::EQUAL);

        $this->assertEquals(['match' => ['age' => '15']], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('15')));
    }

    public function testGreaterThan()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::GRATER_THAN);

        $this->assertEquals(['range' => ['age' => ['gt' => '18']]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18')));
    }

    public function testLessThan()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::LESS_THAN);

        $this->assertEquals(['range' => ['age' => ['lt' => '18']]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18')));
    }

    public function testGreaterThanOrEqual()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::GRATER_THAN_OR_EQUAL);

        $this->assertEquals(['range' => ['age' => ['gte' => '18']]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18')));
    }

    public function testLessThanOrEqual()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::LESS_THAN_OR_EQUAL);

        $this->assertEquals(['range' => ['age' => ['lte' => '18']]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18')));
    }

    public function testIn()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::IN);

        $this->assertEquals(['terms' => ['age' => [18, 19, 20]]], $this->comparisonFormatter->format('age', $this->operatorMock, new SingleValue('18, 19, 20')));
    }

    public function testBetween()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::BETWEEN);

        $this->assertEquals(['range' => ['age' => ['gt' => 12, 'lt' => 20]]], $this->comparisonFormatter->format('age', $this->operatorMock, new \G4\DataMapper\Common\RangeValue(12, 20)));
    }

    public function testTimeFromInMinutes()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::TIME_FROM_IN_MINUTES);

        $this->assertEquals(['range' => ['online' => ['gt' => strtotime("-15 minute", time())]]], $this->comparisonFormatter->format('online', $this->operatorMock, new SingleValue(15)));
    }

    public function testLike()
    {
        $this->operatorMock->expects($this->any())
            ->method('getSymbol')
            ->willReturn(Operator::LIKE);

        $this->assertEquals(['wildcard' => ['name' => '*lada*']], $this->comparisonFormatter->format('name', $this->operatorMock, new SingleValue('lada')));
    }
}
{'fraction_non_alphanumeric': 0.18669474727452923, 'fraction_numerical': 0.012512388503468782, 'mean_word_length': 3.195945945945946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 229, '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': '1921324', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2266, 'n_words': 344}