From db41038d38086fcf2c914d6eaa087babbfb5f85b Mon Sep 17 00:00:00 2001 From: Liviu-Mihail Concioiu Date: Sun, 26 Jul 2026 19:16:11 +0200 Subject: [PATCH] Fix PHP 8.5 deprecations Signed-off-by: Liviu-Mihail Concioiu --- src/Tools/CustomJsonSerializer.php | 7 +++- tests/Misc/TranslatorTest.php | 57 ++++++++++++++++++++++++------ tests/Utils/FormatterTest.php | 7 +++- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/Tools/CustomJsonSerializer.php b/src/Tools/CustomJsonSerializer.php index 65ef9058e..a46d4916f 100644 --- a/src/Tools/CustomJsonSerializer.php +++ b/src/Tools/CustomJsonSerializer.php @@ -10,6 +10,8 @@ use function in_array; +use const PHP_VERSION_ID; + /** * Used for .out files generation */ @@ -64,7 +66,10 @@ protected function extractObjectData($value, $ref, $properties) try { $propRef = $ref->getProperty($property); - $propRef->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $propRef->setAccessible(true); + } + $data[$property] = $propRef->getValue($value); } catch (ReflectionException $e) { $data[$property] = $value->$property; diff --git a/tests/Misc/TranslatorTest.php b/tests/Misc/TranslatorTest.php index ff46d538e..f38b0e9ee 100644 --- a/tests/Misc/TranslatorTest.php +++ b/tests/Misc/TranslatorTest.php @@ -13,16 +13,24 @@ use function realpath; +use const PHP_VERSION_ID; + /** @covers \PhpMyAdmin\SqlParser\Translator */ final class TranslatorTest extends TestCase { public static function tearDownAfterClass(): void { $loaderProperty = new ReflectionProperty(Translator::class, 'loader'); - $loaderProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $loaderProperty->setAccessible(true); + } + $loaderProperty->setValue(null, null); $translatorProperty = new ReflectionProperty(Translator::class, 'translator'); - $translatorProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $translatorProperty->setAccessible(true); + } + $translatorProperty->setValue(null, null); Translator::setLocale('en'); } @@ -46,10 +54,16 @@ public function testLocale(): void public function testLoad(?string $globalLang, string $locale, string $expectedLocale): void { $loaderProperty = new ReflectionProperty(Translator::class, 'loader'); - $loaderProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $loaderProperty->setAccessible(true); + } + $loaderProperty->setValue(null, null); $translatorProperty = new ReflectionProperty(Translator::class, 'translator'); - $translatorProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $translatorProperty->setAccessible(true); + } + $translatorProperty->setValue(null, null); $GLOBALS['lang'] = $globalLang; Translator::setLocale($locale); @@ -62,16 +76,25 @@ public function testLoad(?string $globalLang, string $locale, string $expectedLo self::assertInstanceOf(Loader::class, $loader); $loaderClass = new ReflectionClass(Loader::class); $localeProperty = $loaderClass->getProperty('locale'); - $localeProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $localeProperty->setAccessible(true); + } + self::assertSame($expectedLocale, $localeProperty->getValue($loader)); // Compatibility with MoTranslator < 5 $defaultDomainProperty = $loaderClass->hasProperty('default_domain') ? $loaderClass->getProperty('default_domain') : $loaderClass->getProperty('defaultDomain'); - $defaultDomainProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $defaultDomainProperty->setAccessible(true); + } + self::assertSame('sqlparser', $defaultDomainProperty->getValue($loader)); $pathsProperty = $loaderClass->getProperty('paths'); - $pathsProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $pathsProperty->setAccessible(true); + } + self::assertSame( ['' => './', 'sqlparser' => realpath(__DIR__ . '/../../src/') . '/../locale/'], $pathsProperty->getValue($loader) @@ -81,10 +104,16 @@ public function testLoad(?string $globalLang, string $locale, string $expectedLo public function testGettext(): void { $loaderProperty = new ReflectionProperty(Translator::class, 'loader'); - $loaderProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $loaderProperty->setAccessible(true); + } + $loaderProperty->setValue(null, null); $translatorProperty = new ReflectionProperty(Translator::class, 'translator'); - $translatorProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $translatorProperty->setAccessible(true); + } + $translatorProperty->setValue(null, null); Translator::setLocale('pt_BR'); self::assertSame( @@ -93,10 +122,16 @@ public function testGettext(): void ); $loaderProperty = new ReflectionProperty(Translator::class, 'loader'); - $loaderProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $loaderProperty->setAccessible(true); + } + $loaderProperty->setValue(null, null); $translatorProperty = new ReflectionProperty(Translator::class, 'translator'); - $translatorProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $translatorProperty->setAccessible(true); + } + $translatorProperty->setValue(null, null); Translator::setLocale('en'); self::assertSame( diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php index 98c2ab4cf..68a9df0a8 100644 --- a/tests/Utils/FormatterTest.php +++ b/tests/Utils/FormatterTest.php @@ -8,6 +8,8 @@ use PhpMyAdmin\SqlParser\Utils\Formatter; use ReflectionMethod; +use const PHP_VERSION_ID; + class FormatterTest extends TestCase { /** @@ -54,7 +56,10 @@ public function testMergeFormats(array $default, array $overriding, array $expec ]; $reflectionMethod = new ReflectionMethod($formatter, 'getMergedOptions'); - $reflectionMethod->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $reflectionMethod->setAccessible(true); + } + $this->assertEquals($expectedOptions, $reflectionMethod->invoke($formatter, $overridingOptions)); }