|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license MIT |
|
5
|
|
|
* @author Samuel Adeshina <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of the EmmetBlue project, please read the license document |
|
8
|
|
|
* available in the root level of the project |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace EmmetBlue\Test\Core\Database\Abstraction; |
|
11
|
|
|
|
|
12
|
|
|
use EmmetBlue\Core\Database\Abstraction\InsertQueryBuilder; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* class QueryBuilderTest. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Samuel Adeshina <[email protected]> |
|
18
|
|
|
* |
|
19
|
|
|
* @since v0.0.1 27/05/2016 14:27 |
|
20
|
|
|
*/ |
|
21
|
|
|
class InsertQueryBuilderTest extends \PHPUnit\Framework\TestCase |
|
22
|
|
|
{ |
|
23
|
|
View Code Duplication |
public function testInsertBuilderWithOnlyConstructorParameter() |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
$queryBuilder = new InsertQueryBuilder('tbl_name'); |
|
26
|
|
|
|
|
27
|
|
|
$builtQuery = (string) $queryBuilder; |
|
28
|
|
|
$expectedQuery = 'INSERT INTO tbl_name'; |
|
29
|
|
|
|
|
30
|
|
|
$this->assertEquals($expectedQuery, $builtQuery); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
View Code Duplication |
public function testInsertBuilderWithIntoMethod() |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
$queryBuilder = new InsertQueryBuilder(); |
|
36
|
|
|
$queryBuilder = $queryBuilder->into('tbl_name'); |
|
37
|
|
|
|
|
38
|
|
|
$builtQuery = (string) $queryBuilder; |
|
39
|
|
|
$expectedQuery = 'INSERT INTO tbl_name'; |
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals($expectedQuery, $builtQuery); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testInsertBuilderWithIntoAndTableColumnsMethod() |
|
45
|
|
|
{ |
|
46
|
|
|
$queryBuilder = new InsertQueryBuilder(); |
|
47
|
|
|
$queryBuilder = $queryBuilder->into('tbl_name', ['tbl_col1', 'tbl_col2']); |
|
48
|
|
|
|
|
49
|
|
|
$builtQuery = (string) $queryBuilder; |
|
50
|
|
|
$expectedQuery = 'INSERT INTO tbl_name(tbl_col1,tbl_col2)'; |
|
51
|
|
|
|
|
52
|
|
|
$this->assertEquals($expectedQuery, $builtQuery); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testInsertBuilderWithConstructorParameterAndValuesKeyword() |
|
56
|
|
|
{ |
|
57
|
|
|
$queryBuilder = new InsertQueryBuilder('tbl_name'); |
|
58
|
|
|
$queryBuilder = $queryBuilder->values(['tbl_col_val1', 'tbl_col_val2']); |
|
59
|
|
|
|
|
60
|
|
|
$expectedQuery = 'INSERT INTO tbl_name VALUES (tbl_col_val1,tbl_col_val2)'; |
|
61
|
|
|
$builtQuery = (string) $queryBuilder; |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEquals($expectedQuery, $builtQuery); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.