From 3247f64bc20647d7174bc50ea708cbec01e83648 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 15 Jan 2024 20:21:34 +0100 Subject: [PATCH 1/2] Native property types in Context Signed-off-by: Kamil Tekiela --- src/Context.php | 20 ++++++-------------- src/Contexts/ContextMariaDb100000.php | 2 +- src/Contexts/ContextMariaDb100100.php | 2 +- src/Contexts/ContextMariaDb100200.php | 2 +- src/Contexts/ContextMariaDb100300.php | 2 +- src/Contexts/ContextMariaDb100400.php | 2 +- src/Contexts/ContextMariaDb100500.php | 2 +- src/Contexts/ContextMariaDb100600.php | 2 +- src/Contexts/ContextMariaDb100700.php | 2 +- src/Contexts/ContextMariaDb100800.php | 2 +- src/Contexts/ContextMariaDb100900.php | 2 +- src/Contexts/ContextMariaDb101000.php | 2 +- src/Contexts/ContextMariaDb101100.php | 2 +- src/Contexts/ContextMariaDb110000.php | 2 +- src/Contexts/ContextMariaDb110100.php | 2 +- src/Contexts/ContextMariaDb110200.php | 2 +- src/Contexts/ContextMySql50000.php | 2 +- src/Contexts/ContextMySql50100.php | 2 +- src/Contexts/ContextMySql50500.php | 2 +- src/Contexts/ContextMySql50600.php | 2 +- src/Contexts/ContextMySql50700.php | 2 +- src/Contexts/ContextMySql80000.php | 2 +- src/Contexts/ContextMySql80100.php | 2 +- src/Tools/ContextGenerator.php | 6 +++--- tests/Tools/templates/TestContext.php | 2 +- 25 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/Context.php b/src/Context.php index 7f5fee4f0..0212edaa8 100644 --- a/src/Context.php +++ b/src/Context.php @@ -45,25 +45,19 @@ abstract class Context /** * The name of the default content. - * - * @var string */ - public static $defaultContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700'; + public static string $defaultContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700'; /** * The name of the loaded context. - * - * @var string */ - public static $loadedContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700'; + public static string $loadedContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700'; /** * The prefix concatenated to the context name when an incomplete class name * is specified. - * - * @var string */ - public static $contextPrefix = '\\PhpMyAdmin\\SqlParser\\Contexts\\Context'; + public static string $contextPrefix = '\\PhpMyAdmin\\SqlParser\\Contexts\\Context'; /** * List of keywords. @@ -83,14 +77,14 @@ abstract class Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = []; + public static array $keywords = []; /** * List of operators and their flags. * * @var array */ - public static $operators = [ + public static array $operators = [ // Some operators (*, =) may have ambiguous flags, because they depend on // the context they are being used in. // For example: 1. SELECT * FROM table; # SQL specific (wildcard) @@ -144,10 +138,8 @@ abstract class Context * * @link https://dev.mysql.com/doc/refman/en/sql-mode.html * @link https://mariadb.com/kb/en/sql-mode/ - * - * @var int */ - public static $mode = self::SQL_MODE_NONE; + public static int $mode = self::SQL_MODE_NONE; public const SQL_MODE_NONE = 0; diff --git a/src/Contexts/ContextMariaDb100000.php b/src/Contexts/ContextMariaDb100000.php index b9893caec..a87700b46 100644 --- a/src/Contexts/ContextMariaDb100000.php +++ b/src/Contexts/ContextMariaDb100000.php @@ -30,7 +30,7 @@ class ContextMariaDb100000 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, diff --git a/src/Contexts/ContextMariaDb100100.php b/src/Contexts/ContextMariaDb100100.php index c3b593dec..ded6974d3 100644 --- a/src/Contexts/ContextMariaDb100100.php +++ b/src/Contexts/ContextMariaDb100100.php @@ -30,7 +30,7 @@ class ContextMariaDb100100 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb100200.php b/src/Contexts/ContextMariaDb100200.php index a97f3ae67..aabb25601 100644 --- a/src/Contexts/ContextMariaDb100200.php +++ b/src/Contexts/ContextMariaDb100200.php @@ -30,7 +30,7 @@ class ContextMariaDb100200 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb100300.php b/src/Contexts/ContextMariaDb100300.php index 8d6762a60..ae4095f12 100644 --- a/src/Contexts/ContextMariaDb100300.php +++ b/src/Contexts/ContextMariaDb100300.php @@ -30,7 +30,7 @@ class ContextMariaDb100300 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb100400.php b/src/Contexts/ContextMariaDb100400.php index 7d83076af..526101d2e 100644 --- a/src/Contexts/ContextMariaDb100400.php +++ b/src/Contexts/ContextMariaDb100400.php @@ -30,7 +30,7 @@ class ContextMariaDb100400 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb100500.php b/src/Contexts/ContextMariaDb100500.php index 7dd316ea5..87d2c590b 100644 --- a/src/Contexts/ContextMariaDb100500.php +++ b/src/Contexts/ContextMariaDb100500.php @@ -30,7 +30,7 @@ class ContextMariaDb100500 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb100600.php b/src/Contexts/ContextMariaDb100600.php index 3f0b18645..72c11f8fe 100644 --- a/src/Contexts/ContextMariaDb100600.php +++ b/src/Contexts/ContextMariaDb100600.php @@ -30,7 +30,7 @@ class ContextMariaDb100600 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb100700.php b/src/Contexts/ContextMariaDb100700.php index eea241c1d..5ed7bb88e 100644 --- a/src/Contexts/ContextMariaDb100700.php +++ b/src/Contexts/ContextMariaDb100700.php @@ -30,7 +30,7 @@ class ContextMariaDb100700 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb100800.php b/src/Contexts/ContextMariaDb100800.php index 7119dbb7d..98902e480 100644 --- a/src/Contexts/ContextMariaDb100800.php +++ b/src/Contexts/ContextMariaDb100800.php @@ -30,7 +30,7 @@ class ContextMariaDb100800 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb100900.php b/src/Contexts/ContextMariaDb100900.php index e6b5e01f0..3e58b41a0 100644 --- a/src/Contexts/ContextMariaDb100900.php +++ b/src/Contexts/ContextMariaDb100900.php @@ -30,7 +30,7 @@ class ContextMariaDb100900 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb101000.php b/src/Contexts/ContextMariaDb101000.php index 9188f9953..4626f39e7 100644 --- a/src/Contexts/ContextMariaDb101000.php +++ b/src/Contexts/ContextMariaDb101000.php @@ -30,7 +30,7 @@ class ContextMariaDb101000 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb101100.php b/src/Contexts/ContextMariaDb101100.php index 590325b61..c75db0e6d 100644 --- a/src/Contexts/ContextMariaDb101100.php +++ b/src/Contexts/ContextMariaDb101100.php @@ -30,7 +30,7 @@ class ContextMariaDb101100 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb110000.php b/src/Contexts/ContextMariaDb110000.php index 28086e195..7a6c38855 100644 --- a/src/Contexts/ContextMariaDb110000.php +++ b/src/Contexts/ContextMariaDb110000.php @@ -30,7 +30,7 @@ class ContextMariaDb110000 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb110100.php b/src/Contexts/ContextMariaDb110100.php index c26faf838..060f07157 100644 --- a/src/Contexts/ContextMariaDb110100.php +++ b/src/Contexts/ContextMariaDb110100.php @@ -30,7 +30,7 @@ class ContextMariaDb110100 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMariaDb110200.php b/src/Contexts/ContextMariaDb110200.php index af3cc366a..1fa9ba83a 100644 --- a/src/Contexts/ContextMariaDb110200.php +++ b/src/Contexts/ContextMariaDb110200.php @@ -30,7 +30,7 @@ class ContextMariaDb110200 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMySql50000.php b/src/Contexts/ContextMySql50000.php index e40ddd404..b004c7c55 100644 --- a/src/Contexts/ContextMySql50000.php +++ b/src/Contexts/ContextMySql50000.php @@ -30,7 +30,7 @@ class ContextMySql50000 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'BDB' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, diff --git a/src/Contexts/ContextMySql50100.php b/src/Contexts/ContextMySql50100.php index b8b25f457..5b30b4786 100644 --- a/src/Contexts/ContextMySql50100.php +++ b/src/Contexts/ContextMySql50100.php @@ -30,7 +30,7 @@ class ContextMySql50100 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'BDB' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, diff --git a/src/Contexts/ContextMySql50500.php b/src/Contexts/ContextMySql50500.php index 85c05ee03..9170b4594 100644 --- a/src/Contexts/ContextMySql50500.php +++ b/src/Contexts/ContextMySql50500.php @@ -30,7 +30,7 @@ class ContextMySql50500 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, diff --git a/src/Contexts/ContextMySql50600.php b/src/Contexts/ContextMySql50600.php index 1b4d8327e..5907b6be8 100644 --- a/src/Contexts/ContextMySql50600.php +++ b/src/Contexts/ContextMySql50600.php @@ -30,7 +30,7 @@ class ContextMySql50600 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, diff --git a/src/Contexts/ContextMySql50700.php b/src/Contexts/ContextMySql50700.php index 4bf1a9c90..798b83b4b 100644 --- a/src/Contexts/ContextMySql50700.php +++ b/src/Contexts/ContextMySql50700.php @@ -30,7 +30,7 @@ class ContextMySql50700 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMySql80000.php b/src/Contexts/ContextMySql80000.php index 2f6e5a90d..d28b10421 100644 --- a/src/Contexts/ContextMySql80000.php +++ b/src/Contexts/ContextMySql80000.php @@ -30,7 +30,7 @@ class ContextMySql80000 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Contexts/ContextMySql80100.php b/src/Contexts/ContextMySql80100.php index 66bea628a..e15a841ba 100644 --- a/src/Contexts/ContextMySql80100.php +++ b/src/Contexts/ContextMySql80100.php @@ -30,7 +30,7 @@ class ContextMySql80100 extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, diff --git a/src/Tools/ContextGenerator.php b/src/Tools/ContextGenerator.php index f3bbba53d..7e9d379d7 100644 --- a/src/Tools/ContextGenerator.php +++ b/src/Tools/ContextGenerator.php @@ -42,7 +42,7 @@ class ContextGenerator * * @var array */ - public static $labelsFlags = [ + public static array $labelsFlags = [ '(R)' => 2, // reserved '(D)' => 8, // data type '(K)' => 16, // keyword @@ -54,7 +54,7 @@ class ContextGenerator * * @var array */ - public static $links = [ + public static array $links = [ 'MySql50000' => 'https://dev.mysql.com/doc/refman/5.0/en/keywords.html', 'MySql50100' => 'https://dev.mysql.com/doc/refman/5.1/en/keywords.html', 'MySql50500' => 'https://dev.mysql.com/doc/refman/5.5/en/keywords.html', @@ -121,7 +121,7 @@ class %2$s extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ %4$s ]; } diff --git a/tests/Tools/templates/TestContext.php b/tests/Tools/templates/TestContext.php index bff268166..d92f8c830 100644 --- a/tests/Tools/templates/TestContext.php +++ b/tests/Tools/templates/TestContext.php @@ -30,7 +30,7 @@ class TestContext extends Context * @psalm-var non-empty-array * @phpstan-var non-empty-array */ - public static $keywords = [ + public static array $keywords = [ 'NO_FLAG' => 1, 'RESERVED' => 3, From a764d812d067dc8b58d108a2e20ec6a1e694d0f8 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 15 Jan 2024 20:46:40 +0100 Subject: [PATCH 2/2] Refactor Context::load() Signed-off-by: Kamil Tekiela --- psalm-baseline.xml | 5 ----- src/Context.php | 25 +++++++++++-------------- src/Tools/TestGenerator.php | 2 +- tests/Lexer/ContextTest.php | 13 ++++++------- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d769180a1..42101d185 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -546,11 +546,6 @@ ContextMySql50600 - - - ContextMySql50700 - - ContextMySql80000 diff --git a/src/Context.php b/src/Context.php index 0212edaa8..83d8c0025 100644 --- a/src/Context.php +++ b/src/Context.php @@ -4,6 +4,8 @@ namespace PhpMyAdmin\SqlParser; +use PhpMyAdmin\SqlParser\Contexts\ContextMySql50700; + use function class_exists; use function explode; use function in_array; @@ -43,21 +45,16 @@ abstract class Context */ public const OPERATOR_MAX_LENGTH = 4; - /** - * The name of the default content. - */ - public static string $defaultContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700'; - /** * The name of the loaded context. */ - public static string $loadedContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700'; + public static string $loadedContext = ContextMySql50700::class; /** * The prefix concatenated to the context name when an incomplete class name * is specified. */ - public static string $contextPrefix = '\\PhpMyAdmin\\SqlParser\\Contexts\\Context'; + public static string $contextPrefix = 'PhpMyAdmin\\SqlParser\\Contexts\\Context'; /** * List of keywords. @@ -521,19 +518,19 @@ public static function isSeparator(string $string): bool */ public static function load(string $context = ''): bool { - if (empty($context)) { - $context = self::$defaultContext; + if ($context === '') { + $context = ContextMySql50700::class; } - if ($context[0] !== '\\') { + if (! class_exists($context)) { + if (! class_exists(self::$contextPrefix . $context)) { + return false; + } + // Short context name (must be formatted into class name). $context = self::$contextPrefix . $context; } - if (! class_exists($context)) { - return false; - } - self::$loadedContext = $context; self::$keywords = $context::$keywords; diff --git a/src/Tools/TestGenerator.php b/src/Tools/TestGenerator.php index b6dc65c4e..33018b95f 100644 --- a/src/Tools/TestGenerator.php +++ b/src/Tools/TestGenerator.php @@ -169,7 +169,7 @@ public static function build( Context::load('MariaDb' . $mariaDbVersion); } else { // Load the default context to be sure there is no side effects - Context::load(''); + Context::load(); } $test = static::generate($query, $type); diff --git a/tests/Lexer/ContextTest.php b/tests/Lexer/ContextTest.php index ec20e6848..03318c44c 100644 --- a/tests/Lexer/ContextTest.php +++ b/tests/Lexer/ContextTest.php @@ -20,13 +20,12 @@ public static function tearDownAfterClass(): void public function testLoad(): void { // Default context is 5.7.0. - $this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$loadedContext); + $this->assertEquals('PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$loadedContext); $this->assertArrayHasKey('STORED', Context::$keywords); $this->assertArrayNotHasKey('AUTHORS', Context::$keywords); // Restoring context. - Context::load(''); - $this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$defaultContext); + Context::load(); $this->assertArrayHasKey('STORED', Context::$keywords); $this->assertArrayNotHasKey('AUTHORS', Context::$keywords); } @@ -39,12 +38,12 @@ public function testLoadClosest(string $context, string|null $expected): void { $this->assertEquals($expected, Context::loadClosest($context)); if ($expected !== null) { - $this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\Context' . $expected, Context::$loadedContext); + $this->assertEquals('PhpMyAdmin\\SqlParser\\Contexts\\Context' . $expected, Context::$loadedContext); $this->assertTrue(class_exists(Context::$loadedContext)); } // Restoring context. - Context::load(''); + Context::load(); } /** @@ -89,10 +88,10 @@ public static function contextLoadingProvider(): array public function testLoadAll(string $context): void { Context::load($context); - $this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\Context' . $context, Context::$loadedContext); + $this->assertEquals('PhpMyAdmin\\SqlParser\\Contexts\\Context' . $context, Context::$loadedContext); // Restoring context. - Context::load(''); + Context::load(); } /** @return string[][] */