-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTablesTest.php
57 lines (39 loc) · 1.54 KB
/
TablesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
use PHPUnit\Framework\TestCase;
final class TablesTest extends TestCase{
function testGeneralCreation(){
$tbl = $this->get_first_table("CREATE TABLE foo");
$this->assertEquals($tbl['name'], "foo");
$this->assertEquals(array_key_exists('temporary', $tbl['props']), false);
$tbl = $this->get_first_table("CREATE TEMPORARY TABLE foo");
$this->assertEquals($tbl['name'], "foo");
$this->assertEquals($tbl['props']['temporary'], true);
}
function testIfNotExists(){
$tbl1 = $this->get_first_table("CREATE TABLE bar");
$tbl2 = $this->get_first_table("CREATE TABLE IF NOT EXISTS bar");
# these props wont match, since it's the src sql
unset($tbl1['sql']);
unset($tbl2['sql']);
$this->assertEquals(var_export($tbl1, true), var_export($tbl2, true));
}
function testCreateTableLike(){
$tbl = $this->get_first_table("CREATE TABLE foo LIKE `bar`");
$this->assertEquals($tbl['name'], "foo");
$this->assertEquals($tbl['like'], "bar");
}
function testCreateTableLikeWithDb(){
$tbl = $this->get_first_table("CREATE TABLE db.foo LIKE `db2`.`bar`");
$this->assertEquals($tbl['name'], "foo");
$this->assertEquals($tbl['database'], "db");
$this->assertEquals($tbl['like'], "bar");
$this->assertEquals($tbl['like_database'], "db2");
}
function get_first_table($str){
$obj = new iamcal\SQLParser();
$obj->parse($str);
$tables = array_keys($obj->tables);
$first_key = $tables[0];
return $obj->tables[$first_key];
}
}