Skip to content

Commit 404c1ec

Browse files
committed
split general table tests into their own file
1 parent a0b565e commit 404c1ec

2 files changed

Lines changed: 80 additions & 45 deletions

File tree

tests/TablePropsTest.php

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,34 @@
33

44
final class TablePropsTest extends TestCase{
55

6-
function table_props_test($tokens, $props_expect){
7-
8-
$obj = new iamcal\SQLParser();
9-
$i = 0;
10-
$props = $obj->parse_table_props($tokens, $i);
11-
12-
$this->assertEquals($props, $props_expect);
13-
}
6+
# table_options:
7+
# table_option [[,] table_option] ...
8+
#
9+
# table_option:
10+
# AUTO_INCREMENT [=] value
11+
# | AVG_ROW_LENGTH [=] value
12+
# | [DEFAULT] CHARACTER SET [=] charset_name
13+
# | CHECKSUM [=] {0 | 1}
14+
# | [DEFAULT] COLLATE [=] collation_name
15+
# | COMMENT [=] 'string'
16+
# | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'}
17+
# | CONNECTION [=] 'connect_string'
18+
# | {DATA|INDEX} DIRECTORY [=] 'absolute path to directory'
19+
# | DELAY_KEY_WRITE [=] {0 | 1}
20+
# | ENCRYPTION [=] {'Y' | 'N'}
21+
# | ENGINE [=] engine_name
22+
# | INSERT_METHOD [=] { NO | FIRST | LAST }
23+
# | KEY_BLOCK_SIZE [=] value
24+
# | MAX_ROWS [=] value
25+
# | MIN_ROWS [=] value
26+
# | PACK_KEYS [=] {0 | 1 | DEFAULT}
27+
# | PASSWORD [=] 'string'
28+
# | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT}
29+
# | STATS_AUTO_RECALC [=] {DEFAULT|0|1}
30+
# | STATS_PERSISTENT [=] {DEFAULT|0|1}
31+
# | STATS_SAMPLE_PAGES [=] value
32+
# | TABLESPACE tablespace_name [STORAGE {DISK|MEMORY|DEFAULT}]
33+
# | UNION [=] (tbl_name[,tbl_name]...)
1434

1535

1636
function testEqualsIsOptional(){
@@ -49,44 +69,12 @@ function testTwoWordProps(){
4969
# TODO: case conversion, multiple options, optional commas
5070

5171

52-
function get_first_table($str){
53-
$obj = new iamcal\SQLParser();
54-
$obj->parse($str);
55-
56-
$tables = array_keys($obj->tables);
57-
$first_key = $tables[0];
58-
59-
return $obj->tables[$first_key];
60-
}
61-
62-
function testGeneralCreation(){
63-
64-
$tbl = $this->get_first_table("CREATE TABLE foo");
65-
$this->assertEquals($tbl['name'], "foo");
66-
$this->assertEquals(array_key_exists('temporary', $tbl['props']), false);
67-
68-
$tbl = $this->get_first_table("CREATE TEMPORARY TABLE foo");
69-
$this->assertEquals($tbl['name'], "foo");
70-
$this->assertEquals($tbl['props']['temporary'], true);
71-
}
72-
73-
function testIfNotExists(){
74-
75-
$tbl1 = $this->get_first_table("CREATE TABLE bar");
76-
$tbl2 = $this->get_first_table("CREATE TABLE IF NOT EXISTS bar");
77-
78-
# these props wont match, since it's the src sql
79-
unset($tbl1['sql']);
80-
unset($tbl2['sql']);
81-
82-
$this->assertEquals(var_export($tbl1, true), var_export($tbl2, true));
83-
}
84-
85-
function testCreateTableLike(){
72+
function table_props_test($tokens, $props_expect){
8673

87-
$tbl = $this->get_first_table("CREATE TABLE foo LIKE `bar`");
74+
$obj = new iamcal\SQLParser();
75+
$i = 0;
76+
$props = $obj->parse_table_props($tokens, $i);
8877

89-
$this->assertEquals($tbl['name'], "foo");
90-
$this->assertEquals($tbl['like'], "bar");
78+
$this->assertEquals($props, $props_expect);
9179
}
9280
}

tests/TablesTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
use PHPUnit\Framework\TestCase;
3+
4+
final class TablesTest extends TestCase{
5+
6+
function testGeneralCreation(){
7+
8+
$tbl = $this->get_first_table("CREATE TABLE foo");
9+
$this->assertEquals($tbl['name'], "foo");
10+
$this->assertEquals(array_key_exists('temporary', $tbl['props']), false);
11+
12+
$tbl = $this->get_first_table("CREATE TEMPORARY TABLE foo");
13+
$this->assertEquals($tbl['name'], "foo");
14+
$this->assertEquals($tbl['props']['temporary'], true);
15+
}
16+
17+
function testIfNotExists(){
18+
19+
$tbl1 = $this->get_first_table("CREATE TABLE bar");
20+
$tbl2 = $this->get_first_table("CREATE TABLE IF NOT EXISTS bar");
21+
22+
# these props wont match, since it's the src sql
23+
unset($tbl1['sql']);
24+
unset($tbl2['sql']);
25+
26+
$this->assertEquals(var_export($tbl1, true), var_export($tbl2, true));
27+
}
28+
29+
function testCreateTableLike(){
30+
31+
$tbl = $this->get_first_table("CREATE TABLE foo LIKE `bar`");
32+
33+
$this->assertEquals($tbl['name'], "foo");
34+
$this->assertEquals($tbl['like'], "bar");
35+
}
36+
37+
38+
function get_first_table($str){
39+
$obj = new iamcal\SQLParser();
40+
$obj->parse($str);
41+
42+
$tables = array_keys($obj->tables);
43+
$first_key = $tables[0];
44+
45+
return $obj->tables[$first_key];
46+
}
47+
}

0 commit comments

Comments
 (0)