Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Tools/CustomJsonSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

use function in_array;

use const PHP_VERSION_ID;

/**
* Used for .out files generation
*/
Expand Down Expand Up @@ -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;
Expand Down
57 changes: 46 additions & 11 deletions tests/Misc/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion tests/Utils/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use PhpMyAdmin\SqlParser\Utils\Formatter;
use ReflectionMethod;

use const PHP_VERSION_ID;

class FormatterTest extends TestCase
{
/**
Expand Down Expand Up @@ -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));
}

Expand Down