summaryrefslogtreecommitdiffstats
path: root/tests/Utils/QueryTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Utils/QueryTest.php')
-rw-r--r--tests/Utils/QueryTest.php395
1 files changed, 198 insertions, 197 deletions
diff --git a/tests/Utils/QueryTest.php b/tests/Utils/QueryTest.php
index f4676ec..5639610 100644
--- a/tests/Utils/QueryTest.php
+++ b/tests/Utils/QueryTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Utils;
@@ -9,10 +10,10 @@ use PhpMyAdmin\SqlParser\Utils\Query;
class QueryTest extends TestCase
{
/**
- * @dataProvider getFlagsProvider
- *
* @param mixed $query
* @param mixed $expected
+ *
+ * @dataProvider getFlagsProvider
*/
public function testGetFlags($query, $expected)
{
@@ -25,257 +26,257 @@ class QueryTest extends TestCase
public function getFlagsProvider()
{
- return array(
- array(
+ return [
+ [
'ALTER TABLE DROP col',
- array(
+ [
'reload' => true,
'querytype' => 'ALTER',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CALL test()',
- array(
+ [
'is_procedure' => true,
'querytype' => 'CALL',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CREATE TABLE tbl (id INT)',
- array(
+ [
'reload' => true,
'querytype' => 'CREATE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CHECK TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'CHECK',
- ),
- ),
- array(
+ ],
+ ],
+ [
'DELETE FROM tbl',
- array(
+ [
'is_affected' => true,
'is_delete' => true,
'querytype' => 'DELETE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'DROP VIEW v',
- array(
+ [
'reload' => true,
'querytype' => 'DROP',
- ),
- ),
- array(
+ ],
+ ],
+ [
'DROP DATABASE db',
- array(
+ [
'drop_database' => true,
'reload' => true,
'querytype' => 'DROP',
- ),
- ),
- array(
+ ],
+ ],
+ [
'EXPLAIN tbl',
- array(
+ [
'is_explain' => true,
'querytype' => 'EXPLAIN',
- ),
- ),
- array(
+ ],
+ ],
+ [
'LOAD DATA INFILE \'/tmp/test.txt\' INTO TABLE test',
- array(
+ [
'is_affected' => true,
'is_insert' => true,
'querytype' => 'LOAD',
- ),
- ),
- array(
+ ],
+ ],
+ [
'INSERT INTO tbl VALUES (1)',
- array(
+ [
'is_affected' => true,
'is_insert' => true,
'querytype' => 'INSERT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'REPLACE INTO tbl VALUES (2)',
- array(
+ [
'is_affected' => true,
'is_replace' => true,
'is_insert' => true,
'querytype' => 'REPLACE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT 1',
- array(
+ [
'is_select' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM tbl',
- array(
+ [
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT DISTINCT * FROM tbl LIMIT 0, 10 ORDER BY id',
- array(
+ [
'distinct' => true,
'is_select' => true,
'select_from' => true,
'limit' => true,
'order' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM actor GROUP BY actor_id',
- array(
+ [
'is_group' => true,
'is_select' => true,
'select_from' => true,
'group' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT col1, col2 FROM table1 PROCEDURE ANALYSE(10, 2000);',
- array(
+ [
'is_analyse' => true,
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM tbl INTO OUTFILE "/tmp/export.txt"',
- array(
+ [
'is_export' => true,
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT COUNT(id), SUM(id) FROM tbl',
- array(
+ [
'is_count' => true,
'is_func' => true,
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT (SELECT "foo")',
- array(
+ [
'is_select' => true,
'is_subquery' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM customer HAVING store_id = 2;',
- array(
+ [
'is_select' => true,
'select_from' => true,
'is_group' => true,
'having' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM table1 INNER JOIN table2 ON table1.id=table2.id;',
- array(
+ [
'is_select' => true,
'select_from' => true,
'join' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SHOW CREATE TABLE tbl',
- array(
+ [
'is_show' => true,
'querytype' => 'SHOW',
- ),
- ),
- array(
+ ],
+ ],
+ [
'UPDATE tbl SET id = 1',
- array(
+ [
'is_affected' => true,
'querytype' => 'UPDATE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'ANALYZE TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'ANALYZE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CHECKSUM TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'CHECKSUM',
- ),
- ),
- array(
+ ],
+ ],
+ [
'OPTIMIZE TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'OPTIMIZE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'REPAIR TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'REPAIR',
- ),
- ),
- array(
+ ],
+ ],
+ [
'(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10) ' .
'UNION ' .
'(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);',
- array(
+ [
'is_select' => true,
'select_from' => true,
'limit' => true,
'order' => true,
'union' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM orders AS ord WHERE 1',
- array(
+ [
'querytype' => 'SELECT',
'is_select' => true,
'select_from' => true,
- ),
- ),
- array(
+ ],
+ ],
+ [
'SET NAMES \'latin\'',
- array(
+ [
'querytype' => 'SET',
- ),
- )
- );
+ ],
+ ],
+ ];
}
public function testGetAll()
{
$this->assertEquals(
- array(
+ [
'distinct' => false,
'drop_database' => false,
'group' => false,
@@ -303,7 +304,7 @@ class QueryTest extends TestCase
'reload' => false,
'select_from' => false,
'union' => false,
- ),
+ ],
Query::getAll('')
);
@@ -313,21 +314,21 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array('*'),
- 'select_tables' => array(
- array(
+ 'select_expr' => ['*'],
+ 'select_tables' => [
+ [
'actor',
null,
- ),
- array(
+ ],
+ [
'film',
'sakila2',
- ),
- )
- )
+ ],
+ ],
+ ]
),
Query::getAll($query)
);
@@ -337,21 +338,21 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array('*'),
- 'select_tables' => array(
- array(
+ 'select_expr' => ['*'],
+ 'select_tables' => [
+ [
'actor',
'sakila',
- ),
- array(
+ ],
+ [
'film',
null,
- ),
- )
- )
+ ],
+ ],
+ ]
),
Query::getAll($query)
);
@@ -361,17 +362,17 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array(),
- 'select_tables' => array(
- array(
+ 'select_expr' => [],
+ 'select_tables' => [
+ [
'actor',
'sakila',
- ),
- ),
- )
+ ],
+ ],
+ ]
),
Query::getAll($query)
);
@@ -381,24 +382,24 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array(
+ 'select_expr' => [
'CASE WHEN 2 IS NULL THEN "this is true" ELSE "this is false" END',
- ),
- 'select_tables' => array(),
- )
+ ],
+ 'select_tables' => [],
+ ]
),
Query::getAll($query)
);
}
/**
- * @dataProvider getTablesProvider
- *
* @param mixed $query
* @param mixed $expected
+ *
+ * @dataProvider getTablesProvider
*/
public function testGetTables($query, $expected)
{
@@ -411,42 +412,42 @@ class QueryTest extends TestCase
public function getTablesProvider()
{
- return array(
- array(
+ return [
+ [
'INSERT INTO tbl(`id`, `name`) VALUES (1, "Name")',
- array('`tbl`')
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'UPDATE tbl SET id = 0',
- array('`tbl`')
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'DELETE FROM tbl WHERE id < 10',
- array('`tbl`')
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'TRUNCATE tbl',
- array('`tbl`')
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'DROP VIEW v',
- array()
- ),
- array(
+ [],
+ ],
+ [
'DROP TABLE tbl1, tbl2',
- array(
+ [
'`tbl1`',
'`tbl2`',
- ),
- ),
- array(
+ ],
+ ],
+ [
'RENAME TABLE a TO b, c TO d',
- array(
+ [
'`a`',
- '`c`'
- )
- )
- );
+ '`c`',
+ ],
+ ],
+ ];
}
public function testGetClause()
@@ -614,7 +615,7 @@ class QueryTest extends TestCase
public function testReplaceClauses()
{
- $this->assertEquals('', Query::replaceClauses(null, null, array()));
+ $this->assertEquals('', Query::replaceClauses(null, null, []));
$parser = new Parser('SELECT *, (SELECT 1) FROM film LIMIT 0, 10;');
$this->assertEquals(
@@ -622,12 +623,12 @@ class QueryTest extends TestCase
Query::replaceClauses(
$parser->statements[0],
$parser->list,
- array(
- array(
+ [
+ [
'WHERE',
'WHERE film_id > 0',
- )
- )
+ ],
+ ]
)
);
@@ -648,20 +649,20 @@ class QueryTest extends TestCase
Query::replaceClauses(
$parser->statements[0],
$parser->list,
- array(
- array(
+ [
+ [
'FROM',
'FROM city AS c',
- ),
- array(
+ ],
+ [
'WHERE',
'',
- ),
- array(
+ ],
+ [
'LIMIT',
'LIMIT 0, 10',
- )
- )
+ ],
+ ]
)
);
}