diff options
Diffstat (limited to 'tests/parser')
-rw-r--r-- | tests/parser/ArrayFragmentTest.php | 20 | ||||
-rw-r--r-- | tests/parser/CallStatementTest.php | 15 | ||||
-rw-r--r-- | tests/parser/CreateStatementTest.php | 30 | ||||
-rw-r--r-- | tests/parser/DeleteStatementTest.php | 10 | ||||
-rw-r--r-- | tests/parser/InsertStatementTest.php | 10 | ||||
-rw-r--r-- | tests/parser/ParserTest.php | 66 | ||||
-rw-r--r-- | tests/parser/RenameStatementTest.php | 15 | ||||
-rw-r--r-- | tests/parser/ReplaceStatementTest.php | 15 | ||||
-rw-r--r-- | tests/parser/SelectStatementTest.php | 22 | ||||
-rw-r--r-- | tests/parser/UpdateStatementTest.php | 15 |
10 files changed, 218 insertions, 0 deletions
diff --git a/tests/parser/ArrayFragmentTest.php b/tests/parser/ArrayFragmentTest.php new file mode 100644 index 0000000..ad40385 --- /dev/null +++ b/tests/parser/ArrayFragmentTest.php @@ -0,0 +1,20 @@ +<?php + +class ArrayFragmentTest extends TestCase +{ + + public function testArrayErr1() + { + $this->runParserTest('parseArrayErr1'); + } + + public function testArrayErr2() + { + $this->runParserTest('parseArrayErr2'); + } + + public function testArrayErr3() + { + $this->runParserTest('parseArrayErr3'); + } +} diff --git a/tests/parser/CallStatementTest.php b/tests/parser/CallStatementTest.php new file mode 100644 index 0000000..c558ce1 --- /dev/null +++ b/tests/parser/CallStatementTest.php @@ -0,0 +1,15 @@ +<?php + +class CallStatementTest extends TestCase +{ + + public function testCall() + { + $this->runParserTest('parseCall'); + } + + public function testCall2() + { + $this->runParserTest('parseCall2'); + } +} diff --git a/tests/parser/CreateStatementTest.php b/tests/parser/CreateStatementTest.php new file mode 100644 index 0000000..b23e4ab --- /dev/null +++ b/tests/parser/CreateStatementTest.php @@ -0,0 +1,30 @@ +<?php + +class CreateStatementTest extends TestCase +{ + + public function testCreateTable() + { + $this->runParserTest('parseCreateTable'); + } + + public function testCreateProcedure() + { + $this->runParserTest('parseCreateProcedure'); + } + + public function testCreateProcedure2() + { + $this->runParserTest('parseCreateProcedure2'); + } + + public function testCreateFunction() + { + $this->runParserTest('parseCreateFunction'); + } + + public function testCreateFunctionErr1() + { + $this->runParserTest('parseCreateFunctionErr1'); + } +} diff --git a/tests/parser/DeleteStatementTest.php b/tests/parser/DeleteStatementTest.php new file mode 100644 index 0000000..dab28c7 --- /dev/null +++ b/tests/parser/DeleteStatementTest.php @@ -0,0 +1,10 @@ +<?php + +class DeleteStatementTest extends TestCase +{ + + public function testDelete() + { + $this->runParserTest('parseDelete'); + } +} diff --git a/tests/parser/InsertStatementTest.php b/tests/parser/InsertStatementTest.php new file mode 100644 index 0000000..bce6065 --- /dev/null +++ b/tests/parser/InsertStatementTest.php @@ -0,0 +1,10 @@ +<?php + +class InsertStatementTest extends TestCase +{ + + public function testInsert() + { + $this->runParserTest('parseInsert'); + } +} diff --git a/tests/parser/ParserTest.php b/tests/parser/ParserTest.php new file mode 100644 index 0000000..8a77086 --- /dev/null +++ b/tests/parser/ParserTest.php @@ -0,0 +1,66 @@ +<?php + +use SqlParser\Exceptions\ParserException; +use SqlParser\Lexer; +use SqlParser\Parser; +use SqlParser\Token; +use SqlParser\TokensList; + +class ParserTest extends TestCase +{ + + public function testParse() + { + $this->runParserTest('parse'); + } + + public function testUnrecognizedStatement() + { + $lexer = new Lexer("SELECT 1; FROM"); + $lexer->lex(); + $parser = new Parser($lexer->tokens); + $parser->parse(); + $this->assertEquals( + $parser->errors[0]->getMessage(), + 'Unrecognized statement type "FROM".' + ); + } + + public function testUnrecognizedKeyword() + { + $lexer = new Lexer("SELECT 1 FROM foo PARTITION(bar, baz) AS"); + $lexer->lex(); + $parser = new Parser($lexer->tokens); + $parser->parse(); + $this->assertEquals( + $parser->errors[0]->getMessage(), + 'Unrecognized keyword "AS".' + ); + } + + public function testError() + { + $parser = new Parser(new TokensList()); + + $parser->error('error #1', new Token('foo'), 1); + $parser->error('error #2', new Token('bar'), 2); + + $this->assertEquals($parser->errors, array( + new ParserException('error #1', new Token('foo'), 1), + new ParserException('error #2', new Token('bar'), 2), + )); + } + + /** + * @expectedException SqlParser\Exceptions\ParserException + * @expectedExceptionMessage strict error + * @expectedExceptionCode 3 + */ + public function testErrorStrict() + { + $parser = new Parser(new TokensList()); + $parser->strict = true; + + $parser->error('strict error', new Token('foo'), 3); + } +} diff --git a/tests/parser/RenameStatementTest.php b/tests/parser/RenameStatementTest.php new file mode 100644 index 0000000..2ae608d --- /dev/null +++ b/tests/parser/RenameStatementTest.php @@ -0,0 +1,15 @@ +<?php + +class RenameStatementTest extends TestCase +{ + + public function testRename() + { + $this->runParserTest('parseRename'); + } + + public function testRename2() + { + $this->runParserTest('parseRename2'); + } +} diff --git a/tests/parser/ReplaceStatementTest.php b/tests/parser/ReplaceStatementTest.php new file mode 100644 index 0000000..4366a15 --- /dev/null +++ b/tests/parser/ReplaceStatementTest.php @@ -0,0 +1,15 @@ +<?php + +class ReplaceStatementTest extends TestCase +{ + + public function testReplace() + { + $this->runParserTest('parseReplace'); + } + + public function testReplace2() + { + $this->runParserTest('parseReplace2'); + } +} diff --git a/tests/parser/SelectStatementTest.php b/tests/parser/SelectStatementTest.php new file mode 100644 index 0000000..3ef76b2 --- /dev/null +++ b/tests/parser/SelectStatementTest.php @@ -0,0 +1,22 @@ +<?php + +class SelectStatementTest extends TestCase +{ + + public function testSelect() + { + $parser = $this->runParserTest('parseSelect'); + $stmt = $parser->statements[0]; + $this->assertEquals(10, $stmt->options->has('MAX_STATEMENT_TIME')); + } + + public function testSelectErr1() + { + $this->runParserTest('parseSelectErr1'); + } + + public function testSelectNested() + { + $this->runParserTest('parseSelectNested'); + } +} diff --git a/tests/parser/UpdateStatementTest.php b/tests/parser/UpdateStatementTest.php new file mode 100644 index 0000000..882d9ac --- /dev/null +++ b/tests/parser/UpdateStatementTest.php @@ -0,0 +1,15 @@ +<?php + +class UpdateStatementTest extends TestCase +{ + + public function testUpdate() + { + $this->runParserTest('parseUpdate'); + } + + public function testUpdate2() + { + $this->runParserTest('parseUpdate2'); + } +} |