<commit_before><?php

declare(strict_types=1);

/*
 * This file is part of the ************************ package.
 * _____________                           _______________
 *  ______/     \__  _____  ____  ______  / /_  _________
 *   ____/ __   / / / / _ \/ __`\/ / __ \/ __ \/ __ \___
 *    __/ / /  / /_/ /  __/ /  \  / /_/ / / / / /_/ /__
 *      \_\ \_/\____/\___/_/   / / .___/_/ /_/ .___/
 *         \_\                /_/_/         /_/
 *
 * The PHP Framework For Code Poem As Free As Wind. <Query Yet Simple>
 * (c) 2010-2020 http://queryphp.com All rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Tests\Database\Query;

use Tests\Database\DatabaseTestCase as TestCase;

/**
 * @api(
 *     title="Query lang.reset",
 *     zh-CN:title="查询语言.reset",
 *     path="database/query/reset",
 *     description="",
 * )
 */
class ResetTest extends TestCase
{
    /**
     * @api(
     *     zh-CN:title="重置所有",
     *     description="",
     *     note="",
     * )
     */
    public function testBaseUse(): void
    {
        $connect = $this->createDatabaseConnectMock();

        $sql = <<<'eot'
            [
                "SELECT `test_query_subsql`.* FROM `test_query_subsql` WHERE `test_query_subsql`.`new` = 'world'",
                [],
                false,
                null,
                null,
                []
            ]
            eot;

        $this->assertSame(
            $sql,
            $this->varJson(
                $connect
                    ->table('test_query')
                    ->where('id', '=', 5)
                    ->where('name', 'like', 'me')
                    ->reset()
                    ->table('test_query_subsql')
                    ->where('new', '=', 'world')
                    ->findAll(true)
            )
        );
    }

    /**
     * @api(
     *     zh-CN:title="重置某一项",
     *     description="",
     *     note="",
     * )
     */
    public function testResetItem(): void
    {
        $connect = $this->createDatabaseConnectMock();

        $sql = <<<'eot'
            [
                "SELECT `test_query`.`name`,`test_query`.`id` FROM `test_query` WHERE `test_query`.`new` LIKE 'new'",
                [],
                false,
                null,
                null,
                []
            ]
            eot;

        $this->assertSame(
            $sql,
            $this->varJson(
                $connect
                    ->table('test_query')
                    ->where('id', '=', 5)
                    ->where('name', 'like', 'me')
                    ->setColumns('name,id')
                    ->reset('where')
                    ->where('new', 'like', 'new')
                    ->findAll(true),
                1
            )
        );
    }

    public function testResetFlow(): void
    {
        $condition = false;

        $connect = $this->createDatabaseConnectMock();

        $sql = <<<'eot'
            [
                "SELECT `test_query`.`name`,`test_query`.`id` FROM `test_query` WHERE `test_query`.`id` = 5 AND `test_query`.`name` LIKE 'me' AND `test_query`.`foo` LIKE 'bar'",
                [],
                false,
                null,
                null,
                []
            ]
            eot;

        $this->assertSame(
            $sql,
            $this->varJson(
                $connect
                    ->table('test_query')
                    ->where('id', '=', 5)
                    ->where('name', 'like', 'me')
                    ->setColumns('name,id')
                    ->if($condition)
                    ->reset()
                    ->table('foo')
                    ->else()
                    ->where('foo', 'like', 'bar')
                    ->fi()
                    ->findAll(true)
            )
        );<commit_msg>tests(database): fix reset tests<commit_after><?php

declare(strict_types=1);

/*
 * This file is part of the ************************ package.
 * _____________                           _______________
 *  ______/     \__  _____  ____  ______  / /_  _________
 *   ____/ __   / / / / _ \/ __`\/ / __ \/ __ \/ __ \___
 *    __/ / /  / /_/ /  __/ /  \  / /_/ / / / / /_/ /__
 *      \_\ \_/\____/\___/_/   / / .___/_/ /_/ .___/
 *         \_\                /_/_/         /_/
 *
 * The PHP Framework For Code Poem As Free As Wind. <Query Yet Simple>
 * (c) 2010-2020 http://queryphp.com All rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Tests\Database\Query;

use Tests\Database\DatabaseTestCase as TestCase;

/**
 * @api(
 *     title="Query lang.reset",
 *     zh-CN:title="查询语言.reset",
 *     path="database/query/reset",
 *     description="",
 * )
 */
class ResetTest extends TestCase
{
    /**
     * @api(
     *     zh-CN:title="重置所有",
     *     description="",
     *     note="",
     * )
     */
    public function testBaseUse(): void
    {
        $connect = $this->createDatabaseConnectMock();

        $sql = <<<'eot'
            [
                "SELECT `test_query_subsql`.* FROM `test_query_subsql` WHERE `test_query_subsql`.`new` = :__test_query_subsql__new",
                {
                    "__test_query_subsql__new": [
                        "'world'",
                        2
                    ]
                },
                false,
                null,
                null,
                []
            ]
            eot;

        $this->assertSame(
            $sql,
            $this->varJson(
                $connect
                    ->table('test_query')
                    ->where('id', '=', 5)
                    ->where('name', 'like', 'me')
                    ->reset()
                    ->table('test_query_subsql')
                    ->where('new', '=', 'world')
                    ->findAll(true)
            )
        );
    }

    /**
     * @api(
     *     zh-CN:title="重置某一项",
     *     description="",
     *     note="",
     * )
     */
    public function testResetItem(): void
    {
        $connect = $this->createDatabaseConnectMock();

        $sql = <<<'eot'
            [
                "SELECT `test_query`.`name`,`test_query`.`id` FROM `test_query` WHERE `test_query`.`new` LIKE :__test_query__new",
                {
                    "__test_query__new": [
                        "'new'",
                        2
                    ]
                },
                false,
                null,
                null,
                []
            ]
            eot;

        $this->assertSame(
            $sql,
            $this->varJson(
                $connect
                    ->table('test_query')
                    ->where('id', '=', 5)
                    ->where('name', 'like', 'me')
                    ->setColumns('name,id')
                    ->reset('where')
                    ->where('new', 'like', 'new')
                    ->findAll(true),
                1
            )
        );
    }

    public function testResetFlow(): void
    {
        $condition = false;

        $connect = $this->createDatabaseConnectMock();

        $sql = <<<'eot'
            [
                "SELECT `test_query`.`name`,`test_query`.`id` FROM `test_query` WHERE `test_query`.`id` = :__test_query__id AND `test_query`.`name` LIKE :__test_query__name AND `test_query`.`foo` LIKE :__test_query__foo",
                {
                    "__test_query__id": [
                        5,
                        1
                    ],
                    "__test_query__name": [
                        "'me'",
                        2
                    ],
                    "__test_query__foo": [
                        "'bar'",
                        2
                    ]
                },
                false,
                null,
                null,
                []
            ]
            eot;

        $this->assertSame(
            $sql,
            $this->varJson(
                $connect
                    ->table('test_query')
                    ->where('id', '=', 5)
                    ->where('name', 'like', 'me')
                    ->setColumns('name,id')
                    ->if($condition)
                    ->reset()
                    ->table('foo')
                    ->else()
                    ->where('foo', 'like', 'bar')
                    ->fi()
                    ->findAll(true)
            )
        );
{'fraction_non_alphanumeric': 0.15166647311578213, 'fraction_numerical': 0.0038323075136453373, 'mean_word_length': 1.004655493482309, 'pattern_counts': {'":': 5, '<': 25, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4022055', 'n_tokens_mistral': 2511, 'n_tokens_neox': 2349, 'n_words': 400}