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