|
43 | 43 | use PHPSQLParser\PHPSQLParser; |
44 | 44 | use PHPSQLParser\PHPSQLCreator; |
45 | 45 |
|
| 46 | +/** |
| 47 | + * https://github.com/greenlion/PHP-SQL-Parser/issues/22 |
| 48 | + */ |
46 | 49 | class Issue22Test extends \PHPUnit_Framework_TestCase { |
47 | 50 |
|
48 | | - /** |
49 | | - * https://github.com/greenlion/PHP-SQL-Parser/issues/22 |
50 | | - */ |
51 | | - public function testIssue22() { |
52 | | - $sql = "CREATE TABLE IF NOT EXISTS wp_md_3_term_taxonomy (term_taxonomy_id bigint (20) NOT NULL auto_increment, term_id bigint (20) NOT NULL default 0, taxonomy varchar (32) NOT NULL default '', description longtext NOT NULL, parent bigint (20) NOT NULL default 0, count bigint (20) NOT NULL default 0, PRIMARY KEY (term_taxonomy_id), KEY term_id_taxonomy (term_id, taxonomy), KEY taxonomy (taxonomy)) DEFAULT CHARACTER SET utf8mb4"; |
| 51 | + protected function _test( $sql, $message ) { |
53 | 52 | $parser = new PHPSQLParser(); |
54 | 53 | $parser->parse( $sql ); |
55 | 54 | $creator = new PHPSQLCreator(); |
56 | 55 | $created = $creator->create( $parser->parsed ); |
57 | | - $this->assertSame( $sql, $created, 'Creating a CREATE statement with multi column index' ); |
| 56 | + $this->assertSame( $sql, $created, $message ); |
| 57 | + } |
| 58 | + |
| 59 | + public function testIssue22_key() { |
| 60 | + $sql = "CREATE TABLE wp_md_3_term_taxonomy (term_taxonomy_id bigint (20) NOT NULL auto_increment, term_id bigint (20) NOT NULL default 0, taxonomy varchar (32) NOT NULL default '', description longtext NOT NULL, parent bigint (20) NOT NULL default 0, count bigint (20) NOT NULL default 0, PRIMARY KEY (term_taxonomy_id), KEY term_id_taxonomy (term_id, taxonomy), KEY taxonomy (taxonomy)) DEFAULT CHARACTER SET utf8mb4"; |
| 61 | + $this->_test( $sql, 'Creating a CREATE statement with multi column KEY index' ); |
| 62 | + } |
| 63 | + |
| 64 | + public function testIssue22_primaryKey() { |
| 65 | + $sql = "CREATE TABLE wp_md_3_term_relationships (object_id bigint (20) NOT NULL default 0, term_taxonomy_id bigint (20) NOT NULL default 0, term_order int (11) NOT NULL default 0, PRIMARY KEY (object_id, term_taxonomy_id), KEY term_taxonomy_id (term_taxonomy_id)) DEFAULT CHARACTER SET utf8mb4"; |
| 66 | + $this->_test( $sql, 'Creating a CREATE statement with multi column PRIMARY KEY index' ); |
| 67 | + } |
| 68 | + |
| 69 | + public function testIssue22_index() { |
| 70 | + $sql = "CREATE TABLE wp_md_3_term_relationships (object_id bigint (20) NOT NULL default 0, term_taxonomy_id bigint (20) NOT NULL default 0, term_order int (11) NOT NULL default 0, PRIMARY KEY (term_taxonomy_id), INDEX term_id_taxonomy (term_id, taxonomy)) DEFAULT CHARACTER SET utf8mb4"; |
| 71 | + $this->_test( $sql, 'Creating a CREATE statement with multi column INDEX' ); |
| 72 | + } |
| 73 | + |
| 74 | + public function testIssue22_foreignKey() { |
| 75 | + $sql = "CREATE TABLE child (col_a INT NOT NULL, col_b INT NOT NULL, FOREIGN KEY 'a_b' (col_a, col_b)) DEFAULT CHARACTER SET utf8mb4"; |
| 76 | + $this->_test( $sql, 'Creating a CREATE statement with multi column FOREIGN KEY' ); |
| 77 | + } |
| 78 | + |
| 79 | + public function testIssue22_foreignKeyReferences() { |
| 80 | + $sql = "CREATE TABLE child (col_a INT NOT NULL, col_b INT NOT NULL, FOREIGN KEY 'a_b' (col_a, col_b) REFERENCES parent (parent_a, parent_b)) DEFAULT CHARACTER SET utf8mb4"; |
| 81 | + $this->_test( $sql, 'Creating a CREATE statement with multi column FOREIGN KEY with multi column REFERENCES' ); |
58 | 82 | } |
59 | 83 | } |
60 | 84 |
|
0 commit comments