* Update sqlparser to fit php8.
This commit is contained in:
+80
-69
@@ -1,45 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Tests\TestCase;
|
||||
use PhpMyAdmin\SqlParser\Utils\BufferedQuery;
|
||||
|
||||
use function count;
|
||||
use function str_split;
|
||||
|
||||
class BufferedQueryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider extractProvider
|
||||
* @param array<string, bool> $options
|
||||
* @param string[] $expected
|
||||
* @psalm-param array{delimiter?: non-empty-string, parse_delimiter?: bool, add_delimiter?: bool} $options
|
||||
* @psalm-param positive-int $chunkSize
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param mixed $chunkSize
|
||||
* @dataProvider extractProvider
|
||||
*/
|
||||
public function testExtract(
|
||||
$query,
|
||||
$chunkSize,
|
||||
string $query,
|
||||
int $chunkSize,
|
||||
array $options,
|
||||
array $expected
|
||||
) {
|
||||
): void {
|
||||
$chunks = str_split($query, $chunkSize);
|
||||
$count = count($chunks);
|
||||
|
||||
/**
|
||||
* The array of extracted statements.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
$statements = array();
|
||||
$statements = [];
|
||||
|
||||
/**
|
||||
* The `BufferedQuery` instance used for extraction.
|
||||
*
|
||||
* @var BufferedQuery
|
||||
*/
|
||||
$bq = new BufferedQuery('', $options);
|
||||
|
||||
// Feeding chunks and extracting queries.
|
||||
$i = 0;
|
||||
while ($i < $count) {
|
||||
if ($stmt = $bq->extract()) {
|
||||
$stmt = $bq->extract();
|
||||
|
||||
if ($stmt) {
|
||||
$statements[] = $stmt;
|
||||
} else {
|
||||
$bq->query .= $chunks[$i++];
|
||||
@@ -54,7 +59,11 @@ class BufferedQueryTest extends TestCase
|
||||
$this->assertEquals($expected, $statements);
|
||||
}
|
||||
|
||||
public function extractProvider()
|
||||
/**
|
||||
* @return array<int, array<int, int|string|string[]|bool[]>>
|
||||
* @psalm-return list<array{string, positive-int, array{parse_delimiter: bool, add_delimiter: bool}, string[]}>
|
||||
*/
|
||||
public function extractProvider(): array
|
||||
{
|
||||
$query =
|
||||
'/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' . "\n" .
|
||||
@@ -68,7 +77,8 @@ class BufferedQueryTest extends TestCase
|
||||
'/* a comment */ DELIMITER $$' . "\n" .
|
||||
'' . "\n" .
|
||||
'# Bash-like comment sytanx.' . "\n" .
|
||||
'CREATE DEFINER=`root`@`localhost` PROCEDURE `film_in_stock` (IN `p_film_id` INT, IN `p_store_id` INT, OUT `p_film_count` INT) READS SQL DATA' . "\n" .
|
||||
'CREATE DEFINER=`root`@`localhost` PROCEDURE `film_in_stock` (IN `p_film_id` ' .
|
||||
'INT, IN `p_store_id` INT, OUT `p_film_count` INT) READS SQL DATA' . "\n" .
|
||||
'BEGIN' . "\n" .
|
||||
' SELECT inventory_id' . "\n" .
|
||||
' FROM inventory' . "\n" .
|
||||
@@ -99,33 +109,31 @@ class BufferedQueryTest extends TestCase
|
||||
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;' . "\n" .
|
||||
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */';
|
||||
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
"SELECT '\'';\nSELECT '\'';",
|
||||
8,
|
||||
array(
|
||||
[
|
||||
'parse_delimiter' => true,
|
||||
'add_delimiter' => true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
"SELECT '\'';",
|
||||
"SELECT '\'';",
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
array(
|
||||
"SELECT \\",
|
||||
[
|
||||
'SELECT \\',
|
||||
8,
|
||||
array(
|
||||
[
|
||||
'parse_delimiter' => false,
|
||||
'add_delimiter' => false,
|
||||
),
|
||||
array(
|
||||
"SELECT \\",
|
||||
),
|
||||
),
|
||||
],
|
||||
['SELECT \\'],
|
||||
],
|
||||
|
||||
array(
|
||||
[
|
||||
"CREATE TABLE `test` (\n" .
|
||||
" `txt` varchar(10)\n" .
|
||||
");\n" .
|
||||
@@ -133,58 +141,58 @@ class BufferedQueryTest extends TestCase
|
||||
"INSERT INTO `test` (`txt`) VALUES('\\\\');\n" .
|
||||
"INSERT INTO `test` (`txt`) VALUES('xyz');\n",
|
||||
8,
|
||||
array(
|
||||
[
|
||||
'parse_delimiter' => true,
|
||||
'add_delimiter' => true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
"CREATE TABLE `test` (\n" .
|
||||
" `txt` varchar(10)\n" .
|
||||
');',
|
||||
"INSERT INTO `test` (`txt`) VALUES('abc');",
|
||||
"INSERT INTO `test` (`txt`) VALUES('\\\\');",
|
||||
"INSERT INTO `test` (`txt`) VALUES('xyz');",
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
array(
|
||||
[
|
||||
'SELECT """""""";' .
|
||||
'SELECT """\\\\"""',
|
||||
8,
|
||||
array(
|
||||
[
|
||||
'parse_delimiter' => true,
|
||||
'add_delimiter' => true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'SELECT """""""";',
|
||||
'SELECT """\\\\"""',
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
array(
|
||||
[
|
||||
'DELIMITER A_VERY_LONG_DEL' . "\n" .
|
||||
'SELECT 1 A_VERY_LONG_DEL' . "\n" .
|
||||
'DELIMITER ;',
|
||||
3,
|
||||
array(
|
||||
[
|
||||
'parse_delimiter' => true,
|
||||
'add_delimiter' => true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'DELIMITER A_VERY_LONG_DEL',
|
||||
'SELECT 1 A_VERY_LONG_DEL',
|
||||
'DELIMITER ;',
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
array(
|
||||
[
|
||||
$query,
|
||||
32,
|
||||
array(
|
||||
[
|
||||
'parse_delimiter' => false,
|
||||
'add_delimiter' => false,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */',
|
||||
|
||||
'/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */',
|
||||
@@ -198,7 +206,8 @@ class BufferedQueryTest extends TestCase
|
||||
'SET time_zone = "+00:00"',
|
||||
|
||||
'# Bash-like comment sytanx.' . "\n" .
|
||||
'CREATE DEFINER=`root`@`localhost` PROCEDURE `film_in_stock` (IN `p_film_id` INT, IN `p_store_id` INT, OUT `p_film_count` INT) READS SQL DATA' . "\n" .
|
||||
'CREATE DEFINER=`root`@`localhost` PROCEDURE `film_in_stock` (IN `p_film_id` ' .
|
||||
'INT, IN `p_store_id` INT, OUT `p_film_count` INT) READS SQL DATA' . "\n" .
|
||||
'BEGIN' . "\n" .
|
||||
' SELECT inventory_id' . "\n" .
|
||||
' FROM inventory' . "\n" .
|
||||
@@ -228,17 +237,17 @@ class BufferedQueryTest extends TestCase
|
||||
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */',
|
||||
|
||||
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
array(
|
||||
[
|
||||
$query,
|
||||
32,
|
||||
array(
|
||||
[
|
||||
'parse_delimiter' => true,
|
||||
'add_delimiter' => false,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */',
|
||||
|
||||
'/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */',
|
||||
@@ -254,7 +263,8 @@ class BufferedQueryTest extends TestCase
|
||||
'/* a comment */ DELIMITER $$',
|
||||
|
||||
'# Bash-like comment sytanx.' . "\n" .
|
||||
'CREATE DEFINER=`root`@`localhost` PROCEDURE `film_in_stock` (IN `p_film_id` INT, IN `p_store_id` INT, OUT `p_film_count` INT) READS SQL DATA' . "\n" .
|
||||
'CREATE DEFINER=`root`@`localhost` PROCEDURE `film_in_stock` (IN `p_film_id` ' .
|
||||
'INT, IN `p_store_id` INT, OUT `p_film_count` INT) READS SQL DATA' . "\n" .
|
||||
'BEGIN' . "\n" .
|
||||
' SELECT inventory_id' . "\n" .
|
||||
' FROM inventory' . "\n" .
|
||||
@@ -286,17 +296,17 @@ class BufferedQueryTest extends TestCase
|
||||
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */',
|
||||
|
||||
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
array(
|
||||
[
|
||||
$query,
|
||||
64,
|
||||
array(
|
||||
[
|
||||
'parse_delimiter' => false,
|
||||
'add_delimiter' => true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;',
|
||||
|
||||
'/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;',
|
||||
@@ -310,7 +320,8 @@ class BufferedQueryTest extends TestCase
|
||||
'SET time_zone = "+00:00";',
|
||||
|
||||
'# Bash-like comment sytanx.' . "\n" .
|
||||
'CREATE DEFINER=`root`@`localhost` PROCEDURE `film_in_stock` (IN `p_film_id` INT, IN `p_store_id` INT, OUT `p_film_count` INT) READS SQL DATA' . "\n" .
|
||||
'CREATE DEFINER=`root`@`localhost` PROCEDURE `film_in_stock` (IN `p_film_id` ' .
|
||||
'INT, IN `p_store_id` INT, OUT `p_film_count` INT) READS SQL DATA' . "\n" .
|
||||
'BEGIN' . "\n" .
|
||||
' SELECT inventory_id' . "\n" .
|
||||
' FROM inventory' . "\n" .
|
||||
@@ -340,8 +351,8 @@ class BufferedQueryTest extends TestCase
|
||||
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;',
|
||||
|
||||
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
+248
-217
@@ -1,24 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Tests\TestCase;
|
||||
use PhpMyAdmin\SqlParser\Utils\CLI;
|
||||
|
||||
use function dirname;
|
||||
use function exec;
|
||||
|
||||
use const PHP_BINARY;
|
||||
|
||||
class CLITest extends TestCase
|
||||
{
|
||||
private function getCLI($getopt)
|
||||
/**
|
||||
* @param array<string, bool|string>|false $getopt
|
||||
*/
|
||||
private function getCLI($getopt): CLI
|
||||
{
|
||||
$cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(array('getopt'))->getMock();
|
||||
$cli = $this->createPartialMock(CLI::class, ['getopt']);
|
||||
$cli->method('getopt')->willReturn($getopt);
|
||||
|
||||
return $cli;
|
||||
}
|
||||
|
||||
private function getCLIStdIn($input, $getopt)
|
||||
/**
|
||||
* @param array<string, bool|string>|false $getopt
|
||||
*/
|
||||
private function getCLIStdIn(string $input, $getopt): CLI
|
||||
{
|
||||
$cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(array('getopt', 'readStdin'))->getMock();
|
||||
$cli = $this->createPartialMock(CLI::class, ['getopt', 'readStdin']);
|
||||
$cli->method('getopt')->willReturn($getopt);
|
||||
$cli->method('readStdin')->willReturn($input);
|
||||
|
||||
return $cli;
|
||||
}
|
||||
|
||||
@@ -27,425 +42,441 @@ class CLITest extends TestCase
|
||||
*
|
||||
* We do mock it for other tests to return values we want.
|
||||
*/
|
||||
public function testGetopt()
|
||||
public function testGetopt(): void
|
||||
{
|
||||
$cli = new \PhpMyAdmin\SqlParser\Utils\CLI();
|
||||
$cli = new CLI();
|
||||
$this->assertEquals(
|
||||
$cli->getopt('', array()),
|
||||
array()
|
||||
$cli->getopt('', []),
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider highlightParams
|
||||
* @param array<string, bool|string>|false $getopt
|
||||
*
|
||||
* @param mixed $getopt
|
||||
* @param mixed $output
|
||||
* @param mixed $result
|
||||
* @dataProvider highlightParamsProvider
|
||||
*/
|
||||
public function testRunHighlight($getopt, $output, $result)
|
||||
public function testRunHighlight($getopt, string $output, int $result): void
|
||||
{
|
||||
$cli = $this->getCLI($getopt);
|
||||
$this->expectOutputString($output);
|
||||
$this->assertEquals($result, $cli->runHighlight());
|
||||
}
|
||||
|
||||
public function highlightParams()
|
||||
/**
|
||||
* @return array<int, array<int, int|string|array<string, bool|string>|false>>
|
||||
* @psalm-return list<array{(array<string, bool|string>|false), string, int}>
|
||||
*/
|
||||
public function highlightParamsProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('q' => 'SELECT 1'),
|
||||
return [
|
||||
[
|
||||
['q' => 'SELECT 1'],
|
||||
"\x1b[35mSELECT\n \x1b[92m1\x1b[0m\n",
|
||||
0
|
||||
),
|
||||
array(
|
||||
array('query' => 'SELECT 1'),
|
||||
0,
|
||||
],
|
||||
[
|
||||
['query' => 'SELECT 1'],
|
||||
"\x1b[35mSELECT\n \x1b[92m1\x1b[0m\n",
|
||||
0
|
||||
),
|
||||
array(
|
||||
array(
|
||||
0,
|
||||
],
|
||||
[
|
||||
[
|
||||
'q' => 'SELECT /* comment */ 1 /* other */',
|
||||
'f' => 'text',
|
||||
),
|
||||
],
|
||||
"SELECT\n /* comment */ 1 /* other */\n",
|
||||
0
|
||||
),
|
||||
array(
|
||||
array(
|
||||
0,
|
||||
],
|
||||
[
|
||||
[
|
||||
'q' => 'SELECT 1',
|
||||
'f' => 'foo',
|
||||
),
|
||||
],
|
||||
"ERROR: Invalid value for format!\n",
|
||||
1
|
||||
),
|
||||
array(
|
||||
array(
|
||||
1,
|
||||
],
|
||||
[
|
||||
[
|
||||
'q' => 'SELECT 1',
|
||||
'f' => 'html',
|
||||
),
|
||||
'<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
],
|
||||
'<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' <span class="sql-number">1</span>' . "\n",
|
||||
0
|
||||
),
|
||||
array(
|
||||
array('h' => true),
|
||||
0,
|
||||
],
|
||||
[
|
||||
['h' => true],
|
||||
'Usage: highlight-query --query SQL [--format html|cli|text] [--ansi]' . "\n" .
|
||||
' cat file.sql | highlight-query' . "\n",
|
||||
0
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
0,
|
||||
],
|
||||
[
|
||||
[],
|
||||
'ERROR: Missing parameters!' . "\n" .
|
||||
'Usage: highlight-query --query SQL [--format html|cli|text] [--ansi]' . "\n" .
|
||||
' cat file.sql | highlight-query' . "\n",
|
||||
1,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
false,
|
||||
'',
|
||||
1
|
||||
)
|
||||
);
|
||||
1,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider highlightParamsStdIn
|
||||
* @param array<string, bool|string>|false $getopt
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param mixed $getopt
|
||||
* @param mixed $output
|
||||
* @param mixed $result
|
||||
* @dataProvider highlightParamsStdInProvider
|
||||
*/
|
||||
public function testRunHighlightStdIn($input, $getopt, $output, $result)
|
||||
public function testRunHighlightStdIn(string $input, $getopt, string $output, int $result): void
|
||||
{
|
||||
$cli = $this->getCLIStdIn($input, $getopt);
|
||||
$this->expectOutputString($output);
|
||||
$this->assertEquals($result, $cli->runHighlight());
|
||||
}
|
||||
|
||||
public function highlightParamsStdIn()
|
||||
/**
|
||||
* @return array<int, array<int, int|string|array<string, bool|string>|false>>
|
||||
* @psalm-return list<array{string, (array<string, bool|string>|false), string, int}>
|
||||
*/
|
||||
public function highlightParamsStdInProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'SELECT 1',
|
||||
array(),
|
||||
[],
|
||||
"\x1b[35mSELECT\n \x1b[92m1\x1b[0m\n",
|
||||
0
|
||||
),
|
||||
array(
|
||||
0,
|
||||
],
|
||||
[
|
||||
'SELECT /* comment */ 1 /* other */',
|
||||
array(
|
||||
'f' => 'text',
|
||||
),
|
||||
['f' => 'text'],
|
||||
"SELECT\n /* comment */ 1 /* other */\n",
|
||||
0
|
||||
),
|
||||
array(
|
||||
0,
|
||||
],
|
||||
[
|
||||
'SELECT 1',
|
||||
array(
|
||||
'f' => 'foo',
|
||||
),
|
||||
['f' => 'foo'],
|
||||
"ERROR: Invalid value for format!\n",
|
||||
1
|
||||
),
|
||||
array(
|
||||
1,
|
||||
],
|
||||
[
|
||||
'SELECT 1',
|
||||
array(
|
||||
'f' => 'html',
|
||||
),
|
||||
'<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
['f' => 'html'],
|
||||
'<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' <span class="sql-number">1</span>' . "\n",
|
||||
0
|
||||
),
|
||||
array(
|
||||
0,
|
||||
],
|
||||
[
|
||||
'',
|
||||
array('h' => true),
|
||||
['h' => true],
|
||||
'Usage: highlight-query --query SQL [--format html|cli|text] [--ansi]' . "\n" .
|
||||
' cat file.sql | highlight-query' . "\n",
|
||||
0
|
||||
),
|
||||
array(
|
||||
0,
|
||||
],
|
||||
[
|
||||
'',
|
||||
array(),
|
||||
[],
|
||||
'ERROR: Missing parameters!' . "\n" .
|
||||
'Usage: highlight-query --query SQL [--format html|cli|text] [--ansi]' . "\n" .
|
||||
' cat file.sql | highlight-query' . "\n",
|
||||
1,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
1
|
||||
)
|
||||
);
|
||||
1,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider lintParamsStdIn
|
||||
* @param array<string, bool|string>|false $getopt
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param mixed $getopt
|
||||
* @param mixed $output
|
||||
* @param mixed $result
|
||||
* @dataProvider lintParamsStdInProvider
|
||||
*/
|
||||
public function testRunLintFromStdIn($input, $getopt, $output, $result)
|
||||
public function testRunLintFromStdIn(string $input, $getopt, string $output, int $result): void
|
||||
{
|
||||
$cli = $this->getCLIStdIn($input, $getopt);
|
||||
$this->expectOutputString($output);
|
||||
$this->assertEquals($result, $cli->runLint());
|
||||
}
|
||||
|
||||
public function lintParamsStdIn()
|
||||
/**
|
||||
* @return array<int, array<int, int|string|array<string, bool|string>|false>>
|
||||
* @psalm-return list<array{string, (array<string, bool|string>|false), string, int}>
|
||||
*/
|
||||
public function lintParamsStdInProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'SELECT 1',
|
||||
array(),
|
||||
[],
|
||||
'',
|
||||
0,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'SELECT SELECT',
|
||||
array(),
|
||||
[],
|
||||
'#1: An expression was expected. (near "SELECT" at position 7)' . "\n" .
|
||||
'#2: This type of clause was previously parsed. (near "SELECT" at position 7)' . "\n" .
|
||||
'#3: An expression was expected. (near "" at position 0)' . "\n",
|
||||
10,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'SELECT SELECT',
|
||||
array('c' => 'MySql80000'),
|
||||
['c' => 'MySql80000'],
|
||||
'#1: An expression was expected. (near "SELECT" at position 7)' . "\n" .
|
||||
'#2: This type of clause was previously parsed. (near "SELECT" at position 7)' . "\n" .
|
||||
'#3: An expression was expected. (near "" at position 0)' . "\n",
|
||||
10,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'',
|
||||
array(),
|
||||
[],
|
||||
'ERROR: Missing parameters!' . "\n" .
|
||||
'Usage: lint-query --query SQL [--ansi]' . "\n" .
|
||||
' cat file.sql | lint-query' . "\n",
|
||||
1,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'',
|
||||
array('h' => true),
|
||||
['h' => true],
|
||||
'Usage: lint-query --query SQL [--ansi]' . "\n" .
|
||||
' cat file.sql | lint-query' . "\n",
|
||||
0,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
1,
|
||||
)
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider lintParams
|
||||
* @param array<string, bool|string>|false $getopt
|
||||
*
|
||||
* @param mixed $getopt
|
||||
* @param mixed $output
|
||||
* @param mixed $result
|
||||
* @dataProvider lintParamsProvider
|
||||
*/
|
||||
public function testRunLint($getopt, $output, $result)
|
||||
public function testRunLint($getopt, string $output, int $result): void
|
||||
{
|
||||
$cli = $this->getCLI($getopt);
|
||||
$this->expectOutputString($output);
|
||||
$this->assertEquals($result, $cli->runLint());
|
||||
}
|
||||
|
||||
public function lintParams()
|
||||
/**
|
||||
* @return array<int, array<int, int|string|array<string, bool|string>|false>>
|
||||
* @psalm-return list<array{(array<string, bool|string>|false), string, int}>
|
||||
*/
|
||||
public function lintParamsProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('q' => 'SELECT 1'),
|
||||
return [
|
||||
[
|
||||
['q' => 'SELECT 1'],
|
||||
'',
|
||||
0,
|
||||
),
|
||||
array(
|
||||
array('query' => 'SELECT 1'),
|
||||
],
|
||||
[
|
||||
['query' => 'SELECT 1'],
|
||||
'',
|
||||
0,
|
||||
),
|
||||
array(
|
||||
array('q' => 'SELECT SELECT'),
|
||||
],
|
||||
[
|
||||
['q' => 'SELECT SELECT'],
|
||||
'#1: An expression was expected. (near "SELECT" at position 7)' . "\n" .
|
||||
'#2: This type of clause was previously parsed. (near "SELECT" at position 7)' . "\n" .
|
||||
'#3: An expression was expected. (near "" at position 0)' . "\n",
|
||||
10,
|
||||
),
|
||||
array(
|
||||
array('q' => 'SELECT SELECT', 'c' => 'MySql80000'),
|
||||
],
|
||||
[
|
||||
[
|
||||
'q' => 'SELECT SELECT',
|
||||
'c' => 'MySql80000',
|
||||
],
|
||||
'#1: An expression was expected. (near "SELECT" at position 7)' . "\n" .
|
||||
'#2: This type of clause was previously parsed. (near "SELECT" at position 7)' . "\n" .
|
||||
'#3: An expression was expected. (near "" at position 0)' . "\n",
|
||||
10,
|
||||
),
|
||||
array(
|
||||
array('h' => true),
|
||||
],
|
||||
[
|
||||
['h' => true],
|
||||
'Usage: lint-query --query SQL [--ansi]' . "\n" .
|
||||
' cat file.sql | lint-query' . "\n",
|
||||
0,
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
],
|
||||
[
|
||||
[],
|
||||
'ERROR: Missing parameters!' . "\n" .
|
||||
'Usage: lint-query --query SQL [--ansi]' . "\n" .
|
||||
' cat file.sql | lint-query' . "\n",
|
||||
1,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
false,
|
||||
'',
|
||||
1,
|
||||
)
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider tokenizeParams
|
||||
* @param array<string, bool|string>|false $getopt
|
||||
*
|
||||
* @param mixed $getopt
|
||||
* @param mixed $output
|
||||
* @param mixed $result
|
||||
* @dataProvider tokenizeParamsProvider
|
||||
*/
|
||||
public function testRunTokenize($getopt, $output, $result)
|
||||
public function testRunTokenize($getopt, string $output, int $result): void
|
||||
{
|
||||
$cli = $this->getCLI($getopt);
|
||||
$this->expectOutputString($output);
|
||||
$this->assertEquals($result, $cli->runTokenize());
|
||||
}
|
||||
|
||||
public function tokenizeParams()
|
||||
/**
|
||||
* @return array<int, array<int, int|string|array<string, bool|string>|false>>
|
||||
* @psalm-return list<array{(array<string, bool|string>|false), string, int}>
|
||||
*/
|
||||
public function tokenizeParamsProvider(): array
|
||||
{
|
||||
$result = (
|
||||
"[TOKEN 0]\nType = 1\nFlags = 3\nValue = 'SELECT'\nToken = 'SELECT'\n\n"
|
||||
$result = "[TOKEN 0]\nType = 1\nFlags = 3\nValue = 'SELECT'\nToken = 'SELECT'\n\n"
|
||||
. "[TOKEN 1]\nType = 3\nFlags = 0\nValue = ' '\nToken = ' '\n\n"
|
||||
. "[TOKEN 2]\nType = 6\nFlags = 0\nValue = 1\nToken = '1'\n\n"
|
||||
. "[TOKEN 3]\nType = 9\nFlags = 0\nValue = NULL\nToken = NULL\n\n"
|
||||
);
|
||||
. "[TOKEN 3]\nType = 9\nFlags = 0\nValue = NULL\nToken = NULL\n\n";
|
||||
|
||||
return array(
|
||||
array(
|
||||
array('q' => 'SELECT 1'),
|
||||
return [
|
||||
[
|
||||
['q' => 'SELECT 1'],
|
||||
$result,
|
||||
0,
|
||||
),
|
||||
array(
|
||||
array('query' => 'SELECT 1'),
|
||||
],
|
||||
[
|
||||
['query' => 'SELECT 1'],
|
||||
$result,
|
||||
0,
|
||||
),
|
||||
array(
|
||||
array('h' => true),
|
||||
],
|
||||
[
|
||||
['h' => true],
|
||||
'Usage: tokenize-query --query SQL [--ansi]' . "\n" .
|
||||
' cat file.sql | tokenize-query' . "\n",
|
||||
0,
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
],
|
||||
[
|
||||
[],
|
||||
'ERROR: Missing parameters!' . "\n" .
|
||||
'Usage: tokenize-query --query SQL [--ansi]' . "\n" .
|
||||
' cat file.sql | tokenize-query' . "\n",
|
||||
1,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
false,
|
||||
'',
|
||||
1,
|
||||
)
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider tokenizeParamsStdIn
|
||||
* @param array<string, bool|string>|false $getopt
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param mixed $getopt
|
||||
* @param mixed $output
|
||||
* @param mixed $result
|
||||
* @dataProvider tokenizeParamsStdInProvider
|
||||
*/
|
||||
public function testRunTokenizeStdIn($input, $getopt, $output, $result)
|
||||
public function testRunTokenizeStdIn(string $input, $getopt, string $output, int $result): void
|
||||
{
|
||||
$cli = $this->getCLIStdIn($input, $getopt);
|
||||
$this->expectOutputString($output);
|
||||
$this->assertEquals($result, $cli->runTokenize());
|
||||
}
|
||||
|
||||
public function tokenizeParamsStdIn()
|
||||
/**
|
||||
* @return array<int, array<int, int|string|array<string, bool|string>|false>>
|
||||
* @psalm-return list<array{string, (array<string, bool|string>|false), string, int}>
|
||||
*/
|
||||
public function tokenizeParamsStdInProvider(): array
|
||||
{
|
||||
$result = (
|
||||
"[TOKEN 0]\nType = 1\nFlags = 3\nValue = 'SELECT'\nToken = 'SELECT'\n\n"
|
||||
$result = "[TOKEN 0]\nType = 1\nFlags = 3\nValue = 'SELECT'\nToken = 'SELECT'\n\n"
|
||||
. "[TOKEN 1]\nType = 3\nFlags = 0\nValue = ' '\nToken = ' '\n\n"
|
||||
. "[TOKEN 2]\nType = 6\nFlags = 0\nValue = 1\nToken = '1'\n\n"
|
||||
. "[TOKEN 3]\nType = 9\nFlags = 0\nValue = NULL\nToken = NULL\n\n"
|
||||
);
|
||||
. "[TOKEN 3]\nType = 9\nFlags = 0\nValue = NULL\nToken = NULL\n\n";
|
||||
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'SELECT 1',
|
||||
array(),
|
||||
[],
|
||||
$result,
|
||||
0,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'',
|
||||
array('h' => true),
|
||||
['h' => true],
|
||||
'Usage: tokenize-query --query SQL [--ansi]' . "\n" .
|
||||
' cat file.sql | tokenize-query' . "\n",
|
||||
0,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'',
|
||||
array(),
|
||||
[],
|
||||
'ERROR: Missing parameters!' . "\n" .
|
||||
'Usage: tokenize-query --query SQL [--ansi]' . "\n" .
|
||||
' cat file.sql | tokenize-query' . "\n",
|
||||
1,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
1,
|
||||
)
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stdinParams
|
||||
*
|
||||
* @param string $cmd
|
||||
* @param int $result
|
||||
* @dataProvider stdinParamsProvider
|
||||
*/
|
||||
public function testStdinPipe($cmd, $result)
|
||||
public function testStdinPipe(string $cmd, int $result): void
|
||||
{
|
||||
exec ($cmd, $out, $ret);
|
||||
exec($cmd, $out, $ret);
|
||||
$this->assertSame($result, $ret);
|
||||
}
|
||||
|
||||
public function stdinParams()
|
||||
/**
|
||||
* @return array<int, array<int, int|string>>
|
||||
* @psalm-return list<array{string, int}>
|
||||
*/
|
||||
public function stdinParamsProvider(): array
|
||||
{
|
||||
if (defined('PHP_BINARY')) {
|
||||
$binPath = PHP_BINARY . ' ' . realpath(dirname(__DIR__) . '/../') . '/bin/';
|
||||
} else {
|
||||
$binPath = 'php' . ' ' . realpath(dirname(__DIR__) . '/../') . '/bin/';
|
||||
}
|
||||
$binPath = PHP_BINARY . ' ' . dirname(__DIR__, 2) . '/bin/';
|
||||
|
||||
return array(
|
||||
array('echo "SELECT 1" | '. $binPath .'highlight-query', 0),
|
||||
array('echo "invalid query" | '. $binPath .'highlight-query', 0),
|
||||
array('echo "SELECT 1" | '. $binPath .'lint-query', 0),
|
||||
array('echo "invalid query" | '. $binPath .'lint-query', 10),
|
||||
array('echo "SELECT 1" | '. $binPath .'tokenize-query', 0),
|
||||
array('echo "invalid query" | '. $binPath .'tokenize-query', 0)
|
||||
);
|
||||
return [
|
||||
[
|
||||
'echo "SELECT 1" | ' . $binPath . 'highlight-query',
|
||||
0,
|
||||
],
|
||||
[
|
||||
'echo "invalid query" | ' . $binPath . 'highlight-query',
|
||||
0,
|
||||
],
|
||||
[
|
||||
'echo "SELECT 1" | ' . $binPath . 'lint-query',
|
||||
0,
|
||||
],
|
||||
[
|
||||
'echo "invalid query" | ' . $binPath . 'lint-query',
|
||||
10,
|
||||
],
|
||||
[
|
||||
'echo "SELECT 1" | ' . $binPath . 'tokenize-query',
|
||||
0,
|
||||
],
|
||||
[
|
||||
'echo "invalid query" | ' . $binPath . 'tokenize-query',
|
||||
0,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Lexer;
|
||||
@@ -9,38 +11,55 @@ use PhpMyAdmin\SqlParser\Utils\Error;
|
||||
|
||||
class ErrorTest extends TestCase
|
||||
{
|
||||
public function testGet()
|
||||
public function testGet(): void
|
||||
{
|
||||
$lexer = new Lexer('SELECT * FROM db..tbl }');
|
||||
$parser = new Parser($lexer->list);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array(
|
||||
[
|
||||
[
|
||||
'Unexpected character.',
|
||||
0,
|
||||
'}',
|
||||
22,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'Unexpected dot.',
|
||||
0,
|
||||
'.',
|
||||
17,
|
||||
),
|
||||
),
|
||||
Error::get(array($lexer, $parser))
|
||||
],
|
||||
],
|
||||
Error::get([$lexer, $parser])
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormat()
|
||||
public function testGetWithNullToken(): void
|
||||
{
|
||||
$lexer = new Lexer('LOCK TABLES table1 AS `t1` LOCAL');
|
||||
$parser = new Parser($lexer->list);
|
||||
$this->assertSame(
|
||||
[
|
||||
['An alias was previously found.', 0, 'LOCAL', 27],
|
||||
['Unexpected keyword.', 0, 'LOCAL', 27],
|
||||
['Unexpected end of LOCK expression.', 0, '', null],
|
||||
],
|
||||
Error::get([$lexer, $parser])
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormat(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
array('#1: error msg (near "token" at position 100)'),
|
||||
Error::format(array(array('error msg', 42, 'token', 100)))
|
||||
['#1: error msg (near "token" at position 100)'],
|
||||
Error::format([['error msg', 42, 'token', 100]])
|
||||
);
|
||||
$this->assertEquals(
|
||||
array('#1: error msg (near "token" at position 100)', '#2: error msg (near "token" at position 200)'),
|
||||
Error::format(array(array('error msg', 42, 'token', 100), array('error msg', 42, 'token', 200)))
|
||||
[
|
||||
'#1: error msg (near "token" at position 100)',
|
||||
'#2: error msg (near "token" at position 200)',
|
||||
],
|
||||
Error::format([['error msg', 42, 'token', 100], ['error msg', 42, 'token', 200]])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+355
-294
@@ -1,276 +1,306 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Tests\TestCase;
|
||||
use PhpMyAdmin\SqlParser\Utils\Formatter;
|
||||
use ReflectionMethod;
|
||||
|
||||
class FormatterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider mergeFormats
|
||||
* @param array<int, array<string, int|string>> $default
|
||||
* @param array<int, array<string, int|string>> $overriding
|
||||
* @param array<int, array<string, int|string>> $expected
|
||||
* @psalm-param list<array{type: int, flags: int, html: string, cli: string, function?: string}> $default
|
||||
* @psalm-param list<array{type?: int, flags?: int, html?: string, cli?: string, function?: string}> $overriding
|
||||
* @psalm-param list<array{type: int, flags: int, html: string, cli: string, function?: string}> $expected
|
||||
*
|
||||
* @param mixed $default
|
||||
* @param mixed $overriding
|
||||
* @param mixed $expected
|
||||
* @dataProvider mergeFormatsProvider
|
||||
*/
|
||||
public function testMergeFormats($default, $overriding, $expected)
|
||||
public function testMergeFormats(array $default, array $overriding, array $expected): void
|
||||
{
|
||||
$formatter = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\Formatter')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getDefaultOptions', 'getDefaultFormats'))
|
||||
->getMock();
|
||||
$formatter = $this->createPartialMock(Formatter::class, ['getDefaultOptions', 'getDefaultFormats']);
|
||||
|
||||
$formatter->expects($this->once())
|
||||
->method('getDefaultOptions')
|
||||
->willReturn(array(
|
||||
->willReturn([
|
||||
'type' => 'text',
|
||||
'line_ending' => null,
|
||||
'indentation' => null,
|
||||
'clause_newline' => null,
|
||||
'parts_newline' => null
|
||||
));
|
||||
'parts_newline' => null,
|
||||
]);
|
||||
|
||||
$formatter->expects($this->once())
|
||||
->method('getDefaultFormats')
|
||||
->willReturn($default);
|
||||
|
||||
$expectedOptions = array(
|
||||
$expectedOptions = [
|
||||
'type' => 'test-type',
|
||||
'line_ending' => '<br>',
|
||||
'indentation' => ' ',
|
||||
'clause_newline' => null,
|
||||
'parts_newline' => 0,
|
||||
'formats' => $expected
|
||||
);
|
||||
'formats' => $expected,
|
||||
];
|
||||
|
||||
$overridingOptions = array(
|
||||
$overridingOptions = [
|
||||
'type' => 'test-type',
|
||||
'line_ending' => '<br>',
|
||||
'formats' => $overriding
|
||||
);
|
||||
'formats' => $overriding,
|
||||
];
|
||||
|
||||
$reflectionMethod = new \ReflectionMethod($formatter, 'getMergedOptions');
|
||||
$reflectionMethod = new ReflectionMethod($formatter, 'getMergedOptions');
|
||||
$reflectionMethod->setAccessible(true);
|
||||
$this->assertEquals($expectedOptions, $reflectionMethod->invoke($formatter, $overridingOptions));
|
||||
}
|
||||
|
||||
public function mergeFormats()
|
||||
/**
|
||||
* @return array<string, array<string, array<int, array<string, int|string>>>>
|
||||
* @psalm-return array<string, array{
|
||||
* default: list<array{type: int, flags: int, html: string, cli: string, function?: string}>,
|
||||
* overriding: list<array{type?: int, flags?: int, html?: string, cli?: string, function?: string}>,
|
||||
* expected: list<array{type: int, flags: int, html: string, cli: string, function?: string}>
|
||||
* }>
|
||||
*/
|
||||
public function mergeFormatsProvider(): array
|
||||
{
|
||||
// array($default[], $overriding[], $expected[])
|
||||
return array(
|
||||
'empty formats' => array(
|
||||
'default' => array(
|
||||
array(
|
||||
// [default[], overriding[], expected[]]
|
||||
return [
|
||||
'empty formats' => [
|
||||
'default' => [
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 0,
|
||||
'html' => '',
|
||||
'cli' => '',
|
||||
'function' => '',
|
||||
),
|
||||
),
|
||||
'overriding' => array(
|
||||
array(),
|
||||
),
|
||||
'expected' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'overriding' => [
|
||||
[],
|
||||
],
|
||||
'expected' => [
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 0,
|
||||
'html' => '',
|
||||
'cli' => '',
|
||||
'function' => '',
|
||||
),
|
||||
),
|
||||
),
|
||||
'no flags' => array(
|
||||
'default' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
'no flags' => [
|
||||
'default' => [
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 0,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 1,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
),
|
||||
'overriding' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'overriding' => [
|
||||
[
|
||||
'type' => 0,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
),
|
||||
),
|
||||
'expected' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'expected' => [
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 0,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
'function' => '',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 1,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
),
|
||||
),
|
||||
'with flags' => array(
|
||||
'default' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
'with flags' => [
|
||||
'default' => [
|
||||
[
|
||||
'type' => -1,
|
||||
'flags' => 0,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 0,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 1,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
),
|
||||
'overriding' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'overriding' => [
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 0,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
),
|
||||
),
|
||||
'expected' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'expected' => [
|
||||
[
|
||||
'type' => -1,
|
||||
'flags' => 0,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 0,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
'function' => '',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 1,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
),
|
||||
),
|
||||
'with extra formats' => array(
|
||||
'default' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
'with extra formats' => [
|
||||
'default' => [
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 0,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
),
|
||||
'overriding' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'overriding' => [
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 1,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 1,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 1,
|
||||
'flags' => 1,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
),
|
||||
),
|
||||
'expected' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'expected' => [
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 0,
|
||||
'html' => 'html',
|
||||
'cli' => 'cli',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 0,
|
||||
'flags' => 1,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
'function' => '',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 1,
|
||||
'flags' => 0,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
'function' => '',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'type' => 1,
|
||||
'flags' => 1,
|
||||
'html' => 'new html',
|
||||
'cli' => 'new cli',
|
||||
'function' => '',
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, bool> $options
|
||||
*
|
||||
* @dataProvider formatQueriesProviders
|
||||
*/
|
||||
public function testFormat(string $query, string $text, string $cli, string $html, array $options = []): void
|
||||
{
|
||||
// Test TEXT format
|
||||
$this->assertEquals(
|
||||
$text,
|
||||
Formatter::format($query, ['type' => 'text'] + $options),
|
||||
'Text formatting failed.'
|
||||
);
|
||||
|
||||
// Test CLI format
|
||||
$this->assertEquals(
|
||||
$cli,
|
||||
Formatter::format($query, ['type' => 'cli'] + $options),
|
||||
'CLI formatting failed.'
|
||||
);
|
||||
|
||||
// Test HTML format
|
||||
$this->assertEquals(
|
||||
$html,
|
||||
Formatter::format($query, ['type' => 'html'] + $options),
|
||||
'HTML formatting failed.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider formatQueries
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param mixed $text
|
||||
* @param mixed $cli
|
||||
* @param mixed $html
|
||||
* @return array<string, array<string, string|array<string, string|bool>>>
|
||||
* @psalm-return array<string, array{
|
||||
* query: string,
|
||||
* text: string,
|
||||
* cli: string,
|
||||
* html: string,
|
||||
* options?: array<string, bool>
|
||||
* }>
|
||||
*/
|
||||
public function testFormat($query, $text, $cli, $html, array $options = array())
|
||||
public function formatQueriesProviders(): array
|
||||
{
|
||||
// Test TEXT format
|
||||
$this->assertEquals($text, Formatter::format($query, array('type' => 'text') + $options), 'Text formatting failed.');
|
||||
|
||||
// Test CLI format
|
||||
$this->assertEquals($cli, Formatter::format($query, array('type' => 'cli') + $options), 'CLI formatting failed.');
|
||||
|
||||
// Test HTML format
|
||||
$this->assertEquals($html, Formatter::format($query, array('type' => 'html') + $options), 'HTML formatting failed.');
|
||||
}
|
||||
|
||||
public function formatQueries()
|
||||
{
|
||||
return array(
|
||||
'empty' => array(
|
||||
return [
|
||||
'empty' => [
|
||||
'query' => '',
|
||||
'text' => '',
|
||||
'cli' => "\x1b[0m",
|
||||
'html' => '',
|
||||
),
|
||||
'minimal' => array(
|
||||
],
|
||||
'minimal' => [
|
||||
'query' => 'select 1',
|
||||
'text' => 'SELECT' . "\n" .
|
||||
' 1',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[92m1" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[92m1\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' <span class="sql-number">1</span>',
|
||||
),
|
||||
'simply' => array(
|
||||
],
|
||||
'simply' => [
|
||||
'query' => 'select * from tbl where 1',
|
||||
'text' => 'SELECT' . "\n" .
|
||||
' *' . "\n" .
|
||||
@@ -278,21 +308,22 @@ class FormatterTest extends TestCase
|
||||
' tbl' . "\n" .
|
||||
'WHERE' . "\n" .
|
||||
' 1',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[39m*" . "\n" .
|
||||
"\x1b[35mFROM" . "\n" .
|
||||
" \x1b[39mtbl" . "\n" .
|
||||
"\x1b[35mWHERE" . "\n" .
|
||||
" \x1b[92m1" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
' *' . '<br/>' .
|
||||
'<span class="sql-reserved">FROM</span>' . '<br/>' .
|
||||
' tbl' . '<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[39m*\n" .
|
||||
"\x1b[35mFROM\n" .
|
||||
" \x1b[39mtbl\n" .
|
||||
"\x1b[35mWHERE\n" .
|
||||
" \x1b[92m1\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' *<br/>' .
|
||||
'<span class="sql-reserved">FROM</span><br/>' .
|
||||
' tbl<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span><br/>' .
|
||||
' <span class="sql-number">1</span>',
|
||||
),
|
||||
'typical' => array(
|
||||
'query' => 'SELECT id, if(id=1,"Si","No") from `tbl` where id = 0 or id = 1 group by id order by id desc limit 1 offset 0',
|
||||
],
|
||||
'typical' => [
|
||||
'query' => 'SELECT id, if(id=1,"Si","No") from `tbl` where id = 0 or ' .
|
||||
'id = 1 group by id order by id desc limit 1 offset 0',
|
||||
'text' => 'SELECT' . "\n" .
|
||||
' id,' . "\n" .
|
||||
' IF(id = 1, "Si", "No")' . "\n" .
|
||||
@@ -306,34 +337,38 @@ class FormatterTest extends TestCase
|
||||
' id' . "\n" .
|
||||
'DESC' . "\n" .
|
||||
'LIMIT 1 OFFSET 0',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[39mid," . "\n" .
|
||||
" \x1b[35mIF\x1b[39m(id = \x1b[92m1\x1b[39m, \x1b[91m\"Si\"\x1b[39m, \x1b[91m\"No\"\x1b[39m)" . "\n" .
|
||||
"\x1b[35mFROM" . "\n" .
|
||||
" \x1b[36m`tbl`" . "\n" .
|
||||
"\x1b[35mWHERE" . "\n" .
|
||||
" \x1b[39mid = \x1b[92m0 \x1b[35mOR \x1b[39mid = \x1b[92m1" . "\n" .
|
||||
"\x1b[35mGROUP BY" . "\n" .
|
||||
" \x1b[39mid" . "\n" .
|
||||
"\x1b[35mORDER BY" . "\n" .
|
||||
" \x1b[39mid" . "\n" .
|
||||
"\x1b[35mDESC" . "\n" .
|
||||
"LIMIT \x1b[92m1 \x1b[95mOFFSET \x1b[92m0" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
' id,' . '<br/>' .
|
||||
' <span class="sql-reserved">IF</span>(id = <span class="sql-number">1</span>, <span class="sql-string">"Si"</span>, <span class="sql-string">"No"</span>)' . '<br/>' .
|
||||
'<span class="sql-reserved">FROM</span>' . '<br/>' .
|
||||
' <span class="sql-variable">`tbl`</span>' . '<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
|
||||
' id = <span class="sql-number">0</span> <span class="sql-reserved">OR</span> id = <span class="sql-number">1</span>' . '<br/>' .
|
||||
'<span class="sql-reserved">GROUP BY</span>' . '<br/>' .
|
||||
' id' . '<br/>' .
|
||||
'<span class="sql-reserved">ORDER BY</span>' . '<br/>' .
|
||||
' id' . '<br/>' .
|
||||
'<span class="sql-reserved">DESC</span>' . '<br/>' .
|
||||
'<span class="sql-reserved">LIMIT</span> <span class="sql-number">1</span> <span class="sql-keyword">OFFSET</span> <span class="sql-number">0</span>',
|
||||
),
|
||||
'comments' => array(
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[39mid,\n" .
|
||||
" \x1b[35mIF\x1b[39m(id = \x1b[92m1\x1b[39m, \x1b[91m\"Si\"\x1b[39m, \x1b[91m\"No\"\x1b[39m)\n" .
|
||||
"\x1b[35mFROM\n" .
|
||||
" \x1b[36m`tbl`\n" .
|
||||
"\x1b[35mWHERE\n" .
|
||||
" \x1b[39mid = \x1b[92m0 \x1b[35mOR \x1b[39mid = \x1b[92m1\n" .
|
||||
"\x1b[35mGROUP BY\n" .
|
||||
" \x1b[39mid\n" .
|
||||
"\x1b[35mORDER BY\n" .
|
||||
" \x1b[39mid\n" .
|
||||
"\x1b[35mDESC\n" .
|
||||
"LIMIT \x1b[92m1 \x1b[95mOFFSET \x1b[92m0\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' id,<br/>' .
|
||||
' <span class="sql-reserved">IF</span>(id = ' .
|
||||
'<span class="sql-number">1</span>, <span class="sql-string">"Si"</span>, ' .
|
||||
'<span class="sql-string">"No"</span>)<br/>' .
|
||||
'<span class="sql-reserved">FROM</span><br/>' .
|
||||
' <span class="sql-variable">`tbl`</span><br/>' .
|
||||
'<span class="sql-reserved">WHERE</span><br/>' .
|
||||
' id = <span class="sql-number">0</span> ' .
|
||||
'<span class="sql-reserved">OR</span> id = <span class="sql-number">1</span><br/>' .
|
||||
'<span class="sql-reserved">GROUP BY</span><br/>' .
|
||||
' id<br/>' .
|
||||
'<span class="sql-reserved">ORDER BY</span><br/>' .
|
||||
' id<br/>' .
|
||||
'<span class="sql-reserved">DESC</span><br/>' .
|
||||
'<span class="sql-reserved">LIMIT</span> <span class="sql-number">1</span> ' .
|
||||
'<span class="sql-keyword">OFFSET</span> <span class="sql-number">0</span>',
|
||||
],
|
||||
'comments' => [
|
||||
'query' => 'select /* Comment */ *' . "\n" .
|
||||
'from tbl # Comment' . "\n" .
|
||||
'where 1 -- Comment',
|
||||
@@ -343,20 +378,21 @@ class FormatterTest extends TestCase
|
||||
' tbl # Comment' . "\n" .
|
||||
'WHERE' . "\n" .
|
||||
' 1 -- Comment',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[37m/* Comment */ \x1b[39m*" . "\n" .
|
||||
"\x1b[35mFROM" . "\n" .
|
||||
" \x1b[39mtbl \x1b[37m# Comment" . "\n" .
|
||||
"\x1b[35mWHERE" . "\n" .
|
||||
" \x1b[92m1 \x1b[37m-- Comment" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
' <span class="sql-comment">/* Comment */</span> *' . '<br/>' .
|
||||
'<span class="sql-reserved">FROM</span>' . '<br/>' .
|
||||
' tbl <span class="sql-comment"># Comment</span>' . '<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
|
||||
' <span class="sql-number">1</span> <span class="sql-comment">-- Comment</span>',
|
||||
),
|
||||
'strip comments' => array(
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[37m/* Comment */ \x1b[39m*\n" .
|
||||
"\x1b[35mFROM\n" .
|
||||
" \x1b[39mtbl \x1b[37m# Comment\n" .
|
||||
"\x1b[35mWHERE\n" .
|
||||
" \x1b[92m1 \x1b[37m-- Comment\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' <span class="sql-comment">/* Comment */</span> *<br/>' .
|
||||
'<span class="sql-reserved">FROM</span><br/>' .
|
||||
' tbl <span class="sql-comment"># Comment</span><br/>' .
|
||||
'<span class="sql-reserved">WHERE</span><br/>' .
|
||||
' <span class="sql-number">1</span> ' .
|
||||
'<span class="sql-comment">-- Comment</span>',
|
||||
],
|
||||
'strip comments' => [
|
||||
'query' => 'select /* Comment */ *' . "\n" .
|
||||
'from tbl # Comment' . "\n" .
|
||||
'where 1 -- Comment',
|
||||
@@ -366,41 +402,39 @@ class FormatterTest extends TestCase
|
||||
' tbl' . "\n" .
|
||||
'WHERE' . "\n" .
|
||||
' 1',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[39m*" . "\n" .
|
||||
"\x1b[35mFROM" . "\n" .
|
||||
" \x1b[39mtbl" . "\n" .
|
||||
"\x1b[35mWHERE" . "\n" .
|
||||
" \x1b[92m1" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
' *' . '<br/>' .
|
||||
'<span class="sql-reserved">FROM</span>' . '<br/>' .
|
||||
' tbl' . '<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[39m*\n" .
|
||||
"\x1b[35mFROM\n" .
|
||||
" \x1b[39mtbl\n" .
|
||||
"\x1b[35mWHERE\n" .
|
||||
" \x1b[92m1\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' *<br/>' .
|
||||
'<span class="sql-reserved">FROM</span><br/>' .
|
||||
' tbl<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span><br/>' .
|
||||
' <span class="sql-number">1</span>',
|
||||
'options' => array(
|
||||
'remove_comments' => true,
|
||||
),
|
||||
),
|
||||
'keywords' => array(
|
||||
'options' => ['remove_comments' => true],
|
||||
],
|
||||
'keywords' => [
|
||||
'query' => 'select hex("1")',
|
||||
'text' => 'SELECT' . "\n" .
|
||||
' HEX("1")',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[95mHEX\x1b[39m(\x1b[91m\"1\"\x1b[39m)" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[95mHEX\x1b[39m(\x1b[91m\"1\"\x1b[39m)\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' <span class="sql-keyword">HEX</span>(<span class="sql-string">"1"</span>)',
|
||||
),
|
||||
'distinct count' => array(
|
||||
],
|
||||
'distinct count' => [
|
||||
'query' => 'select distinct count(*)',
|
||||
'text' => 'SELECT DISTINCT' . "\n" .
|
||||
' COUNT(*)',
|
||||
'cli' => "\x1b[35mSELECT DISTINCT" . "\n" .
|
||||
" \x1b[95mCOUNT\x1b[39m(*)" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span> <span class="sql-reserved">DISTINCT</span>' . '<br/>' .
|
||||
'cli' => "\x1b[35mSELECT DISTINCT\n" .
|
||||
" \x1b[95mCOUNT\x1b[39m(*)\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span> <span class="sql-reserved">DISTINCT</span><br/>' .
|
||||
' <span class="sql-keyword">COUNT</span>(*)',
|
||||
),
|
||||
'create procedure' => array(
|
||||
],
|
||||
'create procedure' => [
|
||||
'query' => 'create procedure test_procedure() begin from tbl select *; end',
|
||||
'text' => 'CREATE PROCEDURE test_procedure()' . "\n" .
|
||||
'BEGIN' . "\n" .
|
||||
@@ -410,65 +444,72 @@ class FormatterTest extends TestCase
|
||||
' *;' . "\n" .
|
||||
'END',
|
||||
'cli' => "\x1b[35mCREATE PROCEDURE \x1b[39mtest_procedure()\n" .
|
||||
"\x1b[95mBEGIN" . "\n" .
|
||||
" \x1b[35mFROM" . "\n" .
|
||||
" \x1b[39mtbl" . "\n" .
|
||||
" \x1b[35mSELECT" . "\n" .
|
||||
"\x1b[95mBEGIN\n" .
|
||||
" \x1b[35mFROM\n" .
|
||||
" \x1b[39mtbl\n" .
|
||||
" \x1b[35mSELECT\n" .
|
||||
" \x1b[39m*;\n" .
|
||||
"\x1b[95mEND" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">CREATE</span> <span class="sql-reserved">PROCEDURE</span> test_procedure()' . '<br/>' .
|
||||
'<span class="sql-keyword">BEGIN</span>' . '<br/>' .
|
||||
' <span class="sql-reserved">FROM</span>' . '<br/>' .
|
||||
' tbl' . '<br/>' .
|
||||
' <span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
' *;' . '<br/>' .
|
||||
"\x1b[95mEND\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">CREATE</span> ' .
|
||||
'<span class="sql-reserved">PROCEDURE</span> test_procedure()<br/>' .
|
||||
'<span class="sql-keyword">BEGIN</span><br/>' .
|
||||
' <span class="sql-reserved">FROM</span><br/>' .
|
||||
' tbl<br/>' .
|
||||
' <span class="sql-reserved">SELECT</span><br/>' .
|
||||
' *;<br/>' .
|
||||
'<span class="sql-keyword">END</span>',
|
||||
),
|
||||
'insert' => array(
|
||||
],
|
||||
'insert' => [
|
||||
'query' => 'insert into foo values (0, 0, 0), (1, 1, 1)',
|
||||
'text' => 'INSERT INTO foo' . "\n" .
|
||||
'VALUES(0, 0, 0),(1, 1, 1)',
|
||||
'cli' => "\x1b[35mINSERT INTO \x1b[39mfoo" . "\n" .
|
||||
"\x1b[35mVALUES\x1b[39m(\x1b[92m0\x1b[39m, \x1b[92m0\x1b[39m, \x1b[92m0\x1b[39m),(\x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m)" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">INSERT</span> <span class="sql-reserved">INTO</span> foo' . '<br/>' .
|
||||
'<span class="sql-reserved">VALUES</span>(<span class="sql-number">0</span>, <span class="sql-number">0</span>, <span class="sql-number">0</span>),(<span class="sql-number">1</span>, <span class="sql-number">1</span>, <span class="sql-number">1</span>)',
|
||||
),
|
||||
'string as alias' => array(
|
||||
'cli' => "\x1b[35mINSERT INTO \x1b[39mfoo\n" .
|
||||
"\x1b[35mVALUES\x1b[39m(\x1b[92m0\x1b[39m, \x1b[92m0\x1b[39m, " .
|
||||
"\x1b[92m0\x1b[39m),(\x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m)\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">INSERT</span> <span class="sql-reserved">INTO</span> foo<br/>' .
|
||||
'<span class="sql-reserved">VALUES</span>(<span class="sql-number">0</span>, ' .
|
||||
'<span class="sql-number">0</span>, <span class="sql-number">0</span>),(' .
|
||||
'<span class="sql-number">1</span>, <span class="sql-number">1</span>, ' .
|
||||
'<span class="sql-number">1</span>)',
|
||||
],
|
||||
'string as alias' => [
|
||||
'query' => 'select "Text" as bar',
|
||||
'text' => 'SELECT' . "\n" .
|
||||
' "Text" AS bar',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[91m\"Text\" \x1b[35mAS \x1b[39mbar" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
' <span class="sql-string">"Text"</span> <span class="sql-reserved">AS</span> bar',
|
||||
),
|
||||
'escape cli' => array(
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[91m\"Text\" \x1b[35mAS \x1b[39mbar\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' <span class="sql-string">"Text"</span> ' .
|
||||
'<span class="sql-reserved">AS</span> bar',
|
||||
],
|
||||
'escape cli' => [
|
||||
'query' => "select 'text\x1b[33mcolor-inj'",
|
||||
'text' => 'SELECT' . "\n" .
|
||||
" 'text\x1B[33mcolor-inj'",
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[91m'text\\x1B[33mcolor-inj'" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[91m'text\\x1B[33mcolor-inj'\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' <span class="sql-string">\'text' . "\x1b[33m" . 'color-inj\'</span>',
|
||||
),
|
||||
'escape html' => array(
|
||||
],
|
||||
'escape html' => [
|
||||
'query' => "select '<s>xss' from `<s>xss` , <s>nxss /*s<s>xss*/",
|
||||
'text' => 'SELECT' . "\n" .
|
||||
' \'<s>xss\'' . "\n" .
|
||||
'FROM' . "\n" .
|
||||
' `<s>xss`,' . "\n" .
|
||||
' < s > nxss /*s<s>xss*/',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[91m'<s>xss'" . "\n" .
|
||||
"\x1b[35mFROM" . "\n" .
|
||||
" \x1b[36m`<s>xss`\x1b[39m," . "\n" .
|
||||
" < s > nxss \x1b[37m/*s<s>xss*/" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
' <span class="sql-string">\'<s>xss\'</span>' . '<br/>' .
|
||||
'<span class="sql-reserved">FROM</span>' . '<br/>' .
|
||||
' <span class="sql-variable">`<s>xss`</span>,<br/> < s > nxss <span class="sql-comment">/*s<s>xss*/</span>',
|
||||
),
|
||||
'create table' => array(
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[91m'<s>xss'\n" .
|
||||
"\x1b[35mFROM\n" .
|
||||
" \x1b[36m`<s>xss`\x1b[39m,\n" .
|
||||
" < s > nxss \x1b[37m/*s<s>xss*/\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' <span class="sql-string">\'<s>xss\'</span><br/>' .
|
||||
'<span class="sql-reserved">FROM</span><br/>' .
|
||||
' <span class="sql-variable">`<s>xss`</span>,' .
|
||||
'<br/> < s > nxss <span class="sql-comment">/*s<s>xss*/</span>',
|
||||
],
|
||||
'create table' => [
|
||||
'query' => 'create table if not exists `pma__bookmark` (' . "\n" .
|
||||
'`id` int(11) not null auto_increment,' . "\n" .
|
||||
'`dbase` varchar(255) not null default "",' . "\n" .
|
||||
@@ -483,29 +524,49 @@ class FormatterTest extends TestCase
|
||||
' `label` VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT "",' . "\n" .
|
||||
' `query` TEXT NOT NULL,' . "\n" .
|
||||
' PRIMARY KEY(`id`)',
|
||||
'cli' => "\x1b[35mCREATE TABLE IF NOT EXISTS \x1b[36m`pma__bookmark`\x1b[39m(" . "\n" .
|
||||
" \x1b[36m`id` \x1b[35mINT\x1b[39m(\x1b[92m11\x1b[39m) \x1b[35mNOT NULL \x1b[95mAUTO_INCREMENT\x1b[39m," . "\n" .
|
||||
" \x1b[36m`dbase` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m," . "\n" .
|
||||
" \x1b[36m`user` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m," . "\n" .
|
||||
" \x1b[36m`label` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) \x1b[35mCOLLATE \x1b[39mutf8_general_ci \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m," . "\n" .
|
||||
" \x1b[36m`query` \x1b[95mTEXT \x1b[35mNOT NULL\x1b[39m," . "\n" .
|
||||
" \x1b[35mPRIMARY KEY\x1b[39m(\x1b[36m`id`\x1b[39m)" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">CREATE</span> <span class="sql-reserved">TABLE</span> <span class="sql-reserved">IF NOT EXISTS</span> <span class="sql-variable">`pma__bookmark`</span>(' . '<br/>' .
|
||||
' <span class="sql-variable">`id`</span> <span class="sql-reserved">INT</span>(<span class="sql-number">11</span>) <span class="sql-reserved">NOT NULL</span> <span class="sql-keyword">AUTO_INCREMENT</span>,' . '<br/>' .
|
||||
' <span class="sql-variable">`dbase`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,' . '<br/>' .
|
||||
' <span class="sql-variable">`user`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,' . '<br/>' .
|
||||
' <span class="sql-variable">`label`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">COLLATE</span> utf8_general_ci <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,' . '<br/>' .
|
||||
' <span class="sql-variable">`query`</span> <span class="sql-keyword">TEXT</span> <span class="sql-reserved">NOT NULL</span>,' . '<br/>' .
|
||||
' <span class="sql-reserved">PRIMARY KEY</span>(<span class="sql-variable">`id`</span>)',
|
||||
),
|
||||
'join' => array(
|
||||
'cli' => "\x1b[35mCREATE TABLE IF NOT EXISTS \x1b[36m`pma__bookmark`\x1b[39m(\n" .
|
||||
" \x1b[36m`id` \x1b[35mINT\x1b[39m(\x1b[92m11\x1b[39m) " .
|
||||
"\x1b[35mNOT NULL \x1b[95mAUTO_INCREMENT\x1b[39m,\n" .
|
||||
" \x1b[36m`dbase` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) " .
|
||||
"\x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m,\n" .
|
||||
" \x1b[36m`user` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) " .
|
||||
"\x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m,\n" .
|
||||
" \x1b[36m`label` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) " .
|
||||
"\x1b[35mCOLLATE \x1b[39mutf8_general_ci \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m,\n" .
|
||||
" \x1b[36m`query` \x1b[95mTEXT \x1b[35mNOT NULL\x1b[39m,\n" .
|
||||
" \x1b[35mPRIMARY KEY\x1b[39m(\x1b[36m`id`\x1b[39m)\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">CREATE</span> <span class="sql-reserved">TABLE</span> ' .
|
||||
'<span class="sql-reserved">IF NOT EXISTS</span> <span class="sql-variable">' .
|
||||
'`pma__bookmark`</span>(<br/>' .
|
||||
' <span class="sql-variable">`id`</span> ' .
|
||||
'<span class="sql-reserved">INT</span>(<span class="sql-number">11</span>) ' .
|
||||
'<span class="sql-reserved">NOT NULL</span> <span class="sql-keyword">AUTO_INCREMENT</span>,<br/>' .
|
||||
' <span class="sql-variable">`dbase`</span> ' .
|
||||
'<span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) ' .
|
||||
'<span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> ' .
|
||||
'<span class="sql-string">""</span>,<br/>' .
|
||||
' <span class="sql-variable">`user`</span> ' .
|
||||
'<span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) ' .
|
||||
'<span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> ' .
|
||||
'<span class="sql-string">""</span>,<br/>' .
|
||||
' <span class="sql-variable">`label`</span> ' .
|
||||
'<span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) ' .
|
||||
'<span class="sql-reserved">COLLATE</span> utf8_general_ci ' .
|
||||
'<span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> ' .
|
||||
'<span class="sql-string">""</span>,<br/>' .
|
||||
' <span class="sql-variable">`query`</span> ' .
|
||||
'<span class="sql-keyword">TEXT</span> <span class="sql-reserved">NOT NULL</span>,<br/>' .
|
||||
' <span class="sql-reserved">' .
|
||||
'PRIMARY KEY</span>(<span class="sql-variable">`id`</span>)',
|
||||
],
|
||||
'join' => [
|
||||
'query' => 'join tbl2 on c1=c2',
|
||||
'text' => 'JOIN tbl2 ON c1 = c2',
|
||||
'cli' => "\x1b[35mJOIN \x1b[39mtbl2 \x1b[35mON \x1b[39mc1 = c2" .
|
||||
"\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">JOIN</span> tbl2 <span class="sql-reserved">ON</span> c1 = c2',
|
||||
),
|
||||
'named param' => array(
|
||||
],
|
||||
'named param' => [
|
||||
'query' => 'select * from tbl where col = :param',
|
||||
'text' => 'SELECT' . "\n" .
|
||||
' *' . "\n" .
|
||||
@@ -513,20 +574,20 @@ class FormatterTest extends TestCase
|
||||
' tbl' . "\n" .
|
||||
'WHERE' . "\n" .
|
||||
' col = :param',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[39m*" . "\n" .
|
||||
"\x1b[35mFROM" . "\n" .
|
||||
" \x1b[39mtbl" . "\n" .
|
||||
"\x1b[35mWHERE" . "\n" .
|
||||
" \x1b[39mcol = \x1b[31m:param" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
' *' . '<br/>' .
|
||||
'<span class="sql-reserved">FROM</span>' . '<br/>' .
|
||||
' tbl' . '<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[39m*\n" .
|
||||
"\x1b[35mFROM\n" .
|
||||
" \x1b[39mtbl\n" .
|
||||
"\x1b[35mWHERE\n" .
|
||||
" \x1b[39mcol = \x1b[31m:param\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' *<br/>' .
|
||||
'<span class="sql-reserved">FROM</span><br/>' .
|
||||
' tbl<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span><br/>' .
|
||||
' col = <span class="sql-parameter">:param</span>',
|
||||
),
|
||||
'anon param' => array(
|
||||
],
|
||||
'anon param' => [
|
||||
'query' => 'select * from tbl where col = ?',
|
||||
'text' => 'SELECT' . "\n" .
|
||||
' *' . "\n" .
|
||||
@@ -534,19 +595,19 @@ class FormatterTest extends TestCase
|
||||
' tbl' . "\n" .
|
||||
'WHERE' . "\n" .
|
||||
' col = ?',
|
||||
'cli' => "\x1b[35mSELECT" . "\n" .
|
||||
" \x1b[39m*" . "\n" .
|
||||
"\x1b[35mFROM" . "\n" .
|
||||
" \x1b[39mtbl" . "\n" .
|
||||
"\x1b[35mWHERE" . "\n" .
|
||||
" \x1b[39mcol = \x1b[31m?" . "\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
|
||||
' *' . '<br/>' .
|
||||
'<span class="sql-reserved">FROM</span>' . '<br/>' .
|
||||
' tbl' . '<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
|
||||
'cli' => "\x1b[35mSELECT\n" .
|
||||
" \x1b[39m*\n" .
|
||||
"\x1b[35mFROM\n" .
|
||||
" \x1b[39mtbl\n" .
|
||||
"\x1b[35mWHERE\n" .
|
||||
" \x1b[39mcol = \x1b[31m?\x1b[0m",
|
||||
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
|
||||
' *<br/>' .
|
||||
'<span class="sql-reserved">FROM</span><br/>' .
|
||||
' tbl<br/>' .
|
||||
'<span class="sql-reserved">WHERE</span><br/>' .
|
||||
' col = <span class="sql-parameter">?</span>',
|
||||
)
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Parser;
|
||||
@@ -9,12 +11,15 @@ use PhpMyAdmin\SqlParser\Utils\Misc;
|
||||
class MiscTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getAliasesProvider
|
||||
* @param mixed[] $expected
|
||||
* @psalm-param array<string, array{
|
||||
* alias: (string|null),
|
||||
* tables: array<string, array{alias: (string|null), columns: array<string, string>}>
|
||||
* }> $expected
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param mixed $db
|
||||
* @dataProvider getAliasesProvider
|
||||
*/
|
||||
public function testGetAliases($query, $db, array $expected)
|
||||
public function testGetAliases(string $query, ?string $db, array $expected): void
|
||||
{
|
||||
$parser = new Parser($query);
|
||||
$statement = empty($parser->statements[0]) ?
|
||||
@@ -22,106 +27,111 @@ class MiscTest extends TestCase
|
||||
$this->assertEquals($expected, Misc::getAliases($statement, $db));
|
||||
}
|
||||
|
||||
public function getAliasesProvider()
|
||||
/**
|
||||
* @return array<int, array<int, string|mixed[]|null>>
|
||||
* @psalm-return list<array{string, (string|null), array<string, array{
|
||||
* alias: (string|null),
|
||||
* tables: array<string, array{alias: (string|null), columns: array<string, string>}>
|
||||
* }>}>
|
||||
*/
|
||||
public function getAliasesProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'select * from (select 1) tbl',
|
||||
'mydb',
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
[],
|
||||
],
|
||||
[
|
||||
'select i.name as `n`,abcdef gh from qwerty i',
|
||||
'mydb',
|
||||
array(
|
||||
'mydb' => array(
|
||||
[
|
||||
'mydb' => [
|
||||
'alias' => null,
|
||||
'tables' => array(
|
||||
'qwerty' => array(
|
||||
'tables' => [
|
||||
'qwerty' => [
|
||||
'alias' => 'i',
|
||||
'columns' => array(
|
||||
'columns' => [
|
||||
'name' => 'n',
|
||||
'abcdef' => 'gh',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'select film_id id,title from film',
|
||||
'sakila',
|
||||
array(
|
||||
'sakila' => array(
|
||||
[
|
||||
'sakila' => [
|
||||
'alias' => null,
|
||||
'tables' => array(
|
||||
'film' => array(
|
||||
'tables' => [
|
||||
'film' => [
|
||||
'alias' => null,
|
||||
'columns' => array(
|
||||
'film_id' => 'id',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'columns' => ['film_id' => 'id'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'select `sakila`.`A`.`actor_id` as aid,`F`.`film_id` `fid`,'
|
||||
. 'last_update updated from `sakila`.actor A join `film_actor` as '
|
||||
. '`F` on F.actor_id = A.`actor_id`',
|
||||
'sakila',
|
||||
array(
|
||||
'sakila' => array(
|
||||
[
|
||||
'sakila' => [
|
||||
'alias' => null,
|
||||
'tables' => array(
|
||||
'film_actor' => array(
|
||||
'tables' => [
|
||||
'film_actor' => [
|
||||
'alias' => 'F',
|
||||
'columns' => array(
|
||||
'columns' => [
|
||||
'film_id' => 'fid',
|
||||
'last_update' => 'updated',
|
||||
),
|
||||
),
|
||||
'actor' => array(
|
||||
],
|
||||
],
|
||||
'actor' => [
|
||||
'alias' => 'A',
|
||||
'columns' => array(
|
||||
'columns' => [
|
||||
'actor_id' => 'aid',
|
||||
'last_update' => 'updated',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'SELECT film_id FROM (SELECT * FROM film) as f;',
|
||||
'sakila',
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
[],
|
||||
],
|
||||
[
|
||||
'',
|
||||
null,
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
[],
|
||||
],
|
||||
[
|
||||
'SELECT 1',
|
||||
null,
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
[],
|
||||
],
|
||||
[
|
||||
'SELECT * FROM orders AS ord WHERE 1',
|
||||
'db',
|
||||
array(
|
||||
'db' => array(
|
||||
[
|
||||
'db' => [
|
||||
'alias' => null,
|
||||
'tables' => array(
|
||||
'orders' => array(
|
||||
'tables' => [
|
||||
'orders' => [
|
||||
'alias' => 'ord',
|
||||
'columns' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
'columns' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
+238
-238
@@ -1,281 +1,287 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Parser;
|
||||
use PhpMyAdmin\SqlParser\Tests\TestCase;
|
||||
use PhpMyAdmin\SqlParser\Utils\Query;
|
||||
|
||||
use function array_merge;
|
||||
|
||||
/**
|
||||
* @psalm-import-type QueryFlagsType from Query
|
||||
*/
|
||||
class QueryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getFlagsProvider
|
||||
* @param array<string, bool|string> $expected
|
||||
* @psalm-param QueryFlagsType $expected
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param mixed $expected
|
||||
* @dataProvider getFlagsProvider
|
||||
*/
|
||||
public function testGetFlags($query, $expected)
|
||||
public function testGetFlags(string $query, array $expected): void
|
||||
{
|
||||
$parser = new Parser($query);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Query::getFlags($parser->statements[0])
|
||||
);
|
||||
$this->assertEquals($expected, Query::getFlags($parser->statements[0]));
|
||||
}
|
||||
|
||||
public function getFlagsProvider()
|
||||
/**
|
||||
* @return array<int, array<int, string|array<string, bool|string>>>
|
||||
* @psalm-return list<array{non-empty-string, QueryFlagsType}>
|
||||
*/
|
||||
public function getFlagsProvider(): array
|
||||
{
|
||||
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',
|
||||
),
|
||||
)
|
||||
);
|
||||
['querytype' => 'SET'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetAll()
|
||||
public function testGetAll(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(
|
||||
[
|
||||
'distinct' => false,
|
||||
'drop_database' => false,
|
||||
'group' => false,
|
||||
@@ -303,7 +309,7 @@ class QueryTest extends TestCase
|
||||
'reload' => false,
|
||||
'select_from' => false,
|
||||
'union' => false,
|
||||
),
|
||||
],
|
||||
Query::getAll('')
|
||||
);
|
||||
|
||||
@@ -313,21 +319,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 +343,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 +367,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,26 +387,23 @@ class QueryTest extends TestCase
|
||||
$this->assertEquals(
|
||||
array_merge(
|
||||
Query::getFlags($parser->statements[0], true),
|
||||
array(
|
||||
[
|
||||
'parser' => $parser,
|
||||
'statement' => $parser->statements[0],
|
||||
'select_expr' => array(
|
||||
'CASE WHEN 2 IS NULL THEN "this is true" ELSE "this is false" END',
|
||||
),
|
||||
'select_tables' => array(),
|
||||
)
|
||||
'select_expr' => ['CASE WHEN 2 IS NULL THEN "this is true" ELSE "this is false" END'],
|
||||
'select_tables' => [],
|
||||
]
|
||||
),
|
||||
Query::getAll($query)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTablesProvider
|
||||
* @param string[] $expected
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param mixed $expected
|
||||
* @dataProvider getTablesProvider
|
||||
*/
|
||||
public function testGetTables($query, $expected)
|
||||
public function testGetTables(string $query, array $expected): void
|
||||
{
|
||||
$parser = new Parser($query);
|
||||
$this->assertEquals(
|
||||
@@ -409,59 +412,63 @@ class QueryTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function getTablesProvider()
|
||||
/**
|
||||
* @return array<int, array<int, string|string[]>>
|
||||
* @psalm-return list<array{string, string[]}>
|
||||
*/
|
||||
public function getTablesProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'INSERT INTO tbl(`id`, `name`) VALUES (1, "Name")',
|
||||
array('`tbl`')
|
||||
),
|
||||
array(
|
||||
['`tbl`'],
|
||||
],
|
||||
[
|
||||
'INSERT INTO 0tbl(`id`, `name`) VALUES (1, "Name")',
|
||||
array('`0tbl`')
|
||||
),
|
||||
array(
|
||||
['`0tbl`'],
|
||||
],
|
||||
[
|
||||
'UPDATE tbl SET id = 0',
|
||||
array('`tbl`')
|
||||
),
|
||||
array(
|
||||
['`tbl`'],
|
||||
],
|
||||
[
|
||||
'UPDATE 0tbl SET id = 0',
|
||||
array('`0tbl`')
|
||||
),
|
||||
array(
|
||||
['`0tbl`'],
|
||||
],
|
||||
[
|
||||
'DELETE FROM tbl WHERE id < 10',
|
||||
array('`tbl`')
|
||||
),
|
||||
array(
|
||||
['`tbl`'],
|
||||
],
|
||||
[
|
||||
'DELETE FROM 0tbl WHERE id < 10',
|
||||
array('`0tbl`')
|
||||
),
|
||||
array(
|
||||
['`0tbl`'],
|
||||
],
|
||||
[
|
||||
'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()
|
||||
public function testGetClause(): void
|
||||
{
|
||||
/* Assertion 1 */
|
||||
$parser = new Parser(
|
||||
@@ -567,7 +574,7 @@ class QueryTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testReplaceClause()
|
||||
public function testReplaceClause(): void
|
||||
{
|
||||
$parser = new Parser('SELECT *, (SELECT 1) FROM film LIMIT 0, 10;');
|
||||
$this->assertEquals(
|
||||
@@ -595,7 +602,7 @@ class QueryTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testReplaceClauseOnlyKeyword()
|
||||
public function testReplaceClauseOnlyKeyword(): void
|
||||
{
|
||||
$parser = new Parser('SELECT *, (SELECT 1) FROM film LIMIT 0, 10');
|
||||
$this->assertEquals(
|
||||
@@ -610,7 +617,7 @@ class QueryTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testReplaceNonExistingPart()
|
||||
public function testReplaceNonExistingPart(): void
|
||||
{
|
||||
$parser = new Parser('ALTER TABLE `sale_mast` OPTIMIZE PARTITION p3');
|
||||
$this->assertEquals(
|
||||
@@ -624,22 +631,21 @@ class QueryTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testReplaceClauses()
|
||||
public function testReplaceClauses(): void
|
||||
{
|
||||
$this->assertEquals('', Query::replaceClauses(null, null, array()));
|
||||
|
||||
$parser = new Parser('SELECT *, (SELECT 1) FROM film LIMIT 0, 10;');
|
||||
$this->assertSame('', Query::replaceClauses($parser->statements[0], $parser->list, []));
|
||||
$this->assertEquals(
|
||||
'SELECT *, (SELECT 1) FROM film WHERE film_id > 0 LIMIT 0, 10',
|
||||
Query::replaceClauses(
|
||||
$parser->statements[0],
|
||||
$parser->list,
|
||||
array(
|
||||
array(
|
||||
[
|
||||
[
|
||||
'WHERE',
|
||||
'WHERE film_id > 0',
|
||||
)
|
||||
)
|
||||
],
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
@@ -660,30 +666,29 @@ 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',
|
||||
)
|
||||
)
|
||||
],
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetFirstStatement()
|
||||
public function testGetFirstStatement(): void
|
||||
{
|
||||
$query = 'USE saki';
|
||||
$delimiter = null;
|
||||
list($statement, $query, $delimiter) =
|
||||
Query::getFirstStatement($query, $delimiter);
|
||||
[$statement, $query, $delimiter] = Query::getFirstStatement($query, $delimiter);
|
||||
$this->assertNull($statement);
|
||||
$this->assertEquals('USE saki', $query);
|
||||
|
||||
@@ -695,25 +700,20 @@ class QueryTest extends TestCase
|
||||
'/*!SELECT * FROM actor WHERE last_name = "abc"*/$$';
|
||||
$delimiter = null;
|
||||
|
||||
list($statement, $query, $delimiter) =
|
||||
Query::getFirstStatement($query, $delimiter);
|
||||
[$statement, $query, $delimiter] = Query::getFirstStatement($query, $delimiter);
|
||||
$this->assertEquals('USE sakila;', $statement);
|
||||
|
||||
list($statement, $query, $delimiter) =
|
||||
Query::getFirstStatement($query, $delimiter);
|
||||
[$statement, $query, $delimiter] = Query::getFirstStatement($query, $delimiter);
|
||||
$this->assertEquals('SELECT * FROM actor;', $statement);
|
||||
|
||||
list($statement, $query, $delimiter) =
|
||||
Query::getFirstStatement($query, $delimiter);
|
||||
[$statement, $query, $delimiter] = Query::getFirstStatement($query, $delimiter);
|
||||
$this->assertEquals('DELIMITER $$', $statement);
|
||||
$this->assertEquals('$$', $delimiter);
|
||||
|
||||
list($statement, $query, $delimiter) =
|
||||
Query::getFirstStatement($query, $delimiter);
|
||||
[$statement, $query, $delimiter] = Query::getFirstStatement($query, $delimiter);
|
||||
$this->assertEquals('UPDATE actor SET last_name = "abc"$$', $statement);
|
||||
|
||||
list($statement, $query, $delimiter) =
|
||||
Query::getFirstStatement($query, $delimiter);
|
||||
[$statement, $query, $delimiter] = Query::getFirstStatement($query, $delimiter);
|
||||
$this->assertEquals('SELECT * FROM actor WHERE last_name = "abc"$$', $statement);
|
||||
}
|
||||
}
|
||||
|
||||
+165
-154
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Parser;
|
||||
@@ -9,302 +11,311 @@ use PhpMyAdmin\SqlParser\Utils\Routine;
|
||||
class RoutineTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getReturnTypeProvider
|
||||
* @param string[] $expected
|
||||
*
|
||||
* @param mixed $def
|
||||
* @dataProvider getReturnTypeProvider
|
||||
*/
|
||||
public function testGetReturnType($def, array $expected)
|
||||
public function testGetReturnType(string $def, array $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, Routine::getReturnType($def));
|
||||
}
|
||||
|
||||
public function getReturnTypeProvider()
|
||||
/**
|
||||
* @return array<int, array<int, string|array<int, string>>>
|
||||
* @psalm-return list<array{string, string[]}>
|
||||
*/
|
||||
public function getReturnTypeProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
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
|
||||
* @param string[] $expected
|
||||
*
|
||||
* @param mixed $def
|
||||
* @dataProvider getParameterProvider
|
||||
*/
|
||||
public function testGetParameter($def, array $expected)
|
||||
public function testGetParameter(string $def, array $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, Routine::getParameter($def));
|
||||
}
|
||||
|
||||
public function getParameterProvider()
|
||||
/**
|
||||
* @return array<int, array<int, string|array<int, string>>>
|
||||
* @psalm-return list<array{string, string[]}>
|
||||
*/
|
||||
public function getParameterProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
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
|
||||
* @param array<string, int|string[]|string[][]> $expected
|
||||
* @psalm-param array{
|
||||
* num: int,
|
||||
* dir: string[],
|
||||
* name: string[],
|
||||
* type: string[],
|
||||
* length: string[],
|
||||
* length_arr: string[][],
|
||||
* opts: string[]
|
||||
* } $expected
|
||||
*
|
||||
* @param mixed $query
|
||||
* @dataProvider getParametersProvider
|
||||
*/
|
||||
public function testGetParameters($query, array $expected)
|
||||
public function testGetParameters(string $query, array $expected): void
|
||||
{
|
||||
$parser = new Parser($query);
|
||||
$this->assertEquals($expected, Routine::getParameters($parser->statements[0]));
|
||||
}
|
||||
|
||||
public function getParametersProvider()
|
||||
/**
|
||||
* @return array<int, array<int, string|array<string, int|string[]|string[][]>>>
|
||||
* @psalm-return list<array{string, array{
|
||||
* num: int,
|
||||
* dir: string[],
|
||||
* name: string[],
|
||||
* type: string[],
|
||||
* length: string[],
|
||||
* length_arr: string[][],
|
||||
* opts: string[]
|
||||
* }}>
|
||||
*/
|
||||
public function getParametersProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'CREATE PROCEDURE `foo`() SET @A=0',
|
||||
array(
|
||||
[
|
||||
'num' => 0,
|
||||
'dir' => array(),
|
||||
'name' => array(),
|
||||
'type' => array(),
|
||||
'length' => array(),
|
||||
'length_arr' => array(),
|
||||
'opts' => array(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'dir' => [],
|
||||
'name' => [],
|
||||
'type' => [],
|
||||
'length' => [],
|
||||
'length_arr' => [],
|
||||
'opts' => [],
|
||||
],
|
||||
],
|
||||
[
|
||||
'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 => '',
|
||||
),
|
||||
'length_arr' => array(
|
||||
0 => array(),
|
||||
),
|
||||
'opts' => array(
|
||||
0 => '',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'dir' => [0 => ''],
|
||||
'name' => [0 => 'baz'],
|
||||
'type' => [0 => 'INT'],
|
||||
'length' => [0 => ''],
|
||||
'length_arr' => [
|
||||
0 => [],
|
||||
],
|
||||
'opts' => [0 => ''],
|
||||
],
|
||||
],
|
||||
[
|
||||
'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',
|
||||
),
|
||||
'length_arr' => array(
|
||||
0 => array('25'),
|
||||
),
|
||||
'opts' => array(
|
||||
0 => 'UNSIGNED ZEROFILL',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'dir' => [0 => 'IN'],
|
||||
'name' => [0 => 'baz\\)'],
|
||||
'type' => [0 => 'INT'],
|
||||
'length' => [0 => '25'],
|
||||
'length_arr' => [
|
||||
0 => ['25'],
|
||||
],
|
||||
'opts' => [0 => 'UNSIGNED ZEROFILL'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) ' .
|
||||
'BEGIN SELECT NULL; END',
|
||||
array(
|
||||
[
|
||||
'num' => 2,
|
||||
'dir' => array(
|
||||
'dir' => [
|
||||
0 => 'IN',
|
||||
1 => 'OUT',
|
||||
),
|
||||
'name' => array(
|
||||
],
|
||||
'name' => [
|
||||
0 => 'baz\\',
|
||||
1 => 'bazz',
|
||||
),
|
||||
'type' => array(
|
||||
],
|
||||
'type' => [
|
||||
0 => 'INT',
|
||||
1 => 'VARCHAR',
|
||||
),
|
||||
'length' => array(
|
||||
],
|
||||
'length' => [
|
||||
0 => '1',
|
||||
1 => '15',
|
||||
),
|
||||
'length_arr' => array(
|
||||
0 => array('1'),
|
||||
1 => array('15'),
|
||||
),
|
||||
'opts' => array(
|
||||
],
|
||||
'length_arr' => [
|
||||
0 => ['1'],
|
||||
1 => ['15'],
|
||||
],
|
||||
'opts' => [
|
||||
0 => 'ZEROFILL',
|
||||
1 => 'utf8',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Parser;
|
||||
@@ -9,24 +11,45 @@ use PhpMyAdmin\SqlParser\Utils\Table;
|
||||
class TableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getForeignKeysProvider
|
||||
* @param array<string, string|string[]|null>[] $expected
|
||||
* @psalm-param list<array{
|
||||
* constraint: string,
|
||||
* index_list: string[],
|
||||
* ref_db_name: null,
|
||||
* ref_table_name: string,
|
||||
* ref_index_list: string[],
|
||||
* on_update: string,
|
||||
* on_delete?: string
|
||||
* }> $expected
|
||||
*
|
||||
* @param mixed $query
|
||||
* @dataProvider getForeignKeysProvider
|
||||
*/
|
||||
public function testGetForeignKeys($query, array $expected)
|
||||
public function testGetForeignKeys(string $query, array $expected): void
|
||||
{
|
||||
$parser = new Parser($query);
|
||||
$this->assertEquals($expected, Table::getForeignKeys($parser->statements[0]));
|
||||
}
|
||||
|
||||
public function getForeignKeysProvider()
|
||||
/**
|
||||
* @return array<int, array<int, string|array<string, string|string[]|null>[]>>
|
||||
* @psalm-return list<array{string, list<array{
|
||||
* constraint: string,
|
||||
* index_list: string[],
|
||||
* ref_db_name: null,
|
||||
* ref_table_name: string,
|
||||
* ref_index_list: string[],
|
||||
* on_update: string,
|
||||
* on_delete?: string
|
||||
* }>}>
|
||||
*/
|
||||
public function getForeignKeysProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'CREATE USER test',
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
[],
|
||||
],
|
||||
[
|
||||
'CREATE TABLE `payment` (
|
||||
`payment_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`customer_id` smallint(5) unsigned NOT NULL,
|
||||
@@ -39,39 +62,42 @@ class TableTest extends TestCase
|
||||
KEY `idx_fk_staff_id` (`staff_id`),
|
||||
KEY `idx_fk_customer_id` (`customer_id`),
|
||||
KEY `fk_payment_rental` (`rental_id`),
|
||||
CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_payment_rental` FOREIGN KEY (`rental_id`) REFERENCES `rental` (`rental_id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_payment_staff` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`staff_id`) ON UPDATE CASCADE
|
||||
CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`)
|
||||
REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_payment_rental` FOREIGN KEY (`rental_id`)
|
||||
REFERENCES `rental` (`rental_id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_payment_staff` FOREIGN KEY (`staff_id`)
|
||||
REFERENCES `staff` (`staff_id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=16050 DEFAULT CHARSET=utf8',
|
||||
array(
|
||||
array(
|
||||
[
|
||||
[
|
||||
'constraint' => 'fk_payment_customer',
|
||||
'index_list' => array('customer_id'),
|
||||
'index_list' => ['customer_id'],
|
||||
'ref_db_name' => null,
|
||||
'ref_table_name' => 'customer',
|
||||
'ref_index_list' => array('customer_id'),
|
||||
'ref_index_list' => ['customer_id'],
|
||||
'on_update' => 'CASCADE',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'constraint' => 'fk_payment_rental',
|
||||
'index_list' => array('rental_id'),
|
||||
'index_list' => ['rental_id'],
|
||||
'ref_db_name' => null,
|
||||
'ref_table_name' => 'rental',
|
||||
'ref_index_list' => array('rental_id'),
|
||||
'ref_index_list' => ['rental_id'],
|
||||
'on_delete' => 'SET_NULL',
|
||||
'on_update' => 'CASCADE',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'constraint' => 'fk_payment_staff',
|
||||
'index_list' => array('staff_id'),
|
||||
'index_list' => ['staff_id'],
|
||||
'ref_db_name' => null,
|
||||
'ref_table_name' => 'staff',
|
||||
'ref_index_list' => array('staff_id'),
|
||||
'ref_index_list' => ['staff_id'],
|
||||
'on_update' => 'CASCADE',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'CREATE TABLE `actor` (
|
||||
`actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`first_name` varchar(45) NOT NULL,
|
||||
@@ -80,9 +106,9 @@ class TableTest extends TestCase
|
||||
PRIMARY KEY (`actor_id`),
|
||||
KEY `idx_actor_last_name` (`last_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8',
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
[],
|
||||
],
|
||||
[
|
||||
'CREATE TABLE `address` (
|
||||
`address_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`address` varchar(50) NOT NULL,
|
||||
@@ -96,39 +122,58 @@ class TableTest extends TestCase
|
||||
KEY `idx_fk_city_id` (`city_id`),
|
||||
CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8',
|
||||
array(
|
||||
array(
|
||||
[
|
||||
[
|
||||
'constraint' => 'fk_address_city',
|
||||
'index_list' => array('city_id'),
|
||||
'index_list' => ['city_id'],
|
||||
'ref_db_name' => null,
|
||||
'ref_table_name' => 'city',
|
||||
'ref_index_list' => array('city_id'),
|
||||
'ref_index_list' => ['city_id'],
|
||||
'on_update' => 'CASCADE',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFieldsProvider
|
||||
* @param array<string, array<string, bool|string>> $expected
|
||||
* @psalm-param array<string, array{
|
||||
* type: string,
|
||||
* timestamp_not_null: bool,
|
||||
* default_value?: string,
|
||||
* default_current_timestamp?: bool,
|
||||
* on_update_current_timestamp?: bool,
|
||||
* expr?: string
|
||||
* }> $expected
|
||||
*
|
||||
* @param mixed $query
|
||||
* @dataProvider getFieldsProvider
|
||||
*/
|
||||
public function testGetFields($query, array $expected)
|
||||
public function testGetFields(string $query, array $expected): void
|
||||
{
|
||||
$parser = new Parser($query);
|
||||
$this->assertEquals($expected, Table::getFields($parser->statements[0]));
|
||||
}
|
||||
|
||||
public function getFieldsProvider()
|
||||
/**
|
||||
* @return array<int, array<int, string|array<string, array<string, bool|string>>>>
|
||||
* @psalm-return list<array{string, array<string, array{
|
||||
* type: string,
|
||||
* timestamp_not_null: bool,
|
||||
* default_value?: string,
|
||||
* default_current_timestamp?: bool,
|
||||
* on_update_current_timestamp?: bool,
|
||||
* expr?: string
|
||||
* }>}>
|
||||
*/
|
||||
public function getFieldsProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'CREATE USER test',
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
[],
|
||||
],
|
||||
[
|
||||
'CREATE TABLE `address` (
|
||||
`address_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`address` varchar(50) NOT NULL,
|
||||
@@ -142,76 +187,76 @@ class TableTest extends TestCase
|
||||
KEY `idx_fk_city_id` (`city_id`),
|
||||
CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8',
|
||||
array(
|
||||
'address_id' => array(
|
||||
[
|
||||
'address_id' => [
|
||||
'type' => 'SMALLINT',
|
||||
'timestamp_not_null' => false,
|
||||
),
|
||||
'address' => array(
|
||||
],
|
||||
'address' => [
|
||||
'type' => 'VARCHAR',
|
||||
'timestamp_not_null' => false,
|
||||
),
|
||||
'address2' => array(
|
||||
],
|
||||
'address2' => [
|
||||
'type' => 'VARCHAR',
|
||||
'timestamp_not_null' => false,
|
||||
'default_value' => 'NULL',
|
||||
),
|
||||
'district' => array(
|
||||
],
|
||||
'district' => [
|
||||
'type' => 'VARCHAR',
|
||||
'timestamp_not_null' => false,
|
||||
),
|
||||
'city_id' => array(
|
||||
],
|
||||
'city_id' => [
|
||||
'type' => 'SMALLINT',
|
||||
'timestamp_not_null' => false,
|
||||
),
|
||||
'postal_code' => array(
|
||||
],
|
||||
'postal_code' => [
|
||||
'type' => 'VARCHAR',
|
||||
'timestamp_not_null' => false,
|
||||
'default_value' => 'NULL',
|
||||
),
|
||||
'phone' => array(
|
||||
],
|
||||
'phone' => [
|
||||
'type' => 'VARCHAR',
|
||||
'timestamp_not_null' => false,
|
||||
),
|
||||
'last_update' => array(
|
||||
],
|
||||
'last_update' => [
|
||||
'type' => 'TIMESTAMP',
|
||||
'timestamp_not_null' => true,
|
||||
'default_value' => 'CURRENT_TIMESTAMP',
|
||||
'default_current_timestamp' => true,
|
||||
'on_update_current_timestamp' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'CREATE TABLE table1 (
|
||||
a INT NOT NULL,
|
||||
b VARCHAR(32),
|
||||
c INT AS (a mod 10) VIRTUAL,
|
||||
d VARCHAR(5) AS (left(b,5)) PERSISTENT
|
||||
)',
|
||||
array(
|
||||
'a' => array(
|
||||
[
|
||||
'a' => [
|
||||
'type' => 'INT',
|
||||
'timestamp_not_null' => false,
|
||||
),
|
||||
'b' => array(
|
||||
],
|
||||
'b' => [
|
||||
'type' => 'VARCHAR',
|
||||
'timestamp_not_null' => false,
|
||||
),
|
||||
'c' => array(
|
||||
],
|
||||
'c' => [
|
||||
'type' => 'INT',
|
||||
'timestamp_not_null' => false,
|
||||
'generated' => true,
|
||||
'expr' => '(a mod 10)',
|
||||
),
|
||||
'd' => array(
|
||||
],
|
||||
'd' => [
|
||||
'type' => 'VARCHAR',
|
||||
'timestamp_not_null' => false,
|
||||
'generated' => true,
|
||||
'expr' => '(left(b,5))',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Tests\TestCase;
|
||||
@@ -9,108 +11,112 @@ use PhpMyAdmin\SqlParser\Utils\Tokens;
|
||||
class TokensTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider replaceTokensProvider
|
||||
* @param array<string, string>[] $find
|
||||
* @param Token[] $replace
|
||||
*
|
||||
* @param mixed $list
|
||||
* @param mixed $find
|
||||
* @param mixed $replace
|
||||
* @param mixed $expected
|
||||
* @dataProvider replaceTokensProvider
|
||||
*/
|
||||
public function testReplaceTokens($list, $find, $replace, $expected)
|
||||
public function testReplaceTokens(string $list, array $find, array $replace, string $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, Tokens::replaceTokens($list, $find, $replace));
|
||||
}
|
||||
|
||||
public function replaceTokensProvider()
|
||||
/**
|
||||
* @return array<int, array<int, string|array<string, string>[]|Token[]>>
|
||||
* @psalm-return list<array{string, list<array<string, string>>, Token[], string}>
|
||||
*/
|
||||
public function replaceTokensProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'SELECT * FROM /*x*/a/*c*/.b',
|
||||
array(
|
||||
array('value_str' => 'a'),
|
||||
array('token' => '.'),
|
||||
),
|
||||
array(
|
||||
[
|
||||
['value_str' => 'a'],
|
||||
['token' => '.'],
|
||||
],
|
||||
[
|
||||
new Token('c'),
|
||||
new Token('.'),
|
||||
),
|
||||
],
|
||||
'SELECT * FROM /*x*/c.b',
|
||||
)
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider matchProvider
|
||||
* @param array<string, int|string> $pattern
|
||||
*
|
||||
* @param mixed $token
|
||||
* @param mixed $pattern
|
||||
* @param mixed $expected
|
||||
* @dataProvider matchProvider
|
||||
*/
|
||||
public function testMatch($token, $pattern, $expected)
|
||||
public function testMatch(Token $token, array $pattern, bool $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, Tokens::match($token, $pattern));
|
||||
$this->assertSame($expected, Tokens::match($token, $pattern));
|
||||
}
|
||||
|
||||
public function matchProvider()
|
||||
/**
|
||||
* @return array<int, array<int, Token|bool|array<string, int|string>>>
|
||||
* @psalm-return list<array{Token, array<string, (int|string)>, bool}>
|
||||
*/
|
||||
public function matchProvider(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
new Token(''),
|
||||
array(),
|
||||
[],
|
||||
true,
|
||||
),
|
||||
],
|
||||
|
||||
array(
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('token' => '"abc"'),
|
||||
['token' => '"abc"'],
|
||||
true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('value' => 'abc'),
|
||||
['value' => 'abc'],
|
||||
true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('value_str' => 'ABC'),
|
||||
['value_str' => 'ABC'],
|
||||
true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('type' => Token::TYPE_STRING),
|
||||
['type' => Token::TYPE_STRING],
|
||||
true,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('flags' => Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
['flags' => Token::FLAG_STRING_DOUBLE_QUOTES],
|
||||
true,
|
||||
),
|
||||
],
|
||||
|
||||
array(
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('token' => '"abcd"'),
|
||||
['token' => '"abcd"'],
|
||||
false,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('value' => 'abcd'),
|
||||
['value' => 'abcd'],
|
||||
false,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('value_str' => 'ABCd'),
|
||||
['value_str' => 'ABCd'],
|
||||
false,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('type' => Token::TYPE_NUMBER),
|
||||
['type' => Token::TYPE_NUMBER],
|
||||
false,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
|
||||
array('flags' => Token::FLAG_STRING_SINGLE_QUOTES),
|
||||
['flags' => Token::FLAG_STRING_SINGLE_QUOTES],
|
||||
false,
|
||||
)
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user