diff options
author | Deven Bansod <devenbansod.bits@gmail.com> | 2018-12-22 14:11:48 +0530 |
---|---|---|
committer | Deven Bansod <devenbansod.bits@gmail.com> | 2018-12-22 15:34:48 +0530 |
commit | 09faf92c59feed5c2db7490372ba3dd3947707e8 (patch) | |
tree | 1749682b76337cc607055425e40579b0030be09b /tests/Components/LockExpressionTest.php | |
parent | e07403c05da390e5da272f5ee29e0d4414add527 (diff) | |
download | sql-parser-09faf92c59feed5c2db7490372ba3dd3947707e8.zip sql-parser-09faf92c59feed5c2db7490372ba3dd3947707e8.tar.gz sql-parser-09faf92c59feed5c2db7490372ba3dd3947707e8.tar.bz2 |
Add support for LOCK and UNLOCK Statements
Signed-off-by: Deven Bansod <devenbansod.bits@gmail.com>
Diffstat (limited to 'tests/Components/LockExpressionTest.php')
-rw-r--r-- | tests/Components/LockExpressionTest.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/Components/LockExpressionTest.php b/tests/Components/LockExpressionTest.php new file mode 100644 index 0000000..56654a6 --- /dev/null +++ b/tests/Components/LockExpressionTest.php @@ -0,0 +1,71 @@ +<?php + +namespace PhpMyAdmin\SqlParser\Tests\Components; + +use PhpMyAdmin\SqlParser\Components\LockExpression; +use PhpMyAdmin\SqlParser\Parser; +use PhpMyAdmin\SqlParser\Tests\TestCase; + +class LockExpressionTest extends TestCase +{ + public function testParse() + { + $component = LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL')); + $this->assertNotNull($component->table); + $this->assertEquals($component->table->table, 'table1'); + $this->assertEquals($component->table->alias, 't1'); + $this->assertEquals($component->type, 'READ LOCAL'); + } + + public function testParse2() + { + $component = LockExpression::parse(new Parser(), $this->getTokensList('table1 LOW_PRIORITY WRITE')); + $this->assertNotNull($component->table); + $this->assertEquals($component->table->table, 'table1'); + $this->assertEquals($component->type, 'LOW_PRIORITY WRITE'); + } + + /** + * @dataProvider testParseErrProvider + * + * @param mixed $expr + * @param mixed $error + */ + public function testParseErr($expr, $error) + { + $parser = new Parser(); + LockExpression::parse($parser, $this->getTokensList($expr)); + $errors = $this->getErrorsAsArray($parser); + $this->assertEquals($errors[0][0], $error); + } + + public function testParseErrProvider() + { + return array( + array( + 'table1 AS t1', + 'Unexpected end of LOCK expression.', + ), + array( + 'table1 AS t1 READ WRITE', + 'Unexpected keyword.', + ), + array( + 'table1 AS t1 READ 2', + 'Unexpected token.', + ), + ); + } + + public function testBuild() + { + $component = array( + LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL')), + LockExpression::parse(new Parser(), $this->getTokensList('table2 LOW_PRIORITY WRITE')), + ); + $this->assertEquals( + LockExpression::build($component), + 'table1 AS `t1` READ LOCAL, table2 LOW_PRIORITY WRITE' + ); + } +} |