diff options
Diffstat (limited to 'tests/Parser')
-rw-r--r-- | tests/Parser/ArrayFragmentTest.php | 26 | ||||
-rw-r--r-- | tests/Parser/CallStatementTest.php | 26 | ||||
-rw-r--r-- | tests/Parser/CreateStatementTest.php | 32 | ||||
-rw-r--r-- | tests/Parser/DeleteStatementTest.php | 24 | ||||
-rw-r--r-- | tests/Parser/FragmentTest.php | 20 | ||||
-rw-r--r-- | tests/Parser/InsertStatementTest.php | 24 | ||||
-rw-r--r-- | tests/Parser/LimitKeywordTest.php | 25 | ||||
-rw-r--r-- | tests/Parser/ParserTest.php | 67 | ||||
-rw-r--r-- | tests/Parser/RenameStatementTest.php | 25 | ||||
-rw-r--r-- | tests/Parser/ReplaceStatementTest.php | 25 | ||||
-rw-r--r-- | tests/Parser/RestoreStatementTest.php | 24 | ||||
-rw-r--r-- | tests/Parser/SelectStatementTest.php | 33 | ||||
-rw-r--r-- | tests/Parser/UpdateStatementTest.php | 25 |
13 files changed, 376 insertions, 0 deletions
diff --git a/tests/Parser/ArrayFragmentTest.php b/tests/Parser/ArrayFragmentTest.php new file mode 100644 index 0000000..a31bf2a --- /dev/null +++ b/tests/Parser/ArrayFragmentTest.php @@ -0,0 +1,26 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class ArrayFragmentTest extends TestCase +{ + + /** + * @dataProvider testArrayProvider + */ + public function testArray($test) + { + $this->runParserTest($test); + } + + public function testArrayProvider() + { + return array( + array('parseArrayErr1'), + array('parseArrayErr2'), + array('parseArrayErr3'), + ); + } +} diff --git a/tests/Parser/CallStatementTest.php b/tests/Parser/CallStatementTest.php new file mode 100644 index 0000000..3eec381 --- /dev/null +++ b/tests/Parser/CallStatementTest.php @@ -0,0 +1,26 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class CallStatementTest extends TestCase +{ + + /** + * @dataProvider testCallProvider + */ + public function testCall($test) + { + $this->runParserTest($test); + } + + public function testCallProvider() + { + return array( + array('parseCall'), + array('parseCall2'), + array('parseCall3'), + ); + } +} diff --git a/tests/Parser/CreateStatementTest.php b/tests/Parser/CreateStatementTest.php new file mode 100644 index 0000000..8f8c43a --- /dev/null +++ b/tests/Parser/CreateStatementTest.php @@ -0,0 +1,32 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class CreateStatementTest extends TestCase +{ + + /** + * @dataProvider testCreateProvider + */ + public function testCreate($test) + { + $this->runParserTest($test); + } + + public function testCreateProvider() + { + return array( + array('parseCreateTable'), + array('parseCreateTable2'), + array('parseCreateTableErr1'), + array('parseCreateProcedure'), + array('parseCreateProcedure2'), + array('parseCreateFunction'), + array('parseCreateFunctionErr1'), + array('parseCreateFunctionErr2'), + array('parseCreateUser'), + ); + } +} diff --git a/tests/Parser/DeleteStatementTest.php b/tests/Parser/DeleteStatementTest.php new file mode 100644 index 0000000..d6180e7 --- /dev/null +++ b/tests/Parser/DeleteStatementTest.php @@ -0,0 +1,24 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class DeleteStatementTest extends TestCase +{ + + /** + * @dataProvider testDeleteProvider + */ + public function testDelete($test) + { + $this->runParserTest($test); + } + + public function testDeleteProvider() + { + return array( + array('parseDelete'), + ); + } +} diff --git a/tests/Parser/FragmentTest.php b/tests/Parser/FragmentTest.php new file mode 100644 index 0000000..638b84d --- /dev/null +++ b/tests/Parser/FragmentTest.php @@ -0,0 +1,20 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Fragment; +use SqlParser\Parser; +use SqlParser\TokensList; +use SqlParser\Fragments\ArrayFragment; + +use SqlParser\Tests\TestCase; + +class FragmentTest extends TestCase +{ + + public function testDummy() + { + $this->assertEquals(null, Fragment::parse(new Parser(), new TokensList())); + $this->assertEquals(null, Fragment::build(new ArrayFragment())); + } +} diff --git a/tests/Parser/InsertStatementTest.php b/tests/Parser/InsertStatementTest.php new file mode 100644 index 0000000..d63054c --- /dev/null +++ b/tests/Parser/InsertStatementTest.php @@ -0,0 +1,24 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class InsertStatementTest extends TestCase +{ + + /** + * @dataProvider testInsertProvider + */ + public function testInsert($test) + { + $this->runParserTest($test); + } + + public function testInsertProvider() + { + return array( + array('parseInsert'), + ); + } +} diff --git a/tests/Parser/LimitKeywordTest.php b/tests/Parser/LimitKeywordTest.php new file mode 100644 index 0000000..2e7831d --- /dev/null +++ b/tests/Parser/LimitKeywordTest.php @@ -0,0 +1,25 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class LimitKeywordTest extends TestCase +{ + + /** + * @dataProvider testCallProvider + */ + public function testCall($test) + { + $this->runParserTest($test); + } + + public function testCallProvider() + { + return array( + array('parseLimitErr1'), + array('parseLimitErr2'), + ); + } +} diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php new file mode 100644 index 0000000..2f0bba4 --- /dev/null +++ b/tests/Parser/ParserTest.php @@ -0,0 +1,67 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Exceptions\ParserException; +use SqlParser\Lexer; +use SqlParser\Parser; +use SqlParser\Token; +use SqlParser\TokensList; + +use SqlParser\Tests\TestCase; + +class ParserTest extends TestCase +{ + + public function testParse() + { + $this->runParserTest('parse'); + } + + public function testUnrecognizedStatement() + { + $parser = new Parser('SELECT 1; FROM'); + $this->assertEquals( + $parser->errors[0]->getMessage(), + 'Unrecognized statement type "FROM".' + ); + } + + public function testUnrecognizedKeyword() + { + $parser = new Parser('SELECT 1 FROM foo PARTITION(bar, baz) AS'); + $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..62ed19d --- /dev/null +++ b/tests/Parser/RenameStatementTest.php @@ -0,0 +1,25 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class RenameStatementTest extends TestCase +{ + + /** + * @dataProvider testRenameProvider + */ + public function testRename($test) + { + $this->runParserTest($test); + } + + public function testRenameProvider() + { + return array( + array('parseRename'), + array('parseRename2'), + ); + } +} diff --git a/tests/Parser/ReplaceStatementTest.php b/tests/Parser/ReplaceStatementTest.php new file mode 100644 index 0000000..8044a8f --- /dev/null +++ b/tests/Parser/ReplaceStatementTest.php @@ -0,0 +1,25 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class ReplaceStatementTest extends TestCase +{ + + /** + * @dataProvider testReplaceProvider + */ + public function testReplace($test) + { + $this->runParserTest($test); + } + + public function testReplaceProvider() + { + return array( + array('parseReplace'), + array('parseReplace2'), + ); + } +} diff --git a/tests/Parser/RestoreStatementTest.php b/tests/Parser/RestoreStatementTest.php new file mode 100644 index 0000000..28db6fe --- /dev/null +++ b/tests/Parser/RestoreStatementTest.php @@ -0,0 +1,24 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class RestoreStatementTest extends TestCase +{ + + /** + * @dataProvider testRestoreProvider + */ + public function testRestore($test) + { + $this->runParserTest($test); + } + + public function testRestoreProvider() + { + return array( + array('parseRestore'), + ); + } +} diff --git a/tests/Parser/SelectStatementTest.php b/tests/Parser/SelectStatementTest.php new file mode 100644 index 0000000..943ceb7 --- /dev/null +++ b/tests/Parser/SelectStatementTest.php @@ -0,0 +1,33 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class SelectStatementTest extends TestCase +{ + + public function testSelectOptions() + { + $parser = $this->runParserTest('parseSelect'); + $stmt = $parser->statements[0]; + $this->assertEquals(10, $stmt->options->has('MAX_STATEMENT_TIME')); + } + + /** + * @dataProvider testSelectProvider + */ + public function testSelect($test) + { + $this->runParserTest($test); + } + + public function testSelectProvider() + { + return array( + array('parseSelect2'), + array('parseSelectErr1'), + array('parseSelectNested'), + ); + } +} diff --git a/tests/Parser/UpdateStatementTest.php b/tests/Parser/UpdateStatementTest.php new file mode 100644 index 0000000..0bb4df0 --- /dev/null +++ b/tests/Parser/UpdateStatementTest.php @@ -0,0 +1,25 @@ +<?php + +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + +class UpdateStatementTest extends TestCase +{ + + /** + * @dataProvider testUpdateProvider + */ + public function testUpdate($test) + { + $this->runParserTest($test); + } + + public function testUpdateProvider() + { + return array( + array('parseUpdate'), + array('parseUpdate2'), + ); + } +} |