summaryrefslogtreecommitdiffstats
path: root/tests/parser/ParserTest.php
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-05-26 01:02:55 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-06-08 19:37:46 +0300
commit0a52978705d59c50f785f0f9cf537161046beb21 (patch)
tree00051de2f829f6b1f5c95c54da89be1f298b77a8 /tests/parser/ParserTest.php
downloadsql-parser-0a52978705d59c50f785f0f9cf537161046beb21.zip
sql-parser-0a52978705d59c50f785f0f9cf537161046beb21.tar.gz
sql-parser-0a52978705d59c50f785f0f9cf537161046beb21.tar.bz2
Initial commit.
Diffstat (limited to 'tests/parser/ParserTest.php')
-rw-r--r--tests/parser/ParserTest.php66
1 files changed, 66 insertions, 0 deletions
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);
+ }
+}