1
|
|
|
<?php |
2
|
|
|
use PHPUnit\Framework\TestCase; |
3
|
|
|
use HexMakina\Crudites\Grammar\Query\Delete; |
4
|
|
|
use HexMakina\Crudites\Grammar\Clause\Where; |
5
|
|
|
|
6
|
|
|
class DeleteTest extends TestCase |
7
|
|
|
{ |
8
|
|
|
public function testConstructorThrowsExceptionWhenConditionsAreEmpty() |
9
|
|
|
{ |
10
|
|
|
$this->expectException(\InvalidArgumentException::class); |
11
|
|
|
$this->expectExceptionMessage('DELETE_USED_AS_TRUNCATE'); |
12
|
|
|
|
13
|
|
|
new Delete('test_table', []); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function testConstructorSetsTableAndConditions() |
17
|
|
|
{ |
18
|
|
|
$table = 'test_table'; |
19
|
|
|
$conditions = ['id' => 1]; |
20
|
|
|
$delete = new Delete($table, $conditions); |
21
|
|
|
|
22
|
|
|
$this->assertEquals($table, $delete->table()); |
23
|
|
|
$this->assertInstanceOf(Where::class, $delete->clause(Where::WHERE)); |
24
|
|
|
} |
25
|
|
|
/* |
26
|
|
|
public function testStatement() |
27
|
|
|
{ |
28
|
|
|
$table = 'test_table'; |
29
|
|
|
$conditions = ['id' => 1]; |
30
|
|
|
$delete = new Delete($table, $conditions); |
31
|
|
|
|
32
|
|
|
$expectedStatement = 'DELETE FROM `test_table` WHERE `id` = :id '; |
33
|
|
|
$this->assertEquals($expectedStatement, $delete->statement()); |
34
|
|
|
|
35
|
|
|
$this->assertEquals(['id' => 1], $delete->bindings()); |
36
|
|
|
} |
37
|
|
|
/* |
38
|
|
|
public function testBindings() |
39
|
|
|
{ |
40
|
|
|
$table = 'test_table'; |
41
|
|
|
$conditions = ['id' => 1]; |
42
|
|
|
$delete = new Delete($table, $conditions); |
43
|
|
|
|
44
|
|
|
$expectedBindings = [':id' => 1]; |
45
|
|
|
$this->assertEquals($expectedBindings, $delete->bindings()); |
46
|
|
|
} |
47
|
|
|
*/ |
48
|
|
|
} |