summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Builder/AlterStatementTest.php1
-rw-r--r--tests/Builder/CreateStatementTest.php37
-rw-r--r--tests/Builder/DeleteStatementTest.php1
-rw-r--r--tests/Builder/ExplainStatementTest.php1
-rw-r--r--tests/Builder/InsertStatementTest.php3
-rw-r--r--tests/Builder/LoadStatementTest.php1
-rw-r--r--tests/Builder/LockStatementTest.php1
-rw-r--r--tests/Builder/PurgeStatementTest.php1
-rw-r--r--tests/Builder/RenameStatementTest.php1
-rw-r--r--tests/Builder/ReplaceStatementTest.php1
-rw-r--r--tests/Builder/SelectStatementTest.php4
-rw-r--r--tests/Builder/SetStatementTest.php1
-rw-r--r--tests/Builder/StatementTest.php3
-rw-r--r--tests/Builder/TransactionStatementTest.php1
-rw-r--r--tests/Builder/TruncateStatementTest.php1
-rw-r--r--tests/Components/Array2dTest.php5
-rw-r--r--tests/Components/ArrayObjTest.php30
-rw-r--r--tests/Components/CaseExpressionTest.php1
-rw-r--r--tests/Components/ComponentTest.php12
-rw-r--r--tests/Components/ConditionTest.php1
-rw-r--r--tests/Components/CreateDefinitionTest.php4
-rw-r--r--tests/Components/ExpressionArrayTest.php15
-rw-r--r--tests/Components/ExpressionTest.php31
-rw-r--r--tests/Components/FunctionCallTest.php5
-rw-r--r--tests/Components/GroupKeywordTest.php5
-rw-r--r--tests/Components/IntoKeywordTest.php1
-rw-r--r--tests/Components/JoinKeywordTest.php3
-rw-r--r--tests/Components/KeyTest.php1
-rw-r--r--tests/Components/LimitTest.php13
-rw-r--r--tests/Components/LockExpressionTest.php27
-rw-r--r--tests/Components/OptionsArrayTest.php71
-rw-r--r--tests/Components/OrderKeywordTest.php7
-rw-r--r--tests/Components/ParameterDefinitionTest.php1
-rw-r--r--tests/Components/PartitionDefinitionTest.php1
-rw-r--r--tests/Components/ReferenceTest.php5
-rw-r--r--tests/Components/RenameOperationTest.php1
-rw-r--r--tests/Lexer/ContextTest.php76
-rw-r--r--tests/Lexer/IsMethodsTest.php1
-rw-r--r--tests/Lexer/LexerTest.php73
-rw-r--r--tests/Lexer/TokenTest.php1
-rw-r--r--tests/Lexer/TokensListTest.php9
-rw-r--r--tests/Misc/BugsTest.php25
-rw-r--r--tests/Misc/ParameterTest.php11
-rw-r--r--tests/Misc/UtfStringTest.php38
-rw-r--r--tests/Parser/AlterStatementTest.php35
-rw-r--r--tests/Parser/CallStatementTest.php15
-rw-r--r--tests/Parser/CreateStatementTest.php75
-rw-r--r--tests/Parser/DeleteStatementTest.php59
-rw-r--r--tests/Parser/ExplainStatementTest.php11
-rw-r--r--tests/Parser/InsertStatementTest.php27
-rw-r--r--tests/Parser/LoadStatementTest.php33
-rw-r--r--tests/Parser/LockStatementTest.php43
-rw-r--r--tests/Parser/ParserTest.php27
-rw-r--r--tests/Parser/PurgeStatementTest.php23
-rw-r--r--tests/Parser/RenameStatementTest.php23
-rw-r--r--tests/Parser/ReplaceStatementTest.php27
-rw-r--r--tests/Parser/RestoreStatementTest.php11
-rw-r--r--tests/Parser/SelectStatementTest.php125
-rw-r--r--tests/Parser/SetStatementTest.php23
-rw-r--r--tests/Parser/TransactionStatementTest.php17
-rw-r--r--tests/Parser/UpdateStatementTest.php17
-rw-r--r--tests/TestCase.php27
-rw-r--r--tests/Utils/BufferedQueryTest.php95
-rw-r--r--tests/Utils/CLITest.php363
-rw-r--r--tests/Utils/ErrorTest.php26
-rw-r--r--tests/Utils/FormatterTest.php534
-rw-r--r--tests/Utils/MiscTest.php135
-rw-r--r--tests/Utils/QueryTest.php395
-rw-r--r--tests/Utils/RoutineTest.php277
-rw-r--r--tests/Utils/TableTest.php147
-rw-r--r--tests/Utils/TokensTest.php99
71 files changed, 1654 insertions, 1567 deletions
diff --git a/tests/Builder/AlterStatementTest.php b/tests/Builder/AlterStatementTest.php
index 2372b6d..70236e4 100644
--- a/tests/Builder/AlterStatementTest.php
+++ b/tests/Builder/AlterStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/CreateStatementTest.php b/tests/Builder/CreateStatementTest.php
index 87c5a9b..fc24f16 100644
--- a/tests/Builder/CreateStatementTest.php
+++ b/tests/Builder/CreateStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
@@ -114,19 +115,19 @@ class CreateStatementTest extends TestCase
$stmt = new CreateStatement();
$stmt->name = new Expression('', 'test', '');
- $stmt->options = new OptionsArray(array('TABLE'));
- $stmt->fields = array(
+ $stmt->options = new OptionsArray(['TABLE']);
+ $stmt->fields = [
new CreateDefinition(
'id',
- new OptionsArray(array('NOT NULL', 'AUTO_INCREMENT')),
- new DataType('INT', array(11), new OptionsArray(array('UNSIGNED')))
+ new OptionsArray(['NOT NULL', 'AUTO_INCREMENT']),
+ new DataType('INT', [11], new OptionsArray(['UNSIGNED']))
),
new CreateDefinition(
'',
null,
- new Key('', array(array('name' => 'id')), 'PRIMARY KEY')
- )
- );
+ new Key('', [['name' => 'id']], 'PRIMARY KEY')
+ ),
+ ];
$this->assertEquals(
"CREATE TABLE `test` (\n" .
@@ -217,8 +218,8 @@ class CreateStatementTest extends TestCase
public function partitionQueries()
{
- return array(
- array(
+ return [
+ [
'subparts' => <<<EOT
CREATE TABLE `ts` (
`id` int(11) DEFAULT NULL,
@@ -241,8 +242,9 @@ SUBPARTITION s5 ENGINE=InnoDB
)
)
EOT
- ),
- array(
+ ,
+ ],
+ [
'parts' => <<<EOT
CREATE TABLE ptest (
`event_date` date NOT NULL
@@ -256,14 +258,15 @@ PARTITION p3 ENGINE=InnoDB,
PARTITION p4 ENGINE=InnoDB
)
EOT
- )
- );
+ ,
+ ],
+ ];
}
/**
- * @dataProvider partitionQueries
- *
* @param string $query
+ *
+ * @dataProvider partitionQueries
*/
public function testBuilderPartitionsEngine($query)
{
@@ -304,9 +307,9 @@ EOT
{
$stmt = new CreateStatement();
- $stmt->options = new OptionsArray(array('TRIGGER'));
+ $stmt->options = new OptionsArray(['TRIGGER']);
$stmt->name = new Expression('ins_sum');
- $stmt->entityOptions = new OptionsArray(array('BEFORE', 'INSERT'));
+ $stmt->entityOptions = new OptionsArray(['BEFORE', 'INSERT']);
$stmt->table = new Expression('account');
$stmt->body = 'SET @sum = @sum + NEW.amount';
diff --git a/tests/Builder/DeleteStatementTest.php b/tests/Builder/DeleteStatementTest.php
index 5aa037e..0327e03 100644
--- a/tests/Builder/DeleteStatementTest.php
+++ b/tests/Builder/DeleteStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/ExplainStatementTest.php b/tests/Builder/ExplainStatementTest.php
index 44bb817..7b6215f 100644
--- a/tests/Builder/ExplainStatementTest.php
+++ b/tests/Builder/ExplainStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/InsertStatementTest.php b/tests/Builder/InsertStatementTest.php
index 5e3360d..cf46143 100644
--- a/tests/Builder/InsertStatementTest.php
+++ b/tests/Builder/InsertStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
@@ -64,7 +65,7 @@ class InsertStatementTest extends TestCase
);
/* Assertion 6 */
- /* INSERT array(OPTIONS] INTO ... */
+ /* INSERT [OPTIONS] INTO ... */
$parser = new Parser(
'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar'
);
diff --git a/tests/Builder/LoadStatementTest.php b/tests/Builder/LoadStatementTest.php
index 4c4e9b1..051e13d 100644
--- a/tests/Builder/LoadStatementTest.php
+++ b/tests/Builder/LoadStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/LockStatementTest.php b/tests/Builder/LockStatementTest.php
index b0b4d38..8593a87 100644
--- a/tests/Builder/LockStatementTest.php
+++ b/tests/Builder/LockStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/PurgeStatementTest.php b/tests/Builder/PurgeStatementTest.php
index caa1652..aae52b5 100644
--- a/tests/Builder/PurgeStatementTest.php
+++ b/tests/Builder/PurgeStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/RenameStatementTest.php b/tests/Builder/RenameStatementTest.php
index 97852ab..e803786 100644
--- a/tests/Builder/RenameStatementTest.php
+++ b/tests/Builder/RenameStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/ReplaceStatementTest.php b/tests/Builder/ReplaceStatementTest.php
index b1a6c91..ee5b95a 100644
--- a/tests/Builder/ReplaceStatementTest.php
+++ b/tests/Builder/ReplaceStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/SelectStatementTest.php b/tests/Builder/SelectStatementTest.php
index 6abee03..a22cf08 100644
--- a/tests/Builder/SelectStatementTest.php
+++ b/tests/Builder/SelectStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
@@ -251,7 +252,8 @@ class SelectStatementTest extends TestCase
);
}
- public function testBuilderSurroundedByParanthesisWithLimit() {
+ public function testBuilderSurroundedByParanthesisWithLimit()
+ {
$query = '(SELECT first_name FROM `actor` LIMIT 1, 2)';
$parser = new Parser($query);
$stmt = $parser->statements[0];
diff --git a/tests/Builder/SetStatementTest.php b/tests/Builder/SetStatementTest.php
index 771762e..2e1355d 100644
--- a/tests/Builder/SetStatementTest.php
+++ b/tests/Builder/SetStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/StatementTest.php b/tests/Builder/StatementTest.php
index 178901a..b75b5d5 100644
--- a/tests/Builder/StatementTest.php
+++ b/tests/Builder/StatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
@@ -15,7 +16,7 @@ class StatementTest extends TestCase
{
$stmt = new SelectStatement();
- $stmt->options = new OptionsArray(array('DISTINCT'));
+ $stmt->options = new OptionsArray(['DISTINCT']);
$stmt->expr[] = new Expression('sakila', 'film', 'film_id', 'fid');
$stmt->expr[] = new Expression('COUNT(film_id)');
diff --git a/tests/Builder/TransactionStatementTest.php b/tests/Builder/TransactionStatementTest.php
index d7fd73c..5cd28c6 100644
--- a/tests/Builder/TransactionStatementTest.php
+++ b/tests/Builder/TransactionStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Builder;
diff --git a/tests/Builder/TruncateStatementTest.php b/tests/Builder/TruncateStatementTest.php
index 09cd01f..1abee17 100644
--- a/tests/Builder/TruncateStatementTest.php
+++ b/tests/Builder/TruncateStatementTest.php
@@ -36,5 +36,4 @@ class TruncateStatementTest extends TestCase
$this->assertEquals($query, $stmt->build());
}
-
}
diff --git a/tests/Components/Array2dTest.php b/tests/Components/Array2dTest.php
index 83e6215..1c57a43 100644
--- a/tests/Components/Array2dTest.php
+++ b/tests/Components/Array2dTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -13,10 +14,10 @@ class Array2dTest extends TestCase
$parser = new Parser();
$arrays = Array2d::parse($parser, $this->getTokensList('(1, 2) +'));
$this->assertEquals(
- array(
+ [
1,
2,
- ),
+ ],
$arrays[0]->values
);
}
diff --git a/tests/Components/ArrayObjTest.php b/tests/Components/ArrayObjTest.php
index 3664e1c..f683d72 100644
--- a/tests/Components/ArrayObjTest.php
+++ b/tests/Components/ArrayObjTest.php
@@ -1,8 +1,10 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
use PhpMyAdmin\SqlParser\Components\ArrayObj;
+use PhpMyAdmin\SqlParser\Components\Expression;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Tests\TestCase;
@@ -10,13 +12,13 @@ class ArrayObjTest extends TestCase
{
public function testBuildRaw()
{
- $component = new ArrayObj(array('a', 'b'), array());
+ $component = new ArrayObj(['a', 'b'], []);
$this->assertEquals('(a, b)', ArrayObj::build($component));
}
public function testBuildValues()
{
- $component = new ArrayObj(array(), array('a', 'b'));
+ $component = new ArrayObj([], ['a', 'b']);
$this->assertEquals('(a, b)', ArrayObj::build($component));
}
@@ -25,21 +27,23 @@ class ArrayObjTest extends TestCase
$components = ArrayObj::parse(
new Parser(),
$this->getTokensList('(1 + 2, 3 + 4)'),
- array(
- 'type' => 'PhpMyAdmin\\SqlParser\\Components\\Expression',
- 'typeOptions' => array(
+ [
+ 'type' => Expression::class,
+ 'typeOptions' => [
'breakOnParentheses' => true,
- )
- )
+ ],
+ ]
);
+ $this->assertInstanceOf(Expression::class, $components[0]);
+ $this->assertInstanceOf(Expression::class, $components[1]);
$this->assertEquals($components[0]->expr, '1 + 2');
$this->assertEquals($components[1]->expr, '3 + 4');
}
/**
- * @dataProvider parseProvider
- *
* @param mixed $test
+ *
+ * @dataProvider parseProvider
*/
public function testParse($test)
{
@@ -48,9 +52,9 @@ class ArrayObjTest extends TestCase
public function parseProvider()
{
- return array(
- array('parser/parseArrayErr1'),
- array('parser/parseArrayErr3')
- );
+ return [
+ ['parser/parseArrayErr1'],
+ ['parser/parseArrayErr3'],
+ ];
}
}
diff --git a/tests/Components/CaseExpressionTest.php b/tests/Components/CaseExpressionTest.php
index b337cb1..2ea8f8b 100644
--- a/tests/Components/CaseExpressionTest.php
+++ b/tests/Components/CaseExpressionTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
diff --git a/tests/Components/ComponentTest.php b/tests/Components/ComponentTest.php
index 13dbdf4..1044289 100644
--- a/tests/Components/ComponentTest.php
+++ b/tests/Components/ComponentTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -6,26 +7,25 @@ use PhpMyAdmin\SqlParser\Component;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Tests\TestCase;
use PhpMyAdmin\SqlParser\TokensList;
+use Throwable;
class ComponentTest extends TestCase
{
/**
- * @expectedException \Exception
- * @expectedExceptionMessage Not implemented yet.
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testParse()
{
+ $this->expectExceptionMessage('Not implemented yet.');
+ $this->expectException(Throwable::class);
Component::parse(new Parser(), new TokensList());
}
- /**
- * @expectedException \Exception
- * @expectedExceptionMessage Not implemented yet.
- */
public function testBuild()
{
+ $this->expectExceptionMessage('Not implemented yet.');
+ $this->expectException(Throwable::class);
Component::build(null);
}
}
diff --git a/tests/Components/ConditionTest.php b/tests/Components/ConditionTest.php
index 27c6a4f..eb8cca1 100644
--- a/tests/Components/ConditionTest.php
+++ b/tests/Components/ConditionTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
diff --git a/tests/Components/CreateDefinitionTest.php b/tests/Components/CreateDefinitionTest.php
index d00feea..d0718c8 100644
--- a/tests/Components/CreateDefinitionTest.php
+++ b/tests/Components/CreateDefinitionTest.php
@@ -1,9 +1,11 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
use PhpMyAdmin\SqlParser\Components\CreateDefinition;
use PhpMyAdmin\SqlParser\Parser;
+use PhpMyAdmin\SqlParser\Statements\CreateStatement;
use PhpMyAdmin\SqlParser\Tests\TestCase;
class CreateDefinitionTest extends TestCase
@@ -58,6 +60,7 @@ class CreateDefinitionTest extends TestCase
'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' .
') ENGINE=InnoDB"'
);
+ $this->assertInstanceOf(CreateStatement::class, $parser->statements[0]);
$this->assertEquals(
'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE',
CreateDefinition::build($parser->statements[0]->fields[1])
@@ -74,6 +77,7 @@ class CreateDefinitionTest extends TestCase
'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' .
') ENGINE=InnoDB"'
);
+ $this->assertInstanceOf(CreateStatement::class, $parser->statements[0]);
$this->assertEquals(
'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE',
CreateDefinition::build($parser->statements[0]->fields[2])
diff --git a/tests/Components/ExpressionArrayTest.php b/tests/Components/ExpressionArrayTest.php
index f500f8a..597d0a3 100644
--- a/tests/Components/ExpressionArrayTest.php
+++ b/tests/Components/ExpressionArrayTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -13,11 +14,11 @@ class ExpressionArrayTest extends TestCase
$component = ExpressionArray::parse(
new Parser(),
$this->getTokensList('(expr)'),
- array(
- 'breakOnParentheses' => true
- )
+ [
+ 'breakOnParentheses' => true,
+ ]
);
- $this->assertEquals(array(), $component);
+ $this->assertEquals([], $component);
}
public function testParse2()
@@ -25,9 +26,9 @@ class ExpressionArrayTest extends TestCase
$component = ExpressionArray::parse(
new Parser(),
$this->getTokensList('(expr) +'),
- array(
- 'parenthesesDelimited' => true
- )
+ [
+ 'parenthesesDelimited' => true,
+ ]
);
$this->assertCount(1, $component);
$this->assertEquals('(expr)', $component[0]->expr);
diff --git a/tests/Components/ExpressionTest.php b/tests/Components/ExpressionTest.php
index 45b8be5..f56384c 100644
--- a/tests/Components/ExpressionTest.php
+++ b/tests/Components/ExpressionTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -21,10 +22,10 @@ class ExpressionTest extends TestCase
}
/**
- * @dataProvider parseErrProvider
- *
* @param mixed $expr
* @param mixed $error
+ *
+ * @dataProvider parseErrProvider
*/
public function testParseErr($expr, $error)
{
@@ -36,38 +37,38 @@ class ExpressionTest extends TestCase
public function parseErrProvider()
{
- return array(
+ return [
/*
array(
'(1))',
'Unexpected closing bracket.',
),
*/
- array(
+ [
'tbl..col',
'Unexpected dot.',
- ),
- array(
+ ],
+ [
'id AS AS id2',
'An alias was expected.',
- ),
- array(
+ ],
+ [
'id`id2`\'id3\'',
'An alias was previously found.',
- ),
- array(
+ ],
+ [
'(id) id2 id3',
'An alias was previously found.',
- )
- );
+ ],
+ ];
}
public function testBuild()
{
- $component = array(
+ $component = [
new Expression('1 + 2', 'three'),
- new Expression('1 + 3', 'four')
- );
+ new Expression('1 + 3', 'four'),
+ ];
$this->assertEquals(
Expression::build($component),
'1 + 2 AS `three`, 1 + 3 AS `four`'
diff --git a/tests/Components/FunctionCallTest.php b/tests/Components/FunctionCallTest.php
index b8b485a..386b220 100644
--- a/tests/Components/FunctionCallTest.php
+++ b/tests/Components/FunctionCallTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -10,13 +11,13 @@ class FunctionCallTest extends TestCase
{
public function testBuildArray()
{
- $component = new FunctionCall('func', array('a', 'b'));
+ $component = new FunctionCall('func', ['a', 'b']);
$this->assertEquals('func(a, b)', FunctionCall::build($component));
}
public function testBuildArrayObj()
{
- $component = new FunctionCall('func', new ArrayObj(array('a', 'b')));
+ $component = new FunctionCall('func', new ArrayObj(['a', 'b']));
$this->assertEquals('func(a, b)', FunctionCall::build($component));
}
}
diff --git a/tests/Components/GroupKeywordTest.php b/tests/Components/GroupKeywordTest.php
index 8d4a407..41ff89a 100644
--- a/tests/Components/GroupKeywordTest.php
+++ b/tests/Components/GroupKeywordTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -12,11 +13,11 @@ class GroupKeywordTest extends TestCase
{
$this->assertEquals(
GroupKeyword::build(
- array(
+ [
new GroupKeyword(new Expression('a')),
new GroupKeyword(new Expression('b')),
new GroupKeyword(new Expression('c')),
- )
+ ]
),
'a, b, c'
);
diff --git a/tests/Components/IntoKeywordTest.php b/tests/Components/IntoKeywordTest.php
index 2ebf5ee..896c363 100644
--- a/tests/Components/IntoKeywordTest.php
+++ b/tests/Components/IntoKeywordTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
diff --git a/tests/Components/JoinKeywordTest.php b/tests/Components/JoinKeywordTest.php
index 8baf93f..91fd4a6 100644
--- a/tests/Components/JoinKeywordTest.php
+++ b/tests/Components/JoinKeywordTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -23,7 +24,7 @@ class JoinKeywordTest extends TestCase
$this->assertCount(1, $component);
$this->assertEquals('table2', $component[0]->expr->expr);
$this->assertNull($component[0]->on);
- $this->assertEquals(array('id'), $component[0]->using->values);
+ $this->assertEquals(['id'], $component[0]->using->values);
}
public function testBuild()
diff --git a/tests/Components/KeyTest.php b/tests/Components/KeyTest.php
index c27b9d8..aeb403d 100644
--- a/tests/Components/KeyTest.php
+++ b/tests/Components/KeyTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
diff --git a/tests/Components/LimitTest.php b/tests/Components/LimitTest.php
index 9e00a65..18e7461 100644
--- a/tests/Components/LimitTest.php
+++ b/tests/Components/LimitTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -20,9 +21,9 @@ class LimitTest extends TestCase
}
/**
- * @dataProvider parseProvider
- *
* @param mixed $test
+ *
+ * @dataProvider parseProvider
*/
public function testParse($test)
{
@@ -31,9 +32,9 @@ class LimitTest extends TestCase
public function parseProvider()
{
- return array(
- array('parser/parseLimitErr1'),
- array('parser/parseLimitErr2')
- );
+ return [
+ ['parser/parseLimitErr1'],
+ ['parser/parseLimitErr2'],
+ ];
}
}
diff --git a/tests/Components/LockExpressionTest.php b/tests/Components/LockExpressionTest.php
index 00d5ffb..2fc86bd 100644
--- a/tests/Components/LockExpressionTest.php
+++ b/tests/Components/LockExpressionTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -26,10 +27,10 @@ class LockExpressionTest extends TestCase
}
/**
- * @dataProvider parseErrProvider
- *
* @param mixed $expr
* @param mixed $error
+ *
+ * @dataProvider parseErrProvider
*/
public function testParseErr($expr, $error)
{
@@ -41,28 +42,28 @@ class LockExpressionTest extends TestCase
public function parseErrProvider()
{
- return array(
- array(
+ return [
+ [
'table1 AS t1',
'Unexpected end of LOCK expression.',
- ),
- array(
+ ],
+ [
'table1 AS t1 READ WRITE',
'Unexpected keyword.',
- ),
- array(
+ ],
+ [
'table1 AS t1 READ 2',
'Unexpected token.',
- )
- );
+ ],
+ ];
}
public function testBuild()
{
- $component = array(
+ $component = [
LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL')),
- LockExpression::parse(new Parser(), $this->getTokensList('table2 LOW_PRIORITY WRITE'))
- );
+ LockExpression::parse(new Parser(), $this->getTokensList('table2 LOW_PRIORITY WRITE')),
+ ];
$this->assertEquals(
LockExpression::build($component),
'table1 AS `t1` READ LOCAL, table2 LOW_PRIORITY WRITE'
diff --git a/tests/Components/OptionsArrayTest.php b/tests/Components/OptionsArrayTest.php
index a642f83..3904fdf 100644
--- a/tests/Components/OptionsArrayTest.php
+++ b/tests/Components/OptionsArrayTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -13,26 +14,26 @@ class OptionsArrayTest extends TestCase
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('A B = /*comment*/ (test) C'),
- array(
+ [
'A' => 1,
- 'B' => array(
+ 'B' => [
2,
'var',
- ),
- 'C' => 3
- )
+ ],
+ 'C' => 3,
+ ]
);
$this->assertEquals(
- array(
+ [
1 => 'A',
- 2 => array(
+ 2 => [
'name' => 'B',
'expr' => '(test)',
'value' => 'test',
'equals' => true,
- ),
+ ],
3 => 'C',
- ),
+ ],
$component->options
);
}
@@ -42,17 +43,17 @@ class OptionsArrayTest extends TestCase
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('SUM = (3 + 5) RESULT = 8'),
- array(
- 'SUM' => array(
+ [
+ 'SUM' => [
1,
'expr',
- array('parenthesesDelimited' => true),
- ),
- 'RESULT' => array(
+ ['parenthesesDelimited' => true],
+ ],
+ 'RESULT' => [
2,
'var',
- )
- )
+ ],
+ ]
);
$this->assertEquals('(3 + 5)', (string) $component->has('SUM', true));
$this->assertEquals('8', $component->has('RESULT'));
@@ -63,14 +64,14 @@ class OptionsArrayTest extends TestCase
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('A B = /*comment*/ (test) C'),
- array(
+ [
'A' => 1,
- 'B' => array(
+ 'B' => [
2,
'var',
- ),
- 'C' => 3
- )
+ ],
+ 'C' => 3,
+ ]
);
$this->assertTrue($component->has('A'));
$this->assertEquals('test', $component->has('B'));
@@ -81,23 +82,23 @@ class OptionsArrayTest extends TestCase
public function testRemove()
{
/* Assertion 1 */
- $component = new OptionsArray(array('a', 'b', 'c'));
+ $component = new OptionsArray(['a', 'b', 'c']);
$this->assertTrue($component->remove('b'));
$this->assertFalse($component->remove('d'));
- $this->assertEquals($component->options, array(0 => 'a', 2 => 'c'));
+ $this->assertEquals($component->options, [0 => 'a', 2 => 'c']);
/* Assertion 2 */
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('A B = /*comment*/ (test) C'),
- array(
+ [
'A' => 1,
- 'B' => array(
+ 'B' => [
2,
'var',
- ),
- 'C' => 3
- )
+ ],
+ 'C' => 3,
+ ]
);
$this->assertEquals('test', $component->has('B'));
$component->remove('B');
@@ -106,23 +107,23 @@ class OptionsArrayTest extends TestCase
public function testMerge()
{
- $component = new OptionsArray(array('a'));
- $component->merge(array('b', 'c'));
- $this->assertEquals($component->options, array('a', 'b', 'c'));
+ $component = new OptionsArray(['a']);
+ $component->merge(['b', 'c']);
+ $this->assertEquals($component->options, ['a', 'b', 'c']);
}
public function testBuild()
{
$component = new OptionsArray(
- array(
+ [
'ALL',
'SQL_CALC_FOUND_ROWS',
- array(
+ [
'name' => 'MAX_STATEMENT_TIME',
'value' => '42',
'equals' => true,
- ),
- )
+ ],
+ ]
);
$this->assertEquals(
OptionsArray::build($component),
diff --git a/tests/Components/OrderKeywordTest.php b/tests/Components/OrderKeywordTest.php
index bc07d03..11468fb 100644
--- a/tests/Components/OrderKeywordTest.php
+++ b/tests/Components/OrderKeywordTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -12,10 +13,10 @@ class OrderKeywordTest extends TestCase
{
$this->assertEquals(
OrderKeyword::build(
- array(
+ [
new OrderKeyword(new Expression('a'), 'ASC'),
- new OrderKeyword(new Expression('b'), 'DESC')
- )
+ new OrderKeyword(new Expression('b'), 'DESC'),
+ ]
),
'a ASC, b DESC'
);
diff --git a/tests/Components/ParameterDefinitionTest.php b/tests/Components/ParameterDefinitionTest.php
index 683eb3a..38d28e0 100644
--- a/tests/Components/ParameterDefinitionTest.php
+++ b/tests/Components/ParameterDefinitionTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
diff --git a/tests/Components/PartitionDefinitionTest.php b/tests/Components/PartitionDefinitionTest.php
index 3c9a847..2d26076 100644
--- a/tests/Components/PartitionDefinitionTest.php
+++ b/tests/Components/PartitionDefinitionTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
diff --git a/tests/Components/ReferenceTest.php b/tests/Components/ReferenceTest.php
index dc142fe..19768c7 100644
--- a/tests/Components/ReferenceTest.php
+++ b/tests/Components/ReferenceTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
@@ -13,12 +14,12 @@ class ReferenceTest extends TestCase
{
$component = Reference::parse(new Parser(), $this->getTokensList('tbl (id)'));
$this->assertEquals('tbl', $component->table->table);
- $this->assertEquals(array('id'), $component->columns);
+ $this->assertEquals(['id'], $component->columns);
}
public function testBuild()
{
- $component = new Reference(new Expression('`tbl`'), array('id'));
+ $component = new Reference(new Expression('`tbl`'), ['id']);
$this->assertEquals('`tbl` (`id`)', Reference::build($component));
}
}
diff --git a/tests/Components/RenameOperationTest.php b/tests/Components/RenameOperationTest.php
index 919c4bd..6f38605 100644
--- a/tests/Components/RenameOperationTest.php
+++ b/tests/Components/RenameOperationTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
diff --git a/tests/Lexer/ContextTest.php b/tests/Lexer/ContextTest.php
index 980eecd..2a9c8f3 100644
--- a/tests/Lexer/ContextTest.php
+++ b/tests/Lexer/ContextTest.php
@@ -1,9 +1,11 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Lexer;
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\Tests\TestCase;
+use Throwable;
class ContextTest extends TestCase
{
@@ -29,7 +31,7 @@ class ContextTest extends TestCase
public function testLoadClosest($context, $expected)
{
$this->assertEquals($expected, Context::loadClosest($context));
- if (! is_null($expected)) {
+ if ($expected !== null) {
$this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\Context' . $expected, Context::$loadedContext);
$this->assertTrue(class_exists(Context::$loadedContext));
}
@@ -40,42 +42,42 @@ class ContextTest extends TestCase
public function contextLoading()
{
- return array(
- 'MySQL match' => array(
+ return [
+ 'MySQL match' => [
'MySql50500',
'MySql50500',
- ),
- 'MySQL strip' => array(
+ ],
+ 'MySQL strip' => [
'MySql50712',
'MySql50700',
- ),
- 'MySQL fallback' => array(
+ ],
+ 'MySQL fallback' => [
'MySql99999',
'MySql50700',
- ),
- 'MariaDB match' => array(
+ ],
+ 'MariaDB match' => [
'MariaDb100000',
'MariaDb100000',
- ),
- 'MariaDB stripg' => array(
+ ],
+ 'MariaDB stripg' => [
'MariaDb109900',
'MariaDb100000',
- ),
- 'MariaDB fallback' => array(
+ ],
+ 'MariaDB fallback' => [
'MariaDb990000',
'MariaDb100300',
- ),
- 'Invalid' => array(
+ ],
+ 'Invalid' => [
'Sql',
null,
- )
- );
+ ],
+ ];
}
/**
- * @dataProvider contextNames
- *
* @param mixed $context
+ *
+ * @dataProvider contextNames
*/
public function testLoadAll($context)
{
@@ -88,26 +90,24 @@ class ContextTest extends TestCase
public function contextNames()
{
- return array(
- array('MySql50000'),
- array('MySql50100'),
- array('MySql50500'),
- array('MySql50600'),
- array('MySql50700'),
- array('MySql80000'),
- array('MariaDb100000'),
- array('MariaDb100100'),
- array('MariaDb100200'),
- array('MariaDb100300')
- );
+ return [
+ ['MySql50000'],
+ ['MySql50100'],
+ ['MySql50500'],
+ ['MySql50600'],
+ ['MySql50700'],
+ ['MySql80000'],
+ ['MariaDb100000'],
+ ['MariaDb100100'],
+ ['MariaDb100200'],
+ ['MariaDb100300'],
+ ];
}
- /**
- * @expectedException \Exception
- * @expectedExceptionMessage Specified context ("\PhpMyAdmin\SqlParser\Contexts\ContextFoo") does not exist.
- */
public function testLoadError()
{
+ $this->expectExceptionMessage('Specified context ("\PhpMyAdmin\SqlParser\Contexts\ContextFoo") does not exist.');
+ $this->expectException(Throwable::class);
Context::load('Foo');
}
@@ -139,11 +139,11 @@ class ContextTest extends TestCase
$this->assertEquals('`test`', Context::escape('test'));
$this->assertEquals(
- array(
+ [
'`a`',
'`b`',
- ),
- Context::escape(array('a', 'b'))
+ ],
+ Context::escape(['a', 'b'])
);
}
}
diff --git a/tests/Lexer/IsMethodsTest.php b/tests/Lexer/IsMethodsTest.php
index 3a7ef9b..e967514 100644
--- a/tests/Lexer/IsMethodsTest.php
+++ b/tests/Lexer/IsMethodsTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Lexer;
diff --git a/tests/Lexer/LexerTest.php b/tests/Lexer/LexerTest.php
index 7bc2da5..92a8667 100644
--- a/tests/Lexer/LexerTest.php
+++ b/tests/Lexer/LexerTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Lexer;
@@ -26,20 +27,18 @@ class LexerTest extends TestCase
$this->assertEquals(
$lexer->errors,
- array(
+ [
new LexerException('error #1', 'foo', 1, 2),
new LexerException('error #2', 'bar', 3, 4),
- )
+ ]
);
}
- /**
- * @expectedException \PhpMyAdmin\SqlParser\Exceptions\LexerException
- * @expectedExceptionMessage strict error
- * @expectedExceptionCode 4
- */
public function testErrorStrict()
{
+ $this->expectExceptionCode(4);
+ $this->expectExceptionMessage('strict error');
+ $this->expectException(LexerException::class);
$lexer = new Lexer('');
$lexer->strict = true;
@@ -47,9 +46,9 @@ class LexerTest extends TestCase
}
/**
- * @dataProvider lexProvider
- *
* @param mixed $test
+ *
+ * @dataProvider lexProvider
*/
public function testLex($test)
{
@@ -58,33 +57,33 @@ class LexerTest extends TestCase
public function lexProvider()
{
- return array(
- array('lexer/lex'),
- array('lexer/lexUtf8'),
- array('lexer/lexBool'),
- array('lexer/lexComment'),
- array('lexer/lexCommentEnd'),
- array('lexer/lexDelimiter'),
- array('lexer/lexDelimiter2'),
- array('lexer/lexDelimiterErr1'),
- array('lexer/lexDelimiterErr2'),
- array('lexer/lexDelimiterErr3'),
- array('lexer/lexDelimiterLen'),
- array('lexer/lexKeyword'),
- array('lexer/lexKeyword2'),
- array('lexer/lexNumber'),
- array('lexer/lexOperator'),
- array('lexer/lexString'),
- array('lexer/lexStringErr1'),
- array('lexer/lexSymbol'),
- array('lexer/lexSymbolErr1'),
- array('lexer/lexSymbolErr2'),
- array('lexer/lexSymbolErr3'),
- array('lexer/lexSymbolUser'),
- array('lexer/lexWhitespace'),
- array('lexer/lexLabel1'),
- array('lexer/lexLabel2'),
- array('lexer/lexNoLabel')
- );
+ return [
+ ['lexer/lex'],
+ ['lexer/lexUtf8'],
+ ['lexer/lexBool'],
+ ['lexer/lexComment'],
+ ['lexer/lexCommentEnd'],
+ ['lexer/lexDelimiter'],
+ ['lexer/lexDelimiter2'],
+ ['lexer/lexDelimiterErr1'],
+ ['lexer/lexDelimiterErr2'],
+ ['lexer/lexDelimiterErr3'],
+ ['lexer/lexDelimiterLen'],
+ ['lexer/lexKeyword'],
+ ['lexer/lexKeyword2'],
+ ['lexer/lexNumber'],
+ ['lexer/lexOperator'],
+ ['lexer/lexString'],
+ ['lexer/lexStringErr1'],
+ ['lexer/lexSymbol'],
+ ['lexer/lexSymbolErr1'],
+ ['lexer/lexSymbolErr2'],
+ ['lexer/lexSymbolErr3'],
+ ['lexer/lexSymbolUser'],
+ ['lexer/lexWhitespace'],
+ ['lexer/lexLabel1'],
+ ['lexer/lexLabel2'],
+ ['lexer/lexNoLabel'],
+ ];
}
}
diff --git a/tests/Lexer/TokenTest.php b/tests/Lexer/TokenTest.php
index 68d3b00..ba61e32 100644
--- a/tests/Lexer/TokenTest.php
+++ b/tests/Lexer/TokenTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Lexer;
diff --git a/tests/Lexer/TokensListTest.php b/tests/Lexer/TokensListTest.php
index c1c4414..c963fdd 100644
--- a/tests/Lexer/TokensListTest.php
+++ b/tests/Lexer/TokensListTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Lexer;
@@ -18,9 +19,9 @@ class TokensListTest extends TestCase
/**
* Test setup.
*/
- public function setUp()
+ public function setUp(): void
{
- $this->tokens = array(
+ $this->tokens = [
new Token('SELECT', Token::TYPE_KEYWORD),
new Token(' ', Token::TYPE_WHITESPACE),
new Token('*', Token::TYPE_OPERATOR),
@@ -28,8 +29,8 @@ class TokensListTest extends TestCase
new Token('FROM', Token::TYPE_KEYWORD),
new Token(' ', Token::TYPE_WHITESPACE),
new Token('`test`', Token::TYPE_SYMBOL),
- new Token(' ', Token::TYPE_WHITESPACE)
- );
+ new Token(' ', Token::TYPE_WHITESPACE),
+ ];
}
public function testBuild()
diff --git a/tests/Misc/BugsTest.php b/tests/Misc/BugsTest.php
index d356b57..a467869 100644
--- a/tests/Misc/BugsTest.php
+++ b/tests/Misc/BugsTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Misc;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class BugsTest extends TestCase
{
/**
- * @dataProvider bugProvider
- *
* @param mixed $test
+ *
+ * @dataProvider bugProvider
*/
public function testBug($test)
{
@@ -18,15 +19,15 @@ class BugsTest extends TestCase
public function bugProvider()
{
- return array(
- array('bugs/gh9'),
- array('bugs/gh14'),
- array('bugs/gh16'),
- array('bugs/pma11800'),
- array('bugs/pma11836'),
- array('bugs/pma11843'),
- array('bugs/pma11867'),
- array('bugs/pma11879')
- );
+ return [
+ ['bugs/gh9'],
+ ['bugs/gh14'],
+ ['bugs/gh16'],
+ ['bugs/pma11800'],
+ ['bugs/pma11836'],
+ ['bugs/pma11843'],
+ ['bugs/pma11867'],
+ ['bugs/pma11879'],
+ ];
}
}
diff --git a/tests/Misc/ParameterTest.php b/tests/Misc/ParameterTest.php
index f2d5280..cfabfb1 100644
--- a/tests/Misc/ParameterTest.php
+++ b/tests/Misc/ParameterTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Misc;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class ParameterTest extends TestCase
{
/**
- * @dataProvider parameterProvider
- *
* @param mixed $test
+ *
+ * @dataProvider parameterProvider
*/
public function testParameter($test)
{
@@ -18,8 +19,8 @@ class ParameterTest extends TestCase
public function parameterProvider()
{
- return array(
- array('misc/parseParameter')
- );
+ return [
+ ['misc/parseParameter'],
+ ];
}
}
diff --git a/tests/Misc/UtfStringTest.php b/tests/Misc/UtfStringTest.php
index 36f0298..965812f 100644
--- a/tests/Misc/UtfStringTest.php
+++ b/tests/Misc/UtfStringTest.php
@@ -1,9 +1,11 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Misc;
use PhpMyAdmin\SqlParser\Tests\TestCase;
use PhpMyAdmin\SqlParser\UtfString;
+use Throwable;
class UtfStringTest extends TestCase
{
@@ -36,22 +38,18 @@ class UtfStringTest extends TestCase
$this->assertNull($str[static::TEST_PHRASE_LEN]);
}
- /**
- * @expectedException \Exception
- * @expectedExceptionMessage Not implemented.
- */
public function testSet()
{
+ $this->expectExceptionMessage('Not implemented.');
+ $this->expectException(Throwable::class);
$str = new UtfString('');
$str[0] = 'a';
}
- /**
- * @expectedException \Exception
- * @expectedExceptionMessage Not implemented.
- */
public function testUnset()
{
+ $this->expectExceptionMessage('Not implemented.');
+ $this->expectException(Throwable::class);
$str = new UtfString('');
unset($str[0]);
}
@@ -86,11 +84,11 @@ class UtfStringTest extends TestCase
/**
* Test access to string.
*
- * @dataProvider utf8Strings
- *
* @param mixed $text
* @param mixed $pos10
* @param mixed $pos20
+ *
+ * @dataProvider utf8Strings
*/
public function testAccess($text, $pos10, $pos20)
{
@@ -102,27 +100,27 @@ class UtfStringTest extends TestCase
public function utf8Strings()
{
- return array(
- 'ascii' => array(
+ return [
+ 'ascii' => [
'abcdefghijklmnopqrstuvwxyz',
'k',
'u',
- ),
- 'unicode' => array(
+ ],
+ 'unicode' => [
'áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň',
'ǐ',
'č',
- ),
- 'emoji' => array(
+ ],
+ 'emoji' => [
'😂😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯',
'😂',
'😋',
- ),
- 'iso' => array(
+ ],
+ 'iso' => [
"P\xf8\xed\xb9ern\xec \xbelu\xbbou\xe8k\xfd k\xf3d \xfap\xecl \xef\xe1belsk\xe9 k\xf3dy",
null,
null,
- )
- );
+ ],
+ ];
}
}
diff --git a/tests/Parser/AlterStatementTest.php b/tests/Parser/AlterStatementTest.php
index a8d6bdd..4e17677 100644
--- a/tests/Parser/AlterStatementTest.php
+++ b/tests/Parser/AlterStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class AlterStatementTest extends TestCase
{
/**
- * @dataProvider alterProvider
- *
* @param mixed $test
+ *
+ * @dataProvider alterProvider
*/
public function testAlter($test)
{
@@ -18,20 +19,20 @@ class AlterStatementTest extends TestCase
public function alterProvider()
{
- return array(
- array('parser/parseAlter'),
- array('parser/parseAlter2'),
- array('parser/parseAlter3'),
- array('parser/parseAlter4'),
- array('parser/parseAlter5'),
- array('parser/parseAlter6'),
- array('parser/parseAlter7'),
- array('parser/parseAlter8'),
- array('parser/parseAlter9'),
- array('parser/parseAlter10'),
- array('parser/parseAlterErr'),
- array('parser/parseAlterErr2'),
- array('parser/parseAlterErr3')
- );
+ return [
+ ['parser/parseAlter'],
+ ['parser/parseAlter2'],
+ ['parser/parseAlter3'],
+ ['parser/parseAlter4'],
+ ['parser/parseAlter5'],
+ ['parser/parseAlter6'],
+ ['parser/parseAlter7'],
+ ['parser/parseAlter8'],
+ ['parser/parseAlter9'],
+ ['parser/parseAlter10'],
+ ['parser/parseAlterErr'],
+ ['parser/parseAlterErr2'],
+ ['parser/parseAlterErr3'],
+ ];
}
}
diff --git a/tests/Parser/CallStatementTest.php b/tests/Parser/CallStatementTest.php
index a90d27a..3a71ce3 100644
--- a/tests/Parser/CallStatementTest.php
+++ b/tests/Parser/CallStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class CallStatementTest extends TestCase
{
/**
- * @dataProvider callProvider
- *
* @param mixed $test
+ *
+ * @dataProvider callProvider
*/
public function testCall($test)
{
@@ -18,10 +19,10 @@ class CallStatementTest extends TestCase
public function callProvider()
{
- return array(
- array('parser/parseCall'),
- array('parser/parseCall2'),
- array('parser/parseCall3')
- );
+ return [
+ ['parser/parseCall'],
+ ['parser/parseCall2'],
+ ['parser/parseCall3'],
+ ];
}
}
diff --git a/tests/Parser/CreateStatementTest.php b/tests/Parser/CreateStatementTest.php
index 3e328b1..eb69e01 100644
--- a/tests/Parser/CreateStatementTest.php
+++ b/tests/Parser/CreateStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class CreateStatementTest extends TestCase
{
/**
- * @dataProvider createProvider
- *
* @param mixed $test
+ *
+ * @dataProvider createProvider
*/
public function testCreate($test)
{
@@ -18,40 +19,40 @@ class CreateStatementTest extends TestCase
public function createProvider()
{
- return array(
- array('parser/parseCreateDatabase'),
- array('parser/parseCreateDatabaseErr'),
- array('parser/parseCreateFunction'),
- array('parser/parseCreateFunctionErr1'),
- array('parser/parseCreateFunctionErr2'),
- array('parser/parseCreateFunctionErr3'),
- array('parser/parseCreateProcedure'),
- array('parser/parseCreateProcedure2'),
- array('parser/parseCreateSchema'),
- array('parser/parseCreateSchemaErr'),
- array('parser/parseCreateTable'),
- array('parser/parseCreateTable2'),
- array('parser/parseCreateTable3'),
- array('parser/parseCreateTable4'),
- array('parser/parseCreateTable5'),
- array('parser/parseCreateTable6'),
- array('parser/parseCreateTable7'),
- array('parser/parseCreateTableErr1'),
- array('parser/parseCreateTableErr2'),
- array('parser/parseCreateTableErr3'),
- array('parser/parseCreateTableErr4'),
- array('parser/parseCreateTableErr5'),
- array('parser/parseCreateTableSelect'),
- array('parser/parseCreateTableAsSelect'),
- array('parser/parseCreateTableLike'),
- array('parser/parseCreateTableSpatial'),
- array('parser/parseCreateTableTimestampWithPrecision'),
- array('parser/parseCreateTrigger'),
- array('parser/parseCreateUser'),
- array('parser/parseCreateView'),
- array('parser/parseCreateView2'),
- array('parser/parseCreateViewWithoutQuotes'),
- array('parser/parseCreateViewWithQuotes'),
- );
+ return [
+ ['parser/parseCreateDatabase'],
+ ['parser/parseCreateDatabaseErr'],
+ ['parser/parseCreateFunction'],
+ ['parser/parseCreateFunctionErr1'],
+ ['parser/parseCreateFunctionErr2'],
+ ['parser/parseCreateFunctionErr3'],
+ ['parser/parseCreateProcedure'],
+ ['parser/parseCreateProcedure2'],
+ ['parser/parseCreateSchema'],
+ ['parser/parseCreateSchemaErr'],
+ ['parser/parseCreateTable'],
+ ['parser/parseCreateTable2'],
+ ['parser/parseCreateTable3'],
+ ['parser/parseCreateTable4'],
+ ['parser/parseCreateTable5'],
+ ['parser/parseCreateTable6'],
+ ['parser/parseCreateTable7'],
+ ['parser/parseCreateTableErr1'],
+ ['parser/parseCreateTableErr2'],
+ ['parser/parseCreateTableErr3'],
+ ['parser/parseCreateTableErr4'],
+ ['parser/parseCreateTableErr5'],
+ ['parser/parseCreateTableSelect'],
+ ['parser/parseCreateTableAsSelect'],
+ ['parser/parseCreateTableLike'],
+ ['parser/parseCreateTableSpatial'],
+ ['parser/parseCreateTableTimestampWithPrecision'],
+ ['parser/parseCreateTrigger'],
+ ['parser/parseCreateUser'],
+ ['parser/parseCreateView'],
+ ['parser/parseCreateView2'],
+ ['parser/parseCreateViewWithoutQuotes'],
+ ['parser/parseCreateViewWithQuotes'],
+ ];
}
}
diff --git a/tests/Parser/DeleteStatementTest.php b/tests/Parser/DeleteStatementTest.php
index 75f3b09..dc22c02 100644
--- a/tests/Parser/DeleteStatementTest.php
+++ b/tests/Parser/DeleteStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class DeleteStatementTest extends TestCase
{
/**
- * @dataProvider deleteProvider
- *
* @param mixed $test
+ *
+ * @dataProvider deleteProvider
*/
public function testDelete($test)
{
@@ -18,32 +19,32 @@ class DeleteStatementTest extends TestCase
public function deleteProvider()
{
- return array(
- array('parser/parseDelete'),
- array('parser/parseDelete2'),
- array('parser/parseDelete3'),
- array('parser/parseDelete4'),
- array('parser/parseDelete5'),
- array('parser/parseDelete6'),
- array('parser/parseDelete7'),
- array('parser/parseDelete8'),
- array('parser/parseDelete9'),
- array('parser/parseDelete10'),
- array('parser/parseDelete11'),
- array('parser/parseDelete12'),
- array('parser/parseDeleteErr1'),
- array('parser/parseDeleteErr2'),
- array('parser/parseDeleteErr3'),
- array('parser/parseDeleteErr4'),
- array('parser/parseDeleteErr5'),
- array('parser/parseDeleteErr6'),
- array('parser/parseDeleteErr7'),
- array('parser/parseDeleteErr8'),
- array('parser/parseDeleteErr9'),
- array('parser/parseDeleteErr10'),
- array('parser/parseDeleteErr11'),
- array('parser/parseDeleteErr12'),
- array('parser/parseDeleteJoin')
- );
+ return [
+ ['parser/parseDelete'],
+ ['parser/parseDelete2'],
+ ['parser/parseDelete3'],
+ ['parser/parseDelete4'],
+ ['parser/parseDelete5'],
+ ['parser/parseDelete6'],
+ ['parser/parseDelete7'],
+ ['parser/parseDelete8'],
+ ['parser/parseDelete9'],
+ ['parser/parseDelete10'],
+ ['parser/parseDelete11'],
+ ['parser/parseDelete12'],
+ ['parser/parseDeleteErr1'],
+ ['parser/parseDeleteErr2'],
+ ['parser/parseDeleteErr3'],
+ ['parser/parseDeleteErr4'],
+ ['parser/parseDeleteErr5'],
+ ['parser/parseDeleteErr6'],
+ ['parser/parseDeleteErr7'],
+ ['parser/parseDeleteErr8'],
+ ['parser/parseDeleteErr9'],
+ ['parser/parseDeleteErr10'],
+ ['parser/parseDeleteErr11'],
+ ['parser/parseDeleteErr12'],
+ ['parser/parseDeleteJoin'],
+ ];
}
}
diff --git a/tests/Parser/ExplainStatementTest.php b/tests/Parser/ExplainStatementTest.php
index db66a0a..c00a99d 100644
--- a/tests/Parser/ExplainStatementTest.php
+++ b/tests/Parser/ExplainStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class ExplainStatementTest extends TestCase
{
/**
- * @dataProvider explainProvider
- *
* @param mixed $test
+ *
+ * @dataProvider explainProvider
*/
public function testExplain($test)
{
@@ -18,8 +19,8 @@ class ExplainStatementTest extends TestCase
public function explainProvider()
{
- return array(
- array('parser/parseExplain')
- );
+ return [
+ ['parser/parseExplain'],
+ ];
}
}
diff --git a/tests/Parser/InsertStatementTest.php b/tests/Parser/InsertStatementTest.php
index f0e4b5d..503cae9 100644
--- a/tests/Parser/InsertStatementTest.php
+++ b/tests/Parser/InsertStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class InsertStatementTest extends TestCase
{
/**
- * @dataProvider insertProvider
- *
* @param mixed $test
+ *
+ * @dataProvider insertProvider
*/
public function testInsert($test)
{
@@ -18,16 +19,16 @@ class InsertStatementTest extends TestCase
public function insertProvider()
{
- return array(
- array('parser/parseInsert'),
- array('parser/parseInsertSelect'),
- array('parser/parseInsertOnDuplicateKey'),
- array('parser/parseInsertSetOnDuplicateKey'),
- array('parser/parseInsertSelectOnDuplicateKey'),
- array('parser/parseInsertOnDuplicateKeyErr'),
- array('parser/parseInsertErr'),
- array('parser/parseInsertErr2'),
- array('parser/parseInsertIntoErr')
- );
+ return [
+ ['parser/parseInsert'],
+ ['parser/parseInsertSelect'],
+ ['parser/parseInsertOnDuplicateKey'],
+ ['parser/parseInsertSetOnDuplicateKey'],
+ ['parser/parseInsertSelectOnDuplicateKey'],
+ ['parser/parseInsertOnDuplicateKeyErr'],
+ ['parser/parseInsertErr'],
+ ['parser/parseInsertErr2'],
+ ['parser/parseInsertIntoErr'],
+ ];
}
}
diff --git a/tests/Parser/LoadStatementTest.php b/tests/Parser/LoadStatementTest.php
index 70d0a64..d19a012 100644
--- a/tests/Parser/LoadStatementTest.php
+++ b/tests/Parser/LoadStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -16,9 +17,9 @@ class LoadStatementTest extends TestCase
}
/**
- * @dataProvider loadProvider
- *
* @param mixed $test
+ *
+ * @dataProvider loadProvider
*/
public function testLoad($test)
{
@@ -27,19 +28,19 @@ class LoadStatementTest extends TestCase
public function loadProvider()
{
- return array(
- array('parser/parseLoad1'),
- array('parser/parseLoad2'),
- array('parser/parseLoad3'),
- array('parser/parseLoad4'),
- array('parser/parseLoad5'),
- array('parser/parseLoad6'),
- array('parser/parseLoadErr1'),
- array('parser/parseLoadErr2'),
- array('parser/parseLoadErr3'),
- array('parser/parseLoadErr4'),
- array('parser/parseLoadErr5'),
- array('parser/parseLoadErr6')
- );
+ return [
+ ['parser/parseLoad1'],
+ ['parser/parseLoad2'],
+ ['parser/parseLoad3'],
+ ['parser/parseLoad4'],
+ ['parser/parseLoad5'],
+ ['parser/parseLoad6'],
+ ['parser/parseLoadErr1'],
+ ['parser/parseLoadErr2'],
+ ['parser/parseLoadErr3'],
+ ['parser/parseLoadErr4'],
+ ['parser/parseLoadErr5'],
+ ['parser/parseLoadErr6'],
+ ];
}
}
diff --git a/tests/Parser/LockStatementTest.php b/tests/Parser/LockStatementTest.php
index 5460254..d3c6e5d 100644
--- a/tests/Parser/LockStatementTest.php
+++ b/tests/Parser/LockStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class LockStatementTest extends TestCase
{
/**
- * @dataProvider lockProvider
- *
* @param mixed $test
+ *
+ * @dataProvider lockProvider
*/
public function testLock($test)
{
@@ -18,24 +19,24 @@ class LockStatementTest extends TestCase
public function lockProvider()
{
- return array(
- array('parser/parseLock1'),
- array('parser/parseLock2'),
- array('parser/parseLock3'),
- array('parser/parseLock4'),
- array('parser/parseLock5'),
- array('parser/parseLockErr1'),
- array('parser/parseLockErr2'),
- array('parser/parseLockErr3'),
- array('parser/parseLockErr4'),
- array('parser/parseLockErr5'),
- array('parser/parseLockErr6'),
- array('parser/parseLockErr7'),
- array('parser/parseLockErr8'),
- array('parser/parseLockErr9'),
- array('parser/parseLockErr10'),
- array('parser/parseUnlock1'),
- array('parser/parseUnlockErr1')
- );
+ return [
+ ['parser/parseLock1'],
+ ['parser/parseLock2'],
+ ['parser/parseLock3'],
+ ['parser/parseLock4'],
+ ['parser/parseLock5'],
+ ['parser/parseLockErr1'],
+ ['parser/parseLockErr2'],
+ ['parser/parseLockErr3'],
+ ['parser/parseLockErr4'],
+ ['parser/parseLockErr5'],
+ ['parser/parseLockErr6'],
+ ['parser/parseLockErr7'],
+ ['parser/parseLockErr8'],
+ ['parser/parseLockErr9'],
+ ['parser/parseLockErr10'],
+ ['parser/parseUnlock1'],
+ ['parser/parseUnlockErr1'],
+ ];
}
}
diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php
index 57c4aae..cba4868 100644
--- a/tests/Parser/ParserTest.php
+++ b/tests/Parser/ParserTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -11,9 +12,9 @@ use PhpMyAdmin\SqlParser\TokensList;
class ParserTest extends TestCase
{
/**
- * @dataProvider parseProvider
- *
* @param mixed $test
+ *
+ * @dataProvider parseProvider
*/
public function testParse($test)
{
@@ -22,11 +23,11 @@ class ParserTest extends TestCase
public function parseProvider()
{
- return array(
- array('parser/parse'),
- array('parser/parse2'),
- array('parser/parseDelimiter')
- );
+ return [
+ ['parser/parse'],
+ ['parser/parse2'],
+ ['parser/parseDelimiter'],
+ ];
}
public function testUnrecognizedStatement()
@@ -60,20 +61,18 @@ class ParserTest extends TestCase
$this->assertEquals(
$parser->errors,
- array(
+ [
new ParserException('error #1', new Token('foo'), 1),
new ParserException('error #2', new Token('bar'), 2),
- )
+ ]
);
}
- /**
- * @expectedException \PhpMyAdmin\SqlParser\Exceptions\ParserException
- * @expectedExceptionMessage strict error
- * @expectedExceptionCode 3
- */
public function testErrorStrict()
{
+ $this->expectExceptionCode(3);
+ $this->expectExceptionMessage('strict error');
+ $this->expectException(ParserException::class);
$parser = new Parser(new TokensList());
$parser->strict = true;
diff --git a/tests/Parser/PurgeStatementTest.php b/tests/Parser/PurgeStatementTest.php
index 364c5a3..4e66e52 100644
--- a/tests/Parser/PurgeStatementTest.php
+++ b/tests/Parser/PurgeStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class PurgeStatementTest extends TestCase
{
/**
- * @dataProvider purgeProvider
- *
* @param mixed $test
+ *
+ * @dataProvider purgeProvider
*/
public function testPurge($test)
{
@@ -18,14 +19,14 @@ class PurgeStatementTest extends TestCase
public function purgeProvider()
{
- return array(
- array('parser/parsePurge'),
- array('parser/parsePurge2'),
- array('parser/parsePurge3'),
- array('parser/parsePurge4'),
- array('parser/parsePurgeErr'),
- array('parser/parsePurgeErr2'),
- array('parser/parsePurgeErr3')
- );
+ return [
+ ['parser/parsePurge'],
+ ['parser/parsePurge2'],
+ ['parser/parsePurge3'],
+ ['parser/parsePurge4'],
+ ['parser/parsePurgeErr'],
+ ['parser/parsePurgeErr2'],
+ ['parser/parsePurgeErr3'],
+ ];
}
}
diff --git a/tests/Parser/RenameStatementTest.php b/tests/Parser/RenameStatementTest.php
index bb13c3c..bfbe34f 100644
--- a/tests/Parser/RenameStatementTest.php
+++ b/tests/Parser/RenameStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class RenameStatementTest extends TestCase
{
/**
- * @dataProvider renameProvider
- *
* @param mixed $test
+ *
+ * @dataProvider renameProvider
*/
public function testRename($test)
{
@@ -18,14 +19,14 @@ class RenameStatementTest extends TestCase
public function renameProvider()
{
- return array(
- array('parser/parseRename'),
- array('parser/parseRename2'),
- array('parser/parseRenameErr1'),
- array('parser/parseRenameErr2'),
- array('parser/parseRenameErr3'),
- array('parser/parseRenameErr4'),
- array('parser/parseRenameErr5')
- );
+ return [
+ ['parser/parseRename'],
+ ['parser/parseRename2'],
+ ['parser/parseRenameErr1'],
+ ['parser/parseRenameErr2'],
+ ['parser/parseRenameErr3'],
+ ['parser/parseRenameErr4'],
+ ['parser/parseRenameErr5'],
+ ];
}
}
diff --git a/tests/Parser/ReplaceStatementTest.php b/tests/Parser/ReplaceStatementTest.php
index edac536..4698c4b 100644
--- a/tests/Parser/ReplaceStatementTest.php
+++ b/tests/Parser/ReplaceStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class ReplaceStatementTest extends TestCase
{
/**
- * @dataProvider replaceProvider
- *
* @param mixed $test
+ *
+ * @dataProvider replaceProvider
*/
public function testReplace($test)
{
@@ -18,16 +19,16 @@ class ReplaceStatementTest extends TestCase
public function replaceProvider()
{
- return array(
- array('parser/parseReplace'),
- array('parser/parseReplace2'),
- array('parser/parseReplaceValues'),
- array('parser/parseReplaceSet'),
- array('parser/parseReplaceSelect'),
- array('parser/parseReplaceErr'),
- array('parser/parseReplaceErr2'),
- array('parser/parseReplaceErr3'),
- array('parser/parseReplaceIntoErr')
- );
+ return [
+ ['parser/parseReplace'],
+ ['parser/parseReplace2'],
+ ['parser/parseReplaceValues'],
+ ['parser/parseReplaceSet'],
+ ['parser/parseReplaceSelect'],
+ ['parser/parseReplaceErr'],
+ ['parser/parseReplaceErr2'],
+ ['parser/parseReplaceErr3'],
+ ['parser/parseReplaceIntoErr'],
+ ];
}
}
diff --git a/tests/Parser/RestoreStatementTest.php b/tests/Parser/RestoreStatementTest.php
index 7fa9a5d..783c68e 100644
--- a/tests/Parser/RestoreStatementTest.php
+++ b/tests/Parser/RestoreStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class RestoreStatementTest extends TestCase
{
/**
- * @dataProvider restoreProvider
- *
* @param mixed $test
+ *
+ * @dataProvider restoreProvider
*/
public function testRestore($test)
{
@@ -18,8 +19,8 @@ class RestoreStatementTest extends TestCase
public function restoreProvider()
{
- return array(
- array('parser/parseRestore')
- );
+ return [
+ ['parser/parseRestore'],
+ ];
}
}
diff --git a/tests/Parser/SelectStatementTest.php b/tests/Parser/SelectStatementTest.php
index f4e1e90..3649412 100644
--- a/tests/Parser/SelectStatementTest.php
+++ b/tests/Parser/SelectStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -16,9 +17,9 @@ class SelectStatementTest extends TestCase
}
/**
- * @dataProvider selectProvider
- *
* @param mixed $test
+ *
+ * @dataProvider selectProvider
*/
public function testSelect($test)
{
@@ -27,65 +28,65 @@ class SelectStatementTest extends TestCase
public function selectProvider()
{
- return array(
- array('parser/parseSelect2'),
- array('parser/parseSelect3'),
- array('parser/parseSelect4'),
- array('parser/parseSelect5'),
- array('parser/parseSelect6'),
- array('parser/parseSelect7'),
- array('parser/parseSelect8'),
- array('parser/parseSelect9'),
- array('parser/parseSelect10'),
- array('parser/parseSelect11'),
- array('parser/parseSelectErr1'),
- array('parser/parseSelectErr2'),
- array('parser/parseSelectNested'),
- array('parser/parseSelectCase1'),
- array('parser/parseSelectCase2'),
- array('parser/parseSelectCase3'),
- array('parser/parseSelectCase4'),
- array('parser/parseSelectCase5'),
- array('parser/parseSelectCaseErr1'),
- array('parser/parseSelectCaseErr2'),
- array('parser/parseSelectCaseErr3'),
- array('parser/parseSelectCaseErr4'),
- array('parser/parseSelectCaseErr5'),
- array('parser/parseSelectCaseAlias1'),
- array('parser/parseSelectCaseAlias2'),
- array('parser/parseSelectCaseAlias3'),
- array('parser/parseSelectCaseAlias4'),
- array('parser/parseSelectCaseAlias5'),
- array('parser/parseSelectCaseAlias6'),
- array('parser/parseSelectCaseAliasErr1'),
- array('parser/parseSelectCaseAliasErr2'),
- array('parser/parseSelectCaseAliasErr3'),
- array('parser/parseSelectCaseAliasErr4'),
- array('parser/parseSelectIntoOptions1'),
- array('parser/parseSelectIntoOptions2'),
- array('parser/parseSelectIntoOptions3'),
- array('parser/parseSelectJoinCross'),
- array('parser/parseSelectJoinNatural'),
- array('parser/parseSelectJoinNaturalLeft'),
- array('parser/parseSelectJoinNaturalRight'),
- array('parser/parseSelectJoinNaturalLeftOuter'),
- array('parser/parseSelectJoinNaturalRightOuter'),
- array('parser/parseSelectJoinMultiple'),
- array('parser/parseSelectJoinMultiple2'),
- array('parser/parseSelectWrongOrder'),
- array('parser/parseSelectWrongOrder2'),
- array('parser/parseSelectEndOptions1'),
- array('parser/parseSelectEndOptions2'),
- array('parser/parseSelectEndOptionsErr'),
- array('parser/parseSelectUnion'),
- array('parser/parseSelectUnion2'),
- array('parser/parseSelectIndexHint1'),
- array('parser/parseSelectIndexHint2'),
- array('parser/parseSelectIndexHintErr1'),
- array('parser/parseSelectIndexHintErr2'),
- array('parser/parseSelectIndexHintErr3'),
- array('parser/parseSelectIndexHintErr4'),
- array('parser/parseSelectWithParenthesis')
- );
+ return [
+ ['parser/parseSelect2'],
+ ['parser/parseSelect3'],
+ ['parser/parseSelect4'],
+ ['parser/parseSelect5'],
+ ['parser/parseSelect6'],
+ ['parser/parseSelect7'],
+ ['parser/parseSelect8'],
+ ['parser/parseSelect9'],
+ ['parser/parseSelect10'],
+ ['parser/parseSelect11'],
+ ['parser/parseSelectErr1'],
+ ['parser/parseSelectErr2'],
+ ['parser/parseSelectNested'],
+ ['parser/parseSelectCase1'],
+ ['parser/parseSelectCase2'],
+ ['parser/parseSelectCase3'],
+ ['parser/parseSelectCase4'],
+ ['parser/parseSelectCase5'],
+ ['parser/parseSelectCaseErr1'],
+ ['parser/parseSelectCaseErr2'],
+ ['parser/parseSelectCaseErr3'],
+ ['parser/parseSelectCaseErr4'],
+ ['parser/parseSelectCaseErr5'],
+ ['parser/parseSelectCaseAlias1'],
+ ['parser/parseSelectCaseAlias2'],
+ ['parser/parseSelectCaseAlias3'],
+ ['parser/parseSelectCaseAlias4'],
+ ['parser/parseSelectCaseAlias5'],
+ ['parser/parseSelectCaseAlias6'],
+ ['parser/parseSelectCaseAliasErr1'],
+ ['parser/parseSelectCaseAliasErr2'],
+ ['parser/parseSelectCaseAliasErr3'],
+ ['parser/parseSelectCaseAliasErr4'],
+ ['parser/parseSelectIntoOptions1'],
+ ['parser/parseSelectIntoOptions2'],
+ ['parser/parseSelectIntoOptions3'],
+ ['parser/parseSelectJoinCross'],
+ ['parser/parseSelectJoinNatural'],
+ ['parser/parseSelectJoinNaturalLeft'],
+ ['parser/parseSelectJoinNaturalRight'],
+ ['parser/parseSelectJoinNaturalLeftOuter'],
+ ['parser/parseSelectJoinNaturalRightOuter'],
+ ['parser/parseSelectJoinMultiple'],
+ ['parser/parseSelectJoinMultiple2'],
+ ['parser/parseSelectWrongOrder'],
+ ['parser/parseSelectWrongOrder2'],
+ ['parser/parseSelectEndOptions1'],
+ ['parser/parseSelectEndOptions2'],
+ ['parser/parseSelectEndOptionsErr'],
+ ['parser/parseSelectUnion'],
+ ['parser/parseSelectUnion2'],
+ ['parser/parseSelectIndexHint1'],
+ ['parser/parseSelectIndexHint2'],
+ ['parser/parseSelectIndexHintErr1'],
+ ['parser/parseSelectIndexHintErr2'],
+ ['parser/parseSelectIndexHintErr3'],
+ ['parser/parseSelectIndexHintErr4'],
+ ['parser/parseSelectWithParenthesis'],
+ ];
}
}
diff --git a/tests/Parser/SetStatementTest.php b/tests/Parser/SetStatementTest.php
index 9d31659..9c8af23 100644
--- a/tests/Parser/SetStatementTest.php
+++ b/tests/Parser/SetStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class SetStatementTest extends TestCase
{
/**
- * @dataProvider setProvider
- *
* @param mixed $test
+ *
+ * @dataProvider setProvider
*/
public function testSet($test)
{
@@ -18,14 +19,14 @@ class SetStatementTest extends TestCase
public function setProvider()
{
- return array(
- array('parser/parseSetCharset'),
- array('parser/parseSetCharsetError'),
- array('parser/parseSetCharacterSet'),
- array('parser/parseSetCharacterSetError'),
- array('parser/parseSetNames'),
- array('parser/parseSetNamesError'),
- array('parser/parseSetError1')
- );
+ return [
+ ['parser/parseSetCharset'],
+ ['parser/parseSetCharsetError'],
+ ['parser/parseSetCharacterSet'],
+ ['parser/parseSetCharacterSetError'],
+ ['parser/parseSetNames'],
+ ['parser/parseSetNamesError'],
+ ['parser/parseSetError1'],
+ ];
}
}
diff --git a/tests/Parser/TransactionStatementTest.php b/tests/Parser/TransactionStatementTest.php
index 599015f..b4b8fca 100644
--- a/tests/Parser/TransactionStatementTest.php
+++ b/tests/Parser/TransactionStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class TransactionStatementTest extends TestCase
{
/**
- * @dataProvider transactionProvider
- *
* @param mixed $test
+ *
+ * @dataProvider transactionProvider
*/
public function testTransaction($test)
{
@@ -18,11 +19,11 @@ class TransactionStatementTest extends TestCase
public function transactionProvider()
{
- return array(
- array('parser/parseTransaction'),
- array('parser/parseTransaction2'),
- array('parser/parseTransaction3'),
- array('parser/parseTransactionErr1')
- );
+ return [
+ ['parser/parseTransaction'],
+ ['parser/parseTransaction2'],
+ ['parser/parseTransaction3'],
+ ['parser/parseTransactionErr1'],
+ ];
}
}
diff --git a/tests/Parser/UpdateStatementTest.php b/tests/Parser/UpdateStatementTest.php
index 210e1ab..2ebb478 100644
--- a/tests/Parser/UpdateStatementTest.php
+++ b/tests/Parser/UpdateStatementTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Parser;
@@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class UpdateStatementTest extends TestCase
{
/**
- * @dataProvider updateProvider
- *
* @param mixed $test
+ *
+ * @dataProvider updateProvider
*/
public function testUpdate($test)
{
@@ -18,11 +19,11 @@ class UpdateStatementTest extends TestCase
public function updateProvider()
{
- return array(
- array('parser/parseUpdate'),
- array('parser/parseUpdate2'),
- array('parser/parseUpdate3'),
- array('parser/parseUpdateErr')
- );
+ return [
+ ['parser/parseUpdate'],
+ ['parser/parseUpdate2'],
+ ['parser/parseUpdate3'],
+ ['parser/parseUpdateErr'],
+ ];
}
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index fb6af8d..d464f24 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -1,11 +1,13 @@
<?php
-
/**
* Bootstrap for tests.
*/
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests;
+use PhpMyAdmin\SqlParser\Exceptions\LexerException;
+use PhpMyAdmin\SqlParser\Exceptions\ParserException;
use PhpMyAdmin\SqlParser\Lexer;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\TokensList;
@@ -15,10 +17,6 @@ $GLOBALS['lang'] = 'en';
/**
* Implements useful methods for testing.
- *
- * @category Tests
- *
- * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
abstract class TestCase extends BaseTestCase
{
@@ -45,20 +43,21 @@ abstract class TestCase extends BaseTestCase
*/
public function getErrorsAsArray($obj)
{
- $ret = array();
+ $ret = [];
+ /** @var LexerException|ParserException $err */
foreach ($obj->errors as $err) {
$ret[] = $obj instanceof Lexer
- ? array(
+ ? [
$err->getMessage(),
$err->ch,
$err->pos,
$err->getCode(),
- )
- : array(
+ ]
+ : [
$err->getMessage(),
$err->token,
- $err->getCode()
- );
+ $err->getCode(),
+ ];
}
return $ret;
@@ -101,14 +100,14 @@ abstract class TestCase extends BaseTestCase
// Lexer.
$lexer = new Lexer($data['query']);
$lexerErrors = $this->getErrorsAsArray($lexer);
- $lexer->errors = array();
+ $lexer->errors = [];
// Parser.
$parser = empty($data['parser']) ? null : new Parser($lexer->list);
- $parserErrors = array();
+ $parserErrors = [];
if ($parser !== null) {
$parserErrors = $this->getErrorsAsArray($parser);
- $parser->errors = array();
+ $parser->errors = [];
}
// Testing objects.
diff --git a/tests/Utils/BufferedQueryTest.php b/tests/Utils/BufferedQueryTest.php
index 164c31e..2718126 100644
--- a/tests/Utils/BufferedQueryTest.php
+++ b/tests/Utils/BufferedQueryTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Utils;
@@ -8,10 +9,10 @@ use PhpMyAdmin\SqlParser\Utils\BufferedQuery;
class BufferedQueryTest extends TestCase
{
/**
- * @dataProvider extractProvider
- *
* @param mixed $query
* @param mixed $chunkSize
+ *
+ * @dataProvider extractProvider
*/
public function testExtract(
$query,
@@ -27,7 +28,7 @@ class BufferedQueryTest extends TestCase
*
* @var array
*/
- $statements = array();
+ $statements = [];
/**
* The `BufferedQuery` instance used for extraction.
@@ -99,21 +100,21 @@ 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(
+ [
"CREATE TABLE `test` (\n" .
" `txt` varchar(10)\n" .
");\n" .
@@ -121,58 +122,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 */',
@@ -216,17 +217,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 */',
@@ -274,17 +275,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 */;',
@@ -328,8 +329,8 @@ class BufferedQueryTest extends TestCase
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;',
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
- ),
- )
- );
+ ],
+ ],
+ ];
}
}
diff --git a/tests/Utils/CLITest.php b/tests/Utils/CLITest.php
index 4caa70d..2f7102f 100644
--- a/tests/Utils/CLITest.php
+++ b/tests/Utils/CLITest.php
@@ -1,14 +1,16 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Utils;
use PhpMyAdmin\SqlParser\Tests\TestCase;
+use PhpMyAdmin\SqlParser\Utils\CLI;
class CLITest extends TestCase
{
private function getCLI($getopt)
{
- $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(array('getopt'))->getMock();
+ $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(['getopt'])->getMock();
$cli->method('getopt')->willReturn($getopt);
return $cli;
@@ -16,7 +18,7 @@ class CLITest extends TestCase
private function getCLIStdIn($input, $getopt)
{
- $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(array('getopt', 'readStdin'))->getMock();
+ $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(['getopt', 'readStdin'])->getMock();
$cli->method('getopt')->willReturn($getopt);
$cli->method('readStdin')->willReturn($input);
return $cli;
@@ -29,19 +31,19 @@ class CLITest extends TestCase
*/
public function testGetopt()
{
- $cli = new \PhpMyAdmin\SqlParser\Utils\CLI();
+ $cli = new CLI();
$this->assertEquals(
- $cli->getopt('', array()),
- array()
+ $cli->getopt('', []),
+ []
);
}
/**
- * @dataProvider highlightParams
- *
* @param mixed $getopt
* @param mixed $output
* @param mixed $result
+ *
+ * @dataProvider highlightParams
*/
public function testRunHighlight($getopt, $output, $result)
{
@@ -52,61 +54,61 @@ class CLITest extends TestCase
public function highlightParams()
{
- 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/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>' . "\n",
- 0
- ),
- array(
- array('h' => true),
+ 0,
+ ],
+ [
+ ['h' => true],
'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n" .
' cat file.sql | highlight-query' . "\n",
- 0
- ),
- array(
- array(),
+ 0,
+ ],
+ [
+ [],
'ERROR: Missing parameters!' . "\n" .
'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n" .
' cat file.sql | highlight-query' . "\n",
1,
- ),
- array(
+ ],
+ [
false,
'',
- 1
- )
- );
+ 1,
+ ],
+ ];
}
@@ -127,69 +129,69 @@ class CLITest extends TestCase
public function highlightParamsStdIn()
{
- 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',
- ),
+ ],
"SELECT\n /* comment */ 1 /* other */\n",
- 0
- ),
- array(
+ 0,
+ ],
+ [
'SELECT 1',
- array(
+ [
'f' => 'foo',
- ),
+ ],
"ERROR: Invalid value for format!\n",
- 1
- ),
- array(
+ 1,
+ ],
+ [
'SELECT 1',
- array(
+ [
'f' => 'html',
- ),
+ ],
'<span class="sql-reserved">SELECT</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>' . "\n",
- 0
- ),
- array(
+ 0,
+ ],
+ [
'',
- array('h' => true),
+ ['h' => true],
'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n" .
' cat file.sql | highlight-query' . "\n",
- 0
- ),
- array(
+ 0,
+ ],
+ [
'',
- array(),
+ [],
'ERROR: Missing parameters!' . "\n" .
'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n" .
' cat file.sql | highlight-query' . "\n",
1,
- ),
- array(
+ ],
+ [
'',
false,
'',
- 1
- )
- );
+ 1,
+ ],
+ ];
}
/**
- * @dataProvider lintParamsStdIn
- *
* @param mixed $input
* @param mixed $getopt
* @param mixed $output
* @param mixed $result
+ *
+ * @dataProvider lintParamsStdIn
*/
public function testRunLintFromStdIn($input, $getopt, $output, $result)
{
@@ -200,59 +202,59 @@ class CLITest extends TestCase
public function lintParamsStdIn()
{
- 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' . "\n" .
' cat file.sql | lint-query' . "\n",
1,
- ),
- array(
+ ],
+ [
'',
- array('h' => true),
+ ['h' => true],
'Usage: lint-query --query SQL' . "\n" .
' cat file.sql | lint-query' . "\n",
0,
- ),
- array(
+ ],
+ [
'',
false,
'',
1,
- )
- );
+ ],
+ ];
}
/**
- * @dataProvider lintParams
- *
* @param mixed $getopt
* @param mixed $output
* @param mixed $result
+ *
+ * @dataProvider lintParams
*/
public function testRunLint($getopt, $output, $result)
{
@@ -263,58 +265,61 @@ class CLITest extends TestCase
public function lintParams()
{
- 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' . "\n" .
' cat file.sql | lint-query' . "\n",
0,
- ),
- array(
- array(),
+ ],
+ [
+ [],
'ERROR: Missing parameters!' . "\n" .
'Usage: lint-query --query SQL' . "\n" .
' cat file.sql | lint-query' . "\n",
1,
- ),
- array(
+ ],
+ [
false,
'',
1,
- )
- );
+ ],
+ ];
}
/**
- * @dataProvider tokenizeParams
- *
* @param mixed $getopt
* @param mixed $output
* @param mixed $result
+ *
+ * @dataProvider tokenizeParams
*/
public function testRunTokenize($getopt, $output, $result)
{
@@ -325,52 +330,50 @@ class CLITest extends TestCase
public function tokenizeParams()
{
- $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' . "\n" .
' cat file.sql | tokenize-query' . "\n",
0,
- ),
- array(
- array(),
+ ],
+ [
+ [],
'ERROR: Missing parameters!' . "\n" .
'Usage: tokenize-query --query SQL' . "\n" .
' cat file.sql | tokenize-query' . "\n",
1,
- ),
- array(
+ ],
+ [
false,
'',
1,
- )
- );
+ ],
+ ];
}
/**
- * @dataProvider tokenizeParamsStdIn
- *
* @param mixed $input
* @param mixed $getopt
* @param mixed $output
* @param mixed $result
+ *
+ * @dataProvider tokenizeParamsStdIn
*/
public function testRunTokenizeStdIn($input, $getopt, $output, $result)
{
@@ -388,64 +391,78 @@ class CLITest extends TestCase
. "[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' . "\n" .
' cat file.sql | tokenize-query' . "\n",
0,
- ),
- array(
+ ],
+ [
'',
- array(),
+ [],
'ERROR: Missing parameters!' . "\n" .
'Usage: tokenize-query --query SQL' . "\n" .
' cat file.sql | tokenize-query' . "\n",
1,
- ),
- array(
+ ],
+ [
'',
false,
'',
1,
- )
- );
+ ],
+ ];
}
/**
- * @dataProvider stdinParams
- *
* @param string $cmd
- * @param int $result
+ * @param int $result
+ *
+ * @dataProvider stdinParams
*/
public function testStdinPipe($cmd, $result)
{
- exec ($cmd, $out, $ret);
+ exec($cmd, $out, $ret);
$this->assertSame($result, $ret);
}
public function stdinParams()
{
- 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,
+ ],
+ ];
}
}
diff --git a/tests/Utils/ErrorTest.php b/tests/Utils/ErrorTest.php
index be8e17d..eec1130 100644
--- a/tests/Utils/ErrorTest.php
+++ b/tests/Utils/ErrorTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Utils;
@@ -14,33 +15,36 @@ class ErrorTest extends TestCase
$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()
{
$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]])
);
}
}
diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php
index 3551dc6..f3c6422 100644
--- a/tests/Utils/FormatterTest.php
+++ b/tests/Utils/FormatterTest.php
@@ -1,56 +1,58 @@
<?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 mixed $default
* @param mixed $overriding
* @param mixed $expected
+ *
+ * @dataProvider mergeFormats
*/
public function testMergeFormats($default, $overriding, $expected)
{
$formatter = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\Formatter')
->disableOriginalConstructor()
- ->setMethods(array('getDefaultOptions', 'getDefaultFormats'))
+ ->setMethods(['getDefaultOptions', 'getDefaultFormats'])
->getMock();
$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));
}
@@ -58,219 +60,219 @@ class FormatterTest extends TestCase
public function mergeFormats()
{
// array($default[], $overriding[], $expected[])
- return array(
- 'empty formats' => array(
- 'default' => array(
- array(
+ 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' => '',
- ),
- ),
- )
- );
+ ],
+ ],
+ ],
+ ];
}
/**
- * @dataProvider formatQueries
- *
* @param mixed $query
* @param mixed $text
* @param mixed $cli
* @param mixed $html
+ *
+ * @dataProvider formatQueries
*/
- public function testFormat($query, $text, $cli, $html, array $options = array())
+ public function testFormat($query, $text, $cli, $html, array $options = [])
{
// Test TEXT format
- $this->assertEquals($text, Formatter::format($query, array('type' => 'text') + $options), 'Text formatting failed.');
+ $this->assertEquals($text, Formatter::format($query, ['type' => 'text'] + $options), 'Text formatting failed.');
// Test CLI format
- $this->assertEquals($cli, Formatter::format($query, array('type' => 'cli') + $options), 'CLI formatting failed.');
+ $this->assertEquals($cli, Formatter::format($query, ['type' => 'cli'] + $options), 'CLI formatting failed.');
// Test HTML format
- $this->assertEquals($html, Formatter::format($query, array('type' => 'html') + $options), 'HTML formatting failed.');
+ $this->assertEquals($html, Formatter::format($query, ['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/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>',
- ),
- 'simply' => array(
+ ],
+ 'simply' => [
'query' => 'select * from tbl where 1',
'text' => 'SELECT' . "\n" .
' *' . "\n" .
@@ -278,20 +280,20 @@ 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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;*' . '<br/>' .
- '<span class="sql-reserved">FROM</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;*<br/>' .
+ '<span class="sql-reserved">FROM</span><br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;tbl<br/>' .
+ '<span class="sql-reserved">WHERE</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>',
- ),
- 'typical' => array(
+ ],
+ '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" .
@@ -306,34 +308,34 @@ 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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;id,' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-variable">`tbl`</span>' . '<br/>' .
- '<span class="sql-reserved">WHERE</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;id' . '<br/>' .
- '<span class="sql-reserved">ORDER BY</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;id' . '<br/>' .
- '<span class="sql-reserved">DESC</span>' . '<br/>' .
+ '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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;id,<br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-variable">`tbl`</span><br/>' .
+ '<span class="sql-reserved">WHERE</span><br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;id<br/>' .
+ '<span class="sql-reserved">ORDER BY</span><br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;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(
+ ],
+ 'comments' => [
'query' => 'select /* Comment */ *' . "\n" .
'from tbl # Comment' . "\n" .
'where 1 -- Comment',
@@ -343,20 +345,20 @@ 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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-comment">/* Comment */</span> *' . '<br/>' .
- '<span class="sql-reserved">FROM</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;tbl <span class="sql-comment"># Comment</span>' . '<br/>' .
- '<span class="sql-reserved">WHERE</span>' . '<br/>' .
+ '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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-comment">/* Comment */</span> *<br/>' .
+ '<span class="sql-reserved">FROM</span><br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;tbl <span class="sql-comment"># Comment</span><br/>' .
+ '<span class="sql-reserved">WHERE</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span> <span class="sql-comment">-- Comment</span>',
- ),
- 'strip comments' => array(
+ ],
+ 'strip comments' => [
'query' => 'select /* Comment */ *' . "\n" .
'from tbl # Comment' . "\n" .
'where 1 -- Comment',
@@ -366,41 +368,41 @@ 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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;*' . '<br/>' .
- '<span class="sql-reserved">FROM</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;*<br/>' .
+ '<span class="sql-reserved">FROM</span><br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;tbl<br/>' .
+ '<span class="sql-reserved">WHERE</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>',
- 'options' => array(
+ 'options' => [
'remove_comments' => true,
- ),
- ),
- 'keywords' => array(
+ ],
+ ],
+ '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/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<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 +412,65 @@ 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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-reserved">FROM</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tbl' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-reserved">SELECT</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*;' . '<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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-reserved">FROM</span><br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tbl<br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-reserved">SELECT</span><br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*;<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/>' .
+ '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(
+ ],
+ '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/>' .
+ 'cli' => "\x1b[35mSELECT\n" .
+ " \x1b[91m\"Text\" \x1b[35mAS \x1b[39mbar\x1b[0m",
+ 'html' => '<span class="sql-reserved">SELECT</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-string">"Text"</span> <span class="sql-reserved">AS</span> bar',
- ),
- 'escape cli' => array(
+ ],
+ '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/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-string">\'&lt;s&gt;xss\'</span>' . '<br/>' .
- '<span class="sql-reserved">FROM</span>' . '<br/>' .
+ '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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-string">\'&lt;s&gt;xss\'</span><br/>' .
+ '<span class="sql-reserved">FROM</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-variable">`&lt;s&gt;xss`</span>,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt; s &gt; nxss <span class="sql-comment">/*s&lt;s&gt;xss*/</span>',
- ),
- 'create table' => array(
+ ],
+ '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 +485,29 @@ 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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-variable">`query`</span> <span class="sql-keyword">TEXT</span> <span class="sql-reserved">NOT NULL</span>,' . '<br/>' .
+ '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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-variable">`query`</span> <span class="sql-keyword">TEXT</span> <span class="sql-reserved">NOT NULL</span>,<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-reserved">PRIMARY KEY</span>(<span class="sql-variable">`id`</span>)',
- ),
- 'join' => array(
+ ],
+ '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 +515,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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;*' . '<br/>' .
- '<span class="sql-reserved">FROM</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;*<br/>' .
+ '<span class="sql-reserved">FROM</span><br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;tbl<br/>' .
+ '<span class="sql-reserved">WHERE</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;col = <span class="sql-parameter">:param</span>',
- ),
- 'anon param' => array(
+ ],
+ 'anon param' => [
'query' => 'select * from tbl where col = ?',
'text' => 'SELECT' . "\n" .
' *' . "\n" .
@@ -534,19 +536,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/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;*' . '<br/>' .
- '<span class="sql-reserved">FROM</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;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/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;*<br/>' .
+ '<span class="sql-reserved">FROM</span><br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;tbl<br/>' .
+ '<span class="sql-reserved">WHERE</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;col = <span class="sql-parameter">?</span>',
- )
- );
+ ],
+ ];
}
}
diff --git a/tests/Utils/MiscTest.php b/tests/Utils/MiscTest.php
index 3abc1cb..480d687 100644
--- a/tests/Utils/MiscTest.php
+++ b/tests/Utils/MiscTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Utils;
@@ -9,10 +10,10 @@ use PhpMyAdmin\SqlParser\Utils\Misc;
class MiscTest extends TestCase
{
/**
- * @dataProvider getAliasesProvider
- *
* @param mixed $query
* @param mixed $db
+ *
+ * @dataProvider getAliasesProvider
*/
public function testGetAliases($query, $db, array $expected)
{
@@ -24,104 +25,104 @@ class MiscTest extends TestCase
public function getAliasesProvider()
{
- 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(
+ 'columns' => [
'film_id' => 'id',
- ),
- ),
- ),
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
+ [
'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' => [],
+ ],
+ ],
+ ],
+ ],
+ ],
+ ];
}
}
diff --git a/tests/Utils/QueryTest.php b/tests/Utils/QueryTest.php
index 3bc1783..340f70f 100644
--- a/tests/Utils/QueryTest.php
+++ b/tests/Utils/QueryTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Utils;
@@ -9,10 +10,10 @@ use PhpMyAdmin\SqlParser\Utils\Query;
class QueryTest extends TestCase
{
/**
- * @dataProvider getFlagsProvider
- *
* @param mixed $query
* @param mixed $expected
+ *
+ * @dataProvider getFlagsProvider
*/
public function testGetFlags($query, $expected)
{
@@ -25,257 +26,257 @@ class QueryTest extends TestCase
public function getFlagsProvider()
{
- return array(
- array(
+ return [
+ [
'ALTER TABLE DROP col',
- array(
+ [
'reload' => true,
'querytype' => 'ALTER',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CALL test()',
- array(
+ [
'is_procedure' => true,
'querytype' => 'CALL',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CREATE TABLE tbl (id INT)',
- array(
+ [
'reload' => true,
'querytype' => 'CREATE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CHECK TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'CHECK',
- ),
- ),
- array(
+ ],
+ ],
+ [
'DELETE FROM tbl',
- array(
+ [
'is_affected' => true,
'is_delete' => true,
'querytype' => 'DELETE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'DROP VIEW v',
- array(
+ [
'reload' => true,
'querytype' => 'DROP',
- ),
- ),
- array(
+ ],
+ ],
+ [
'DROP DATABASE db',
- array(
+ [
'drop_database' => true,
'reload' => true,
'querytype' => 'DROP',
- ),
- ),
- array(
+ ],
+ ],
+ [
'EXPLAIN tbl',
- array(
+ [
'is_explain' => true,
'querytype' => 'EXPLAIN',
- ),
- ),
- array(
+ ],
+ ],
+ [
'LOAD DATA INFILE \'/tmp/test.txt\' INTO TABLE test',
- array(
+ [
'is_affected' => true,
'is_insert' => true,
'querytype' => 'LOAD',
- ),
- ),
- array(
+ ],
+ ],
+ [
'INSERT INTO tbl VALUES (1)',
- array(
+ [
'is_affected' => true,
'is_insert' => true,
'querytype' => 'INSERT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'REPLACE INTO tbl VALUES (2)',
- array(
+ [
'is_affected' => true,
'is_replace' => true,
'is_insert' => true,
'querytype' => 'REPLACE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT 1',
- array(
+ [
'is_select' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM tbl',
- array(
+ [
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT DISTINCT * FROM tbl LIMIT 0, 10 ORDER BY id',
- array(
+ [
'distinct' => true,
'is_select' => true,
'select_from' => true,
'limit' => true,
'order' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM actor GROUP BY actor_id',
- array(
+ [
'is_group' => true,
'is_select' => true,
'select_from' => true,
'group' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT col1, col2 FROM table1 PROCEDURE ANALYSE(10, 2000);',
- array(
+ [
'is_analyse' => true,
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM tbl INTO OUTFILE "/tmp/export.txt"',
- array(
+ [
'is_export' => true,
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT COUNT(id), SUM(id) FROM tbl',
- array(
+ [
'is_count' => true,
'is_func' => true,
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT (SELECT "foo")',
- array(
+ [
'is_select' => true,
'is_subquery' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM customer HAVING store_id = 2;',
- array(
+ [
'is_select' => true,
'select_from' => true,
'is_group' => true,
'having' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM table1 INNER JOIN table2 ON table1.id=table2.id;',
- array(
+ [
'is_select' => true,
'select_from' => true,
'join' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SHOW CREATE TABLE tbl',
- array(
+ [
'is_show' => true,
'querytype' => 'SHOW',
- ),
- ),
- array(
+ ],
+ ],
+ [
'UPDATE tbl SET id = 1',
- array(
+ [
'is_affected' => true,
'querytype' => 'UPDATE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'ANALYZE TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'ANALYZE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CHECKSUM TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'CHECKSUM',
- ),
- ),
- array(
+ ],
+ ],
+ [
'OPTIMIZE TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'OPTIMIZE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'REPAIR TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'REPAIR',
- ),
- ),
- array(
+ ],
+ ],
+ [
'(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10) ' .
'UNION ' .
'(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);',
- array(
+ [
'is_select' => true,
'select_from' => true,
'limit' => true,
'order' => true,
'union' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM orders AS ord WHERE 1',
- array(
+ [
'querytype' => 'SELECT',
'is_select' => true,
'select_from' => true,
- ),
- ),
- array(
+ ],
+ ],
+ [
'SET NAMES \'latin\'',
- array(
+ [
'querytype' => 'SET',
- ),
- )
- );
+ ],
+ ],
+ ];
}
public function testGetAll()
{
$this->assertEquals(
- array(
+ [
'distinct' => false,
'drop_database' => false,
'group' => false,
@@ -303,7 +304,7 @@ class QueryTest extends TestCase
'reload' => false,
'select_from' => false,
'union' => false,
- ),
+ ],
Query::getAll('')
);
@@ -313,21 +314,21 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array('*'),
- 'select_tables' => array(
- array(
+ 'select_expr' => ['*'],
+ 'select_tables' => [
+ [
'actor',
null,
- ),
- array(
+ ],
+ [
'film',
'sakila2',
- ),
- )
- )
+ ],
+ ],
+ ]
),
Query::getAll($query)
);
@@ -337,21 +338,21 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array('*'),
- 'select_tables' => array(
- array(
+ 'select_expr' => ['*'],
+ 'select_tables' => [
+ [
'actor',
'sakila',
- ),
- array(
+ ],
+ [
'film',
null,
- ),
- )
- )
+ ],
+ ],
+ ]
),
Query::getAll($query)
);
@@ -361,17 +362,17 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array(),
- 'select_tables' => array(
- array(
+ 'select_expr' => [],
+ 'select_tables' => [
+ [
'actor',
'sakila',
- ),
- ),
- )
+ ],
+ ],
+ ]
),
Query::getAll($query)
);
@@ -381,24 +382,24 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array(
+ 'select_expr' => [
'CASE WHEN 2 IS NULL THEN "this is true" ELSE "this is false" END',
- ),
- 'select_tables' => array(),
- )
+ ],
+ 'select_tables' => [],
+ ]
),
Query::getAll($query)
);
}
/**
- * @dataProvider getTablesProvider
- *
* @param mixed $query
* @param mixed $expected
+ *
+ * @dataProvider getTablesProvider
*/
public function testGetTables($query, $expected)
{
@@ -411,42 +412,42 @@ class QueryTest extends TestCase
public function getTablesProvider()
{
- return array(
- array(
+ return [
+ [
'INSERT INTO tbl(`id`, `name`) VALUES (1, "Name")',
- array('`tbl`')
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'UPDATE tbl SET id = 0',
- array('`tbl`')
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'DELETE FROM tbl WHERE id < 10',
- array('`tbl`')
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'TRUNCATE tbl',
- array('`tbl`')
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'DROP VIEW v',
- array()
- ),
- array(
+ [],
+ ],
+ [
'DROP TABLE tbl1, tbl2',
- array(
+ [
'`tbl1`',
'`tbl2`',
- ),
- ),
- array(
+ ],
+ ],
+ [
'RENAME TABLE a TO b, c TO d',
- array(
+ [
'`a`',
- '`c`'
- )
- )
- );
+ '`c`',
+ ],
+ ],
+ ];
}
public function testGetClause()
@@ -600,7 +601,7 @@ class QueryTest extends TestCase
public function testReplaceClauses()
{
- $this->assertEquals('', Query::replaceClauses(null, null, array()));
+ $this->assertEquals('', Query::replaceClauses(null, null, []));
$parser = new Parser('SELECT *, (SELECT 1) FROM film LIMIT 0, 10;');
$this->assertEquals(
@@ -608,12 +609,12 @@ class QueryTest extends TestCase
Query::replaceClauses(
$parser->statements[0],
$parser->list,
- array(
- array(
+ [
+ [
'WHERE',
'WHERE film_id > 0',
- )
- )
+ ],
+ ]
)
);
@@ -634,20 +635,20 @@ class QueryTest extends TestCase
Query::replaceClauses(
$parser->statements[0],
$parser->list,
- array(
- array(
+ [
+ [
'FROM',
'FROM city AS c',
- ),
- array(
+ ],
+ [
'WHERE',
'',
- ),
- array(
+ ],
+ [
'LIMIT',
'LIMIT 0, 10',
- )
- )
+ ],
+ ]
)
);
}
diff --git a/tests/Utils/RoutineTest.php b/tests/Utils/RoutineTest.php
index c988b91..90ba0b7 100644
--- a/tests/Utils/RoutineTest.php
+++ b/tests/Utils/RoutineTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Utils;
@@ -9,9 +10,9 @@ use PhpMyAdmin\SqlParser\Utils\Routine;
class RoutineTest extends TestCase
{
/**
- * @dataProvider getReturnTypeProvider
- *
* @param mixed $def
+ *
+ * @dataProvider getReturnTypeProvider
*/
public function testGetReturnType($def, array $expected)
{
@@ -20,94 +21,94 @@ class RoutineTest extends TestCase
public function getReturnTypeProvider()
{
- 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 mixed $def
+ *
+ * @dataProvider getParameterProvider
*/
public function testGetParameter($def, array $expected)
{
@@ -116,94 +117,94 @@ class RoutineTest extends TestCase
public function getParameterProvider()
{
- 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 mixed $query
+ *
+ * @dataProvider getParametersProvider
*/
public function testGetParameters($query, array $expected)
{
@@ -213,98 +214,98 @@ class RoutineTest extends TestCase
public function getParametersProvider()
{
- 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(
+ 'dir' => [
0 => '',
- ),
- 'name' => array(
+ ],
+ 'name' => [
0 => 'baz',
- ),
- 'type' => array(
+ ],
+ 'type' => [
0 => 'INT',
- ),
- 'length' => array(
+ ],
+ 'length' => [
0 => '',
- ),
- 'length_arr' => array(
- 0 => array(),
- ),
- 'opts' => array(
+ ],
+ 'length_arr' => [
+ 0 => [],
+ ],
+ 'opts' => [
0 => '',
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ [
'CREATE PROCEDURE `foo`(IN `baz\\)` INT(25) zerofill unsigned) BEGIN SELECT NULL; END',
- array(
+ [
'num' => 1,
- 'dir' => array(
+ 'dir' => [
0 => 'IN',
- ),
- 'name' => array(
+ ],
+ 'name' => [
0 => 'baz\\)',
- ),
- 'type' => array(
+ ],
+ 'type' => [
0 => 'INT',
- ),
- 'length' => array(
+ ],
+ 'length' => [
0 => '25',
- ),
- 'length_arr' => array(
- 0 => array('25'),
- ),
- 'opts' => array(
+ ],
+ 'length_arr' => [
+ 0 => ['25'],
+ ],
+ 'opts' => [
0 => 'UNSIGNED ZEROFILL',
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ [
'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) ' .
'BEGIN SELECT NULL; END',
- array(
+ [
'num' => 2,
- 'dir' => array(
+ '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',
- ),
- ),
- )
- );
+ ],
+ ],
+ ],
+ ];
}
}
diff --git a/tests/Utils/TableTest.php b/tests/Utils/TableTest.php
index ade4929..b71d951 100644
--- a/tests/Utils/TableTest.php
+++ b/tests/Utils/TableTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Utils;
@@ -9,9 +10,9 @@ use PhpMyAdmin\SqlParser\Utils\Table;
class TableTest extends TestCase
{
/**
- * @dataProvider getForeignKeysProvider
- *
* @param mixed $query
+ *
+ * @dataProvider getForeignKeysProvider
*/
public function testGetForeignKeys($query, array $expected)
{
@@ -21,12 +22,12 @@ class TableTest extends TestCase
public function getForeignKeysProvider()
{
- 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,
@@ -43,35 +44,35 @@ class TableTest extends TestCase
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 +81,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,24 +97,24 @@ 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 mixed $query
+ *
+ * @dataProvider getFieldsProvider
*/
public function testGetFields($query, array $expected)
{
@@ -123,12 +124,12 @@ class TableTest extends TestCase
public function getFieldsProvider()
{
- 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 +143,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))',
- ),
- ),
- )
- );
+ ],
+ ],
+ ],
+ ];
}
}
diff --git a/tests/Utils/TokensTest.php b/tests/Utils/TokensTest.php
index 685c670..b71a873 100644
--- a/tests/Utils/TokensTest.php
+++ b/tests/Utils/TokensTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Utils;
@@ -9,12 +10,12 @@ use PhpMyAdmin\SqlParser\Utils\Tokens;
class TokensTest extends TestCase
{
/**
- * @dataProvider replaceTokensProvider
- *
* @param mixed $list
* @param mixed $find
* @param mixed $replace
* @param mixed $expected
+ *
+ * @dataProvider replaceTokensProvider
*/
public function testReplaceTokens($list, $find, $replace, $expected)
{
@@ -23,28 +24,28 @@ class TokensTest extends TestCase
public function replaceTokensProvider()
{
- 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 mixed $token
* @param mixed $pattern
* @param mixed $expected
+ *
+ * @dataProvider matchProvider
*/
public function testMatch($token, $pattern, $expected)
{
@@ -53,64 +54,64 @@ class TokensTest extends TestCase
public function matchProvider()
{
- 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,
- )
- );
+ ],
+ ];
}
}