<commit_before><?php declare(strict_types = 1);

namespace Algatux\Tests\QueryBuilder\unit;

use Algatux\QueryBuilder\Builder;
use Algatux\QueryBuilder\Query;
use MongoDB\Collection;

class BuilderTest extends \PHPUnit_Framework_TestCase
{
    public function test_and_array()
    {
        $builder = $this->getBuilder();

        $builder
            ->count()
            ->and(['testField' => 10]);

        $this->assertEquals(
            [
                '$and' => [
                    [ "testField" => 10 ]
                ]
            ],
            $builder->getQuery()->getFilters()
        );
        $this->assertEquals(Query::TYPE_COUNT, $builder->getQueryType());
    }

    public function test_and_multiple_array()
    {
        $builder = $this->getBuilder();

        $builder
            ->find()
            ->and(['testField1' => 1])
            ->and(['testField2' => 2]);

        $this->assertEquals(
            [
                '$and' => [
                    [ "testField1" => 1 ],
                    [ "testField2" => 2 ],
                ]
            ],
            $builder->getQuery()->getFilters()
        );
        $this->assertEquals(Query::TYPE_FIND, $builder->getQueryType());
    }

    public function test_and_multiple_array_single_call()
    {
        $builder = $this->getBuilder();

        $builder->and(['testField1' => 1],['testField2' => 2]);

        $this->assertEquals(
            [
                '$and' => [
                    [ "testField1" => 1 ],
                    [ "testField2" => 2 ],
                ]
            ],
            $builder->getQuery()->getFilters()
        );
    }

    public function test_expressions_concatenation_and()
    {
        $builder = $this->getBuilder();

        $builder->and(
            $builder->expr()->or(
                ['testField1' => ['$in' => ['a', 'b']]],
                ['testField2' => 2]
            ),
            ['testField3' => 3]
        );

        $this->assertEquals(
            [
                '$and' => [
                    [
                        '$or' => [
                            ["testField1" => ['$in' => ['a', 'b']]] ,
                            ['testField2' => 2]
                        ]
                    ],
                    ['testField3' => 3]
                ]
            ],
            $builder->getQuery()->getFilters()
        );
    }

    public function test_expressions_concatenation_or()
    {
        $builder = $this->getBuilder();

        $builder->or(
            $builder->expr()->and(
                ['testField1' => ['$in' => ['a', 'b']]],
                ['testField2' => 2]
            ),
            ['testField3' => 3]
        );

        $this->assertEquals(
            [
                '$or' => [
                    [
                        '$and' => [
                            ["testField1" => ['$in' => ['a', 'b']]] ,
                            ['testField2' => 2]
                        ]
                    ],
                    ['testField3' => 3]
                ]
            ],
            $builder->getQuery()->getFilters()
        );
    }

    public function test_sort()
    {
        $builder = $this->getBuilder();

        $builder->sort(['sortField' => -1]);

        $this->assertEquals(
            ['sort' => ['sortField' => -1]],
            $builder->getQuery()->getOptions()
        );
    }

    public function test_limit()
    {
        $builder = $this->getBuilder();

        $builder->limit(10);

        $this->assertEquals(
            ['limit' => 10],
            $builder->getQuery()->getOptions()
        );
    }

    public function test_projection()
    {
        $builder = $this->getBuilder();

        $builder->select('_id', 'field1');

        $this->assertEquals(<commit_msg>added skip test<commit_after><?php declare(strict_types = 1);

namespace Algatux\Tests\QueryBuilder\unit;

use Algatux\QueryBuilder\Builder;
use Algatux\QueryBuilder\Query;
use MongoDB\Collection;

class BuilderTest extends \PHPUnit_Framework_TestCase
{
    public function test_and_array()
    {
        $builder = $this->getBuilder();

        $builder
            ->count()
            ->and(['testField' => 10]);

        $this->assertEquals(
            [
                '$and' => [
                    [ "testField" => 10 ]
                ]
            ],
            $builder->getQuery()->getFilters()
        );
        $this->assertEquals(Query::TYPE_COUNT, $builder->getQueryType());
    }

    public function test_and_multiple_array()
    {
        $builder = $this->getBuilder();

        $builder
            ->find()
            ->and(['testField1' => 1])
            ->and(['testField2' => 2]);

        $this->assertEquals(
            [
                '$and' => [
                    [ "testField1" => 1 ],
                    [ "testField2" => 2 ],
                ]
            ],
            $builder->getQuery()->getFilters()
        );
        $this->assertEquals(Query::TYPE_FIND, $builder->getQueryType());
    }

    public function test_and_multiple_array_single_call()
    {
        $builder = $this->getBuilder();

        $builder->and(['testField1' => 1],['testField2' => 2]);

        $this->assertEquals(
            [
                '$and' => [
                    [ "testField1" => 1 ],
                    [ "testField2" => 2 ],
                ]
            ],
            $builder->getQuery()->getFilters()
        );
    }

    public function test_expressions_concatenation_and()
    {
        $builder = $this->getBuilder();

        $builder->and(
            $builder->expr()->or(
                ['testField1' => ['$in' => ['a', 'b']]],
                ['testField2' => 2]
            ),
            ['testField3' => 3]
        );

        $this->assertEquals(
            [
                '$and' => [
                    [
                        '$or' => [
                            ["testField1" => ['$in' => ['a', 'b']]] ,
                            ['testField2' => 2]
                        ]
                    ],
                    ['testField3' => 3]
                ]
            ],
            $builder->getQuery()->getFilters()
        );
    }

    public function test_expressions_concatenation_or()
    {
        $builder = $this->getBuilder();

        $builder->or(
            $builder->expr()->and(
                ['testField1' => ['$in' => ['a', 'b']]],
                ['testField2' => 2]
            ),
            ['testField3' => 3]
        );

        $this->assertEquals(
            [
                '$or' => [
                    [
                        '$and' => [
                            ["testField1" => ['$in' => ['a', 'b']]] ,
                            ['testField2' => 2]
                        ]
                    ],
                    ['testField3' => 3]
                ]
            ],
            $builder->getQuery()->getFilters()
        );
    }

    public function test_sort()
    {
        $builder = $this->getBuilder();

        $builder->sort(['sortField' => -1]);

        $this->assertEquals(
            ['sort' => ['sortField' => -1]],
            $builder->getQuery()->getOptions()
        );
    }

    public function test_limit()
    {
        $builder = $this->getBuilder();

        $builder->limit(10);

        $this->assertEquals(
            ['limit' => 10],
            $builder->getQuery()->getOptions()
        );
    }

    public function test_skip()
    {
        $builder = $this->getBuilder();

        $builder->skip(10);

        $this->assertEquals(
            ['skip' => 10],
            $builder->getQuery()->getOptions()
        );
    }

    public function test_projection()
    {
        $builder = $this->getBuilder();

        $builder->select('_id', 'field1');

        $this->assertEquals(
{'fraction_non_alphanumeric': 0.16683647478349464, 'fraction_numerical': 0.01273560876209883, 'mean_word_length': 1.2071388420460933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 181, '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': '6857454', 'n_tokens_mistral': 2246, 'n_tokens_neox': 2096, 'n_words': 311}