Skip to content

Commit 0fb198f

Browse files
committed
Added test cases for Building DELETE Statements
Signed-off-by: Deven Bansod <[email protected]>
1 parent 6dc3e0c commit 0fb198f

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace SqlParser\Tests\Builder;
4+
5+
use SqlParser\Parser;
6+
7+
use SqlParser\Tests\TestCase;
8+
9+
class DeleteStatementTest extends TestCase
10+
{
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+
}

0 commit comments

Comments
 (0)