<commit_before><?php

namespace Compolomus\LSQLQueryBuilder\Tests;

use Compolomus\LSQLQueryBuilder\Builder;
use Compolomus\LSQLQueryBuilder\BuilderFactory;
use Compolomus\LSQLQueryBuilder\System\Fields;
use PHPUnit\Framework\TestCase;

class BuilderTest extends TestCase
{

    public function test__construct(): void
    {
        try {
            $builder = new Builder();
            $this->assertInternalType('object', $builder);
            $this->assertInstanceOf(Builder::class, $builder);
        } catch (\Exception $e) {
            $this->assertContains('Must be initialized ', $e->getMessage());
        }
    }

    public function testTable(): void
    {
        $builder = new Builder();
        $this->assertEquals('', $builder->table());
    }

    public function testEscapeField(): void
    {
        $builder = new Builder();
        $testString = 'Dummy';
        $testArray = ['Dummy', 'Dummy'];
        $this->assertEquals($builder->escapeField($testString), '`Dummy`');
        $this->assertEquals($builder->escapeField($testArray), ['`Dummy`', '`Dummy`']);
    }

    public function testSetTable(): void
    {
        $builder = new Builder('Dummy');
        $this->assertEquals('`Dummy`', $builder->table());
    }

    public function testFactory(): void
    {
        $builder = (new BuilderFactory)('Dummy');
        $this->assertInstanceOf(Builder::class, $builder);
        $this->assertEquals('`Dummy`', $builder->table());
    }

    public function testFields(): void
    {
        $field = new Fields('Dummy');
        $this->assertEquals('`Dummy`', $field->result());
        $field->setAllias('Allias');
        $this->assertEquals('`Dummy` AS `Allias`', $field->result());
        $field->setFunction('count');
        $this->assertEquals('COUNT(`Dummy`) AS `Allias`', $field->result());
    }

    public function testSelect(): void
    {
        $builder = (new Builder('Dummy'))->select();
        $this->assertEquals('SELECT * FROM `Dummy`', $builder);
        $builder = new Builder('table');
        $this->assertEquals('SELECT COUNT(`Dummy`) AS `Allias`,`dummy` FROM `table`', $builder->select(['Allias' => 'Dummy|count', 'dummy']));
    }

//    public function testException(): void
//    {
//
//    }

    //    public function testConcat()
//    {
//
//    }
//
//    public function testInsert()
//    {
//
//    }
//
//    public function test__isset()
//    {
//<commit_msg>Select and Fields tests complete<commit_after><?php

namespace Compolomus\LSQLQueryBuilder\Tests;

use Compolomus\LSQLQueryBuilder\Builder;
use Compolomus\LSQLQueryBuilder\BuilderException;
use Compolomus\LSQLQueryBuilder\BuilderFactory;
use Compolomus\LSQLQueryBuilder\System\Fields;
use PHPUnit\Framework\TestCase;

class BuilderTest extends TestCase
{

    public function test__construct(): void
    {
        try {
            $builder = new Builder();
            $this->assertInternalType('object', $builder);
            $this->assertInstanceOf(Builder::class, $builder);
        } catch (\Exception $e) {
            $this->assertContains('Must be initialized ', $e->getMessage());
        }
    }

    public function testTable(): void
    {
        $builder = new Builder();
        $this->assertEquals('', $builder->table());
    }

    public function testEscapeField(): void
    {
        $builder = new Builder();
        $testString = 'Dummy';
        $testArray = ['Dummy', 'Dummy'];
        $this->assertEquals($builder->escapeField($testString), '`Dummy`');
        $this->assertEquals($builder->escapeField($testArray), ['`Dummy`', '`Dummy`']);
    }

    public function testSetTable(): void
    {
        $builder = new Builder('Dummy');
        $this->assertEquals('`Dummy`', $builder->table());
    }

    public function testFactory(): void
    {
        $builder = (new BuilderFactory)('Dummy');
        $this->assertInstanceOf(Builder::class, $builder);
        $this->assertEquals('`Dummy`', $builder->table());
    }

    public function testFields(): void
    {
        $field = new Fields('Dummy');
        $this->assertEquals('`Dummy`', $field->result());
        $field->setAllias('Allias');
        $this->assertEquals('`Dummy` AS `Allias`', $field->result());
        $field->setFunction('count');
        $this->assertEquals('COUNT(`Dummy`) AS `Allias`', $field->result());
    }

    public function testSelect(): void
    {
        $builder = (new Builder('Dummy'))->select();
        $this->assertEquals('SELECT * FROM `Dummy`', $builder);
        $builder = new Builder('table');
        $this->assertEquals('SELECT COUNT(`Dummy`) AS `Allias`,`dummy` AS `allias` FROM `table`',
            $builder->select(['Dummy', 'allias' => 'dummy'])->setFunction('Dummy', 'count')->setAllias('Dummy', 'Allias'));
    }

    public function testFieldsException(): void
    {
        $this->expectException(BuilderException::class);
        (new Builder('table'))->select(['dummy|abcd']);
    }

    public function testSelectException(): void
    {
        $this->expectException(BuilderException::class);
        (new Builder('table'))->select(['dummy'])->setFunction('notDummy', 'count');
    }

    //    public function testConcat()
//    {
//
//    }
//
//    public function testInsert()
//    {
//
//    }
//
//    public function test__isset()
//    {
//
{'fraction_non_alphanumeric': 0.17916901673246852, 'fraction_numerical': 0.0, 'mean_word_length': 2.8860482103725347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 66, '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': '7621249', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1518, 'n_words': 291}