Skip to content

Commit

Permalink
Add few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Compolomus committed May 7, 2018
1 parent d50c95d commit b528f17
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -4,6 +4,7 @@

[![Build Status](https://scrutinizer-ci.com/g/Compolomus/SQLQueryBuilder/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Compolomus/SQLQueryBuilder/build-status/master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Compolomus/SQLQueryBuilder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Compolomus/SQLQueryBuilder/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/Compolomus/SQLQueryBuilder/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Compolomus/SQLQueryBuilder/?branch=master)
[![Code Climate](https://codeclimate.com/github/Compolomus/SQLQueryBuilder/badges/gpa.svg)](https://codeclimate.com/github/Compolomus/SQLQueryBuilder)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/783c680b-cf5e-49ec-bc21-c4d50f257974/mini.png)](https://insight.sensiolabs.com/projects/783c680b-cf5e-49ec-bc21-c4d50f257974)
[![Downloads](https://poser.pugx.org/compolomus/light-sql-query-builder/downloads)](https://packagist.org/packages/compolomus/light-sql-query-builder)
Expand Down
2 changes: 1 addition & 1 deletion src/Builder.php
Expand Up @@ -41,7 +41,7 @@ public function setTable(string $table): Builder

public function table(): string
{
return $this->escapeField($this->table);
return $this->table ? $this->escapeField($this->table) : '';
}

public function placeholders(): array
Expand Down
4 changes: 2 additions & 2 deletions src/BuilderFactory.php
Expand Up @@ -4,8 +4,8 @@

class BuilderFactory
{
public function __invoke()
public function __invoke(?string $table = null)
{
return new Builder;
return new Builder($table);
}
}
136 changes: 136 additions & 0 deletions tests/BuilderTest.php
@@ -0,0 +1,136 @@
<?php

namespace Compolomus\LSQLQueryBuilder\Tests;

use Compolomus\LSQLQueryBuilder\Builder;
use Compolomus\LSQLQueryBuilder\BuilderFactory;
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 testConcat()
// {
//
// }
//
// public function testInsert()
// {
//
// }
//
// public function test__isset()
// {
//
// }
//

//
// public function test__call()
// {
//
// }
//
// public function testMap()
// {
//
// }
//
// public function test__unset()
// {
//
// }
//
// public function test__set()
// {
//
// }
//
// public function testDelete()
// {
//
// }
//
// public function testPlaceholders()
// {
//
// }
//
// public function testConcatOrder()
// {
//
// }
//

//
// public function testAddPlaceholders()
// {
//
// }
//

//
// public function testUpdate()
// {
//
// }
//
// public function testSelect()
// {
//
// }
//
// public function test__get()
// {
//
// }
//
// public function testConcatWhere()
// {
//
// }
//
// public function testUid()
// {
//
// }
}

0 comments on commit b528f17

Please sign in to comment.