summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-06-15 20:03:11 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-06-15 20:03:11 +0300
commit846d7c3417d4b1c748193163f038a2619ce62c93 (patch)
tree3e6e50ff5a7de7201694c9b7bc1b7b10e071bb2a /tests
parent7ad9549468007c37c0eddda0cd969c648aa779a1 (diff)
downloadsql-parser-846d7c3417d4b1c748193163f038a2619ce62c93.zip
sql-parser-846d7c3417d4b1c748193163f038a2619ce62c93.tar.gz
sql-parser-846d7c3417d4b1c748193163f038a2619ce62c93.tar.bz2
Added methods to extract only one parameter and the return type of a routine.
Improved the value extraction method for tokens. Fixed a bug in data type parser. Minor parser refactoring.
Diffstat (limited to 'tests')
-rw-r--r--tests/utils/RoutineTest.php76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/utils/RoutineTest.php b/tests/utils/RoutineTest.php
index 950f1cc..34ed2af 100644
--- a/tests/utils/RoutineTest.php
+++ b/tests/utils/RoutineTest.php
@@ -11,6 +11,82 @@ class RoutineTest extends TestCase
{
/**
+ * @dataProvider getReturnTypeProvider
+ */
+ public function testGetReturnType($def, array $expected)
+ {
+ $this->assertEquals($expected, Routine::getReturnType($def));
+ }
+
+ public function getReturnTypeProvider()
+ {
+ return array(
+ array('TEXT', array('', '', 'TEXT', '', '')),
+ array('INT(20)', array('', '', 'INT', '20', '')),
+ array(
+ 'INT UNSIGNED',
+ array('', '', 'INT', '', 'UNSIGNED')
+ ),
+ array(
+ 'VARCHAR(1) CHARSET utf8',
+ array('', '', 'VARCHAR', '1', 'utf8')
+ ),
+ array(
+ 'ENUM(\'a\', \'b\') CHARSET latin1',
+ array('', '', 'ENUM', '\'a\',\'b\'', 'latin1')
+ ),
+ array(
+ 'DECIMAL(5,2) UNSIGNED ZEROFILL',
+ array('', '', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL')
+ ),
+ array(
+ 'SET(\'test\'\'esc"\', \'more\\\'esc\')',
+ array(
+ '', '', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', ''
+ )
+ )
+ );
+ }
+
+ /**
+ * @dataProvider getParameterProvider
+ */
+ public function testGetParameter($def, array $expected)
+ {
+ $this->assertEquals($expected, Routine::getParameter($def));
+ }
+
+ public function getParameterProvider()
+ {
+ return array(
+ array('`foo` TEXT', array('', 'foo', 'TEXT', '', '')),
+ array('`foo` INT(20)', array('', 'foo', 'INT', '20', '')),
+ array(
+ 'IN `fo``fo` INT UNSIGNED',
+ array('IN', 'fo`fo', 'INT', '', 'UNSIGNED')
+ ),
+ array(
+ 'OUT bar VARCHAR(1) CHARSET utf8',
+ array('OUT', 'bar', 'VARCHAR', '1', 'utf8')
+ ),
+ array(
+ '`"baz\'\'` ENUM(\'a\', \'b\') CHARSET latin1',
+ array('', '"baz\'\'', 'ENUM', '\'a\',\'b\'', 'latin1')
+ ),
+ array(
+ 'INOUT `foo` DECIMAL(5,2) UNSIGNED ZEROFILL',
+ array('INOUT', 'foo', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL')
+ ),
+ array(
+ '`foo``s func` SET(\'test\'\'esc"\', \'more\\\'esc\')',
+ array(
+ '', 'foo`s func', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', ''
+ )
+ )
+ );
+ }
+
+ /**
* @dataProvider getParametersProvider
*/
public function testGetParameters($query, array $expected)