summaryrefslogtreecommitdiffstats
path: root/tests/utils/RoutineTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils/RoutineTest.php')
-rw-r--r--tests/utils/RoutineTest.php103
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/utils/RoutineTest.php b/tests/utils/RoutineTest.php
new file mode 100644
index 0000000..1f95c33
--- /dev/null
+++ b/tests/utils/RoutineTest.php
@@ -0,0 +1,103 @@
+<?php
+
+use SqlParser\Parser;
+use SqlParser\Utils\Routine;
+
+class RoutineTest extends TestCase
+{
+
+ /**
+ * @dataProvider getParametersProvider
+ */
+ public function testGetParameters($query, array $expected)
+ {
+ $parser = new Parser($query);
+ $this->assertEquals($expected, Routine::getParameters($parser->statements[0]));
+ }
+
+ public function getParametersProvider()
+ {
+ return array(
+ array(
+ 'CREATE PROCEDURE `foo`() SET @A=0',
+ array(
+ 'num' => 0,
+ 'dir' => array(),
+ 'name' => array(),
+ 'type' => array(),
+ 'length' => array(),
+ 'opts' => array()
+ )
+ ),
+ array(
+ 'CREATE DEFINER=`user\\`@`somehost``(` FUNCTION `foo```(`baz` INT) BEGIN SELECT NULL; END',
+ array(
+ 'num' => 1,
+ 'dir' => array(
+ 0 => ''
+ ),
+ 'name' => array(
+ 0 => 'baz'
+ ),
+ 'type' => array(
+ 0 => 'INT'
+ ),
+ 'length' => array(
+ 0 => ''
+ ),
+ 'opts' => array(
+ 0 => ''
+ )
+ )
+ ),
+ array(
+ 'CREATE PROCEDURE `foo`(IN `baz\\)` INT(25) zerofill unsigned) BEGIN SELECT NULL; END',
+ array(
+ 'num' => 1,
+ 'dir' => array(
+ 0 => 'IN'
+ ),
+ 'name' => array(
+ 0 => 'baz\\)'
+ ),
+ 'type' => array(
+ 0 => 'INT'
+ ),
+ 'length' => array(
+ 0 => '25'
+ ),
+ 'opts' => array(
+ 0 => 'UNSIGNED ZEROFILL'
+ )
+ )
+ ),
+ array(
+ 'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) BEGIN SELECT NULL; END',
+ array(
+ 'num' => 2,
+ 'dir' => array(
+ 0 => 'IN',
+ 1 => 'OUT'
+ ),
+ 'name' => array(
+ 0 => 'baz\\',
+ 1 => 'bazz'
+ ),
+ 'type' => array(
+ 0 => 'INT',
+ 1 => 'VARCHAR'
+ ),
+ 'length' => array(
+ 0 => '1',
+ 1 => '15'
+ ),
+ 'opts' => array(
+ 0 => 'ZEROFILL',
+ 1 => 'utf8'
+ )
+ )
+ ),
+ );
+ }
+
+}