Passed
Branch master (366c16)
by William
03:30
created

DeleteStatementTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 43
c 1
b 0
f 0
dl 0
loc 88
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testBuilderMultiTable() 0 34 1
A testBuilderSingleTable() 0 50 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Tests\Builder;
6
7
use PhpMyAdmin\SqlParser\Parser;
8
use PhpMyAdmin\SqlParser\Tests\TestCase;
9
10
class DeleteStatementTest extends TestCase
11
{
12
    public function testBuilderSingleTable()
13
    {
14
        /* Assertion 1 */
15
        $query = 'DELETE IGNORE FROM t1';
16
17
        $parser = new Parser($query);
18
        $stmt = $parser->statements[0];
19
20
        $this->assertEquals($query, $stmt->build());
21
22
        /* Assertion 2 */
23
        $query = 'DELETE IGNORE FROM t1 WHERE 1=1';
24
25
        $parser = new Parser($query);
26
        $stmt = $parser->statements[0];
27
28
        $this->assertEquals($query, $stmt->build());
29
30
        /* Assertion 3 */
31
        $query = 'DELETE IGNORE FROM t1 WHERE 1=1 ORDER BY id ASC';
32
33
        $parser = new Parser($query);
34
        $stmt = $parser->statements[0];
35
36
        $this->assertEquals($query, $stmt->build());
37
38
        /* Assertion 4 */
39
        $query = 'DELETE IGNORE FROM t1 WHERE 1=1 ORDER BY id ASC LIMIT 0, 25';
40
41
        $parser = new Parser($query);
42
        $stmt = $parser->statements[0];
43
44
        $this->assertEquals($query, $stmt->build());
45
46
        /* Assertion 5 */
47
        $query = 'DELETE IGNORE FROM t1';
48
49
        $parser = new Parser($query);
50
        $stmt = $parser->statements[0];
51
52
        $this->assertEquals($query, $stmt->build());
53
54
        /* Assertion 6 */
55
        $query = 'DELETE LOW_PRIORITY FROM `test`.users '
56
            . 'WHERE `id`<3 AND (username="Dan" OR username="Paul") ORDER BY id ASC';
57
58
        $parser = new Parser($query);
59
        $stmt = $parser->statements[0];
60
61
        $this->assertEquals($query, $stmt->build());
62
    }
63
64
    public function testBuilderMultiTable()
65
    {
66
        /* Assertion 1 */
67
        $query = 'DELETE QUICK table1, table2.* FROM table1 AS `t1`, table2 AS `t2`';
68
69
        $parser = new Parser($query);
70
        $stmt = $parser->statements[0];
71
72
        $this->assertEquals($query, $stmt->build());
73
74
        /* Assertion 2 */
75
        $query = 'DELETE QUICK table1, table2.* FROM table1 AS `t1`, table2 AS `t2` WHERE 1=1';
76
77
        $parser = new Parser($query);
78
        $stmt = $parser->statements[0];
79
80
        $this->assertEquals($query, $stmt->build());
81
82
        /* Assertion 3 */
83
        $query = 'DELETE QUICK FROM table1, table2.* USING table1 AS `t1`, table2 AS `t2` WHERE 1=1';
84
85
        $parser = new Parser($query);
86
        $stmt = $parser->statements[0];
87
88
        $this->assertEquals($query, $stmt->build());
89
90
        /* Assertion 4 */
91
        $query = 'DELETE LOW_PRIORITY t1, t2 FROM t1 INNER JOIN t2 '
92
            . 'INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id';
93
94
        $parser = new Parser($query);
95
        $stmt = $parser->statements[0];
96
97
        $this->assertEquals($query, $stmt->build());
98
    }
99
}
100