1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
use HexMakina\Crudites\Grammar\Query\Insert; |
5
|
|
|
|
6
|
|
|
class InsertTest extends TestCase |
7
|
|
|
{ |
8
|
|
|
public function testConstructorWithEmptyData() |
9
|
|
|
{ |
10
|
|
|
$this->expectException(\InvalidArgumentException::class); |
11
|
|
|
$this->expectExceptionMessage('EMPTY_DATA'); |
12
|
|
|
|
13
|
|
|
new Insert('test_table', []); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function testConstructorWithValidData() |
17
|
|
|
{ |
18
|
|
|
$data = ['field1' => 'value1', 'field2' => 'value2']; |
19
|
|
|
$insert = new Insert('test_table', $data); |
20
|
|
|
|
21
|
|
|
$this->assertInstanceOf(Insert::class, $insert); |
22
|
|
|
} |
23
|
|
|
public function testValues() |
24
|
|
|
{ |
25
|
|
|
$data = ['field1' => 'value1', 'field2' => 'value2']; |
26
|
|
|
$insert = new Insert('test_table', $data); |
27
|
|
|
|
28
|
|
|
$insert->values(['field1' => 'value1-2', 'field2' => 'value2-2']); |
29
|
|
|
|
30
|
|
|
$expectedBindings = [ |
31
|
|
|
'test_table_field1_0' => 'value1', |
32
|
|
|
'test_table_field2_1' => 'value2', |
33
|
|
|
'test_table_field1_2' => 'value1-2', |
34
|
|
|
'test_table_field2_3' => 'value2-2' |
35
|
|
|
]; |
36
|
|
|
$this->assertEquals($expectedBindings, $insert->bindings()); |
37
|
|
|
$this->assertEquals('INSERT INTO `test_table` (`field1`,`field2`) VALUES (:test_table_field1_0,:test_table_field2_1),(:test_table_field1_2,:test_table_field2_3)', $insert->statement()); |
38
|
|
|
} |
39
|
|
|
public function testStatement() |
40
|
|
|
{ |
41
|
|
|
$data = ['field1' => 'value1', 'field2' => 'value2']; |
42
|
|
|
$insert = new Insert('test_table', $data); |
43
|
|
|
|
44
|
|
|
$expectedStatement = 'INSERT INTO `test_table` (`field1`,`field2`) VALUES (:test_table_field1_0,:test_table_field2_1)'; |
45
|
|
|
$this->assertEquals($expectedStatement, $insert->statement()); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|