Skip to content

Commit

Permalink
Rename Config\Settings::$DBG to $debug
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Mar 17, 2024
1 parent c9c286b commit 63ae297
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 49 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15475,11 +15475,6 @@ parameters:
count: 1
path: tests/unit/Config/SettingsTest.php

-
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpMyAdmin\\\\\\\\Config\\\\\\\\Settings\\\\\\\\Debug' and PhpMyAdmin\\\\Config\\\\Settings\\\\Debug will always evaluate to true\\.$#"
count: 1
path: tests/unit/Config/SettingsTest.php

-
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpMyAdmin\\\\\\\\Config\\\\\\\\Settings\\\\\\\\Export' and PhpMyAdmin\\\\Config\\\\Settings\\\\Export will always evaluate to true\\.$#"
count: 1
Expand Down
21 changes: 11 additions & 10 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12245,6 +12245,7 @@
<code><![CDATA[valuesForAllowThirdPartyFramingProvider]]></code>
<code><![CDATA[valuesForAuthLogProvider]]></code>
<code><![CDATA[valuesForBlowfishSecretProvider]]></code>
<code><![CDATA[valuesForDebugProvider]]></code>
<code><![CDATA[valuesForExecTimeLimitProvider]]></code>
<code><![CDATA[valuesForLimitCharsProvider]]></code>
<code><![CDATA[valuesForMaxCharactersInDisplayedSQLProvider]]></code>
Expand Down Expand Up @@ -13232,8 +13233,8 @@
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<InaccessibleProperty>
<code><![CDATA[$config->config->DBG->sql]]></code>
<code><![CDATA[$config->config->DBG->sql]]></code>
<code><![CDATA[$config->config->debug->sql]]></code>
<code><![CDATA[$config->config->debug->sql]]></code>
</InaccessibleProperty>
<PossiblyUnusedMethod>
<code><![CDATA[currentRolesData]]></code>
Expand Down Expand Up @@ -13445,8 +13446,8 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InaccessibleProperty>
<code><![CDATA[$config->config->DBG->sql]]></code>
<code><![CDATA[$config->config->DBG->sql]]></code>
<code><![CDATA[$config->config->debug->sql]]></code>
<code><![CDATA[$config->config->debug->sql]]></code>
</InaccessibleProperty>
<MixedArrayAssignment>
<code><![CDATA[$_SESSION['debug']['queries']]]></code>
Expand Down Expand Up @@ -14739,12 +14740,12 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InaccessibleProperty>
<code><![CDATA[$config->config->DBG->simple2fa]]></code>
<code><![CDATA[$config->config->DBG->simple2fa]]></code>
<code><![CDATA[$config->config->DBG->simple2fa]]></code>
<code><![CDATA[$config->config->DBG->simple2fa]]></code>
<code><![CDATA[$config->config->DBG->simple2fa]]></code>
<code><![CDATA[$config->config->DBG->simple2fa]]></code>
<code><![CDATA[$config->config->debug->simple2fa]]></code>
<code><![CDATA[$config->config->debug->simple2fa]]></code>
<code><![CDATA[$config->config->debug->simple2fa]]></code>
<code><![CDATA[$config->config->debug->simple2fa]]></code>
<code><![CDATA[$config->config->debug->simple2fa]]></code>
<code><![CDATA[$config->config->debug->simple2fa]]></code>
</InaccessibleProperty>
<MixedArgument>
<code><![CDATA[$object->config['settings']['secret']]]></code>
Expand Down
8 changes: 4 additions & 4 deletions src/Config/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,7 @@ final class Settings
*
* @link https://docs.phpmyadmin.net/en/latest/config.html#cfg_DBG
*/
public Debug $DBG;
public Debug $debug;

/**
* Sets the working environment
Expand Down Expand Up @@ -2808,7 +2808,7 @@ public function __construct(array $settings)
$this->SendErrorReports = $this->setSendErrorReports($settings);
$this->ConsoleEnterExecutes = $this->setConsoleEnterExecutes($settings);
$this->zeroConf = $this->setZeroConf($settings);
$this->DBG = $this->setDBG($settings);
$this->debug = $this->setDebug($settings);
$this->environment = $this->setEnvironment($settings);
$this->DefaultFunctions = $this->setDefaultFunctions($settings);
$this->maxRowPlotLimit = $this->setMaxRowPlotLimit($settings);
Expand Down Expand Up @@ -3006,7 +3006,7 @@ public function asArray(): array
'SendErrorReports' => $this->SendErrorReports,
'ConsoleEnterExecutes' => $this->ConsoleEnterExecutes,
'ZeroConf' => $this->zeroConf,
'DBG' => $this->DBG->asArray(),
'DBG' => $this->debug->asArray(),
'environment' => $this->environment,
'DefaultFunctions' => $this->DefaultFunctions,
'maxRowPlotLimit' => $this->maxRowPlotLimit,
Expand Down Expand Up @@ -5389,7 +5389,7 @@ private function setZeroConf(array $settings): bool
}

/** @param array<int|string, mixed> $settings */
private function setDBG(array $settings): Debug
private function setDebug(array $settings): Debug
{
if (isset($settings['DBG']) && is_array($settings['DBG'])) {
return new Debug($settings['DBG']);
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static function testDBConnection(
string $errorKey = 'Server',
): bool|array {
$config = Config::getInstance();
if ($config->config->DBG->demo) {
if ($config->config->debug->demo) {
// Connection test disabled on the demo server!
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getDisplay(): string
'has_bookmark_feature' => $bookmarkFeature !== null,
'sql_history' => $sqlHistory,
'bookmark_content' => $bookmarkContent,
'debug' => $this->config->config->DBG->sql,
'debug' => $this->config->config->debug->sql,
]);
}
}
2 changes: 1 addition & 1 deletion src/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function __invoke(ServerRequest $request): Response|null
'server' => Current::$server,
'sync_favorite_tables' => $syncFavoriteTables,
'has_server' => $hasServer,
'is_demo' => $config->config->DBG->demo,
'is_demo' => $config->config->debug->demo,
'has_server_selection' => $hasServerSelection ?? false,
'server_selection' => $serverSelection ?? '',
'has_change_password_link' => ($config->selectedServer['auth_type'] ?? '') !== 'config'
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/Setup/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
public function __invoke(ServerRequest $request): Response
{
$config = Config::getInstance();
if (@file_exists(CONFIG_FILE) && ! $config->config->DBG->demo) {
if (@file_exists(CONFIG_FILE) && ! $config->config->debug->demo) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND);

return $response->write($this->template->render('error/generic', [
Expand Down
4 changes: 2 additions & 2 deletions src/DatabaseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ public function tryQuery(
$GLOBALS['cached_affected_rows'] = $this->affectedRows($connectionType, false);
}

if ($this->config->config->DBG->sql) {
if ($this->config->config->debug->sql) {
$errorMessage = $this->getError($connectionType);
Utilities::debugLogQueryIntoSession(
$query,
$errorMessage !== '' ? $errorMessage : null,
$result,
$this->lastQueryExecutionTime,
);
if ($this->config->config->DBG->sqllog) {
if ($this->config->config->debug->sqllog) {
openlog('phpMyAdmin', LOG_NDELAY | LOG_PID, LOG_USER);

syslog(
Expand Down
6 changes: 3 additions & 3 deletions src/Footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static function removeRecursion(mixed &$object, array $stack = []): mixe
public function getDebugMessage(): string
{
$retval = '\'false\'';
if ($this->config->config->DBG->sql && empty($_REQUEST['no_debug']) && ! empty($_SESSION['debug'])) {
if ($this->config->config->debug->sql && empty($_REQUEST['no_debug']) && ! empty($_SESSION['debug'])) {
// Remove recursions and iterators from $_SESSION['debug']
self::removeRecursion($_SESSION['debug']);

Expand Down Expand Up @@ -239,7 +239,7 @@ public function getDisplay(): string
$errorMessages = $this->getErrorMessages();
$scripts = $this->scripts->getDisplay();

if ($this->config->config->DBG->demo) {
if ($this->config->config->debug->demo) {
$gitRevisionInfo = $this->getGitRevisionInfo();
}

Expand All @@ -252,7 +252,7 @@ public function getDisplay(): string
'self_url' => $url ?? null,
'error_messages' => $errorMessages ?? '',
'scripts' => $scripts ?? '',
'is_demo' => $this->config->config->DBG->demo,
'is_demo' => $this->config->config->debug->demo,
'git_revision_info' => $gitRevisionInfo ?? [],
'footer' => $footer ?? '',
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/Auth/AuthenticationCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function showLoginForm(): never

$response->addHTML($this->template->render('login/form', [
'login_header' => $loginHeader,
'is_demo' => $config->config->DBG->demo,
'is_demo' => $config->config->debug->demo,
'error_messages' => $errorMessages,
'available_languages' => $availableLanguages,
'is_session_expired' => $sessionExpired,
Expand Down
2 changes: 1 addition & 1 deletion src/TwoFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getAvailableBackends(): array
{
$result = [];
$config = Config::getInstance();
if ($config->config->DBG->simple2fa) {
if ($config->config->debug->simple2fa) {
$result[] = 'simple';
}

Expand Down
29 changes: 20 additions & 9 deletions tests/unit/Config/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ class SettingsTest extends TestCase
'DisableMultiTableMaintenance' => false,
'SendErrorReports' => 'ask',
'ConsoleEnterExecutes' => false,
'DBG' => null,
'environment' => 'production',
'DefaultFunctions' => [
'FUNC_CHAR' => '',
Expand Down Expand Up @@ -268,11 +267,6 @@ public function testConstructor(array $values): void
continue;
}

if ($key === 'DBG') {
self::assertInstanceOf(Debug::class, $settings->DBG);
continue;
}

if ($key === 'Export') {
self::assertInstanceOf(Export::class, $settings->Export);
continue;
Expand Down Expand Up @@ -468,7 +462,6 @@ public static function providerForTestConstructor(): array
['DisableMultiTableMaintenance', null, false],
['SendErrorReports', null, 'ask'],
['ConsoleEnterExecutes', null, false],
['DBG', null, null],
['environment', null, 'production'],
['DefaultFunctions', null, ['FUNC_CHAR' => '', 'FUNC_DATE' => '', 'FUNC_NUMBER' => '', 'FUNC_SPATIAL' => 'GeomFromText', 'FUNC_UUID' => 'UUID', 'first_timestamp' => 'NOW']],
['maxRowPlotLimit', null, 500],
Expand Down Expand Up @@ -634,7 +627,6 @@ public static function providerForTestConstructor(): array
['DisableMultiTableMaintenance', true, true],
['SendErrorReports', 'never', 'never'],
['ConsoleEnterExecutes', true, true],
['DBG', [], null],
['environment', 'development', 'development'],
['DefaultFunctions', ['key' => 'value', 'key2' => 'value2'], ['key' => 'value', 'key2' => 'value2']],
['maxRowPlotLimit', 1, 1],
Expand Down Expand Up @@ -963,7 +955,6 @@ public static function providerForTestConstructor(): array
['TrustedProxies', 'invalid', []],
['LinkLengthLimit', 0, 1000],
['SendErrorReports', 'invalid', 'ask'],
['DBG', 'invalid', null],
['environment', 'invalid', 'production'],
['DefaultFunctions', 'invalid', ['FUNC_CHAR' => '', 'FUNC_DATE' => '', 'FUNC_NUMBER' => '', 'FUNC_SPATIAL' => 'GeomFromText', 'FUNC_UUID' => 'UUID', 'first_timestamp' => 'NOW']],
['maxRowPlotLimit', 0, 500],
Expand Down Expand Up @@ -1453,6 +1444,26 @@ public static function booleanWithDefaultTrueProvider(): iterable
yield 'valid value with type coercion' => [0, false];
}

/** @param mixed[] $expected */
#[DataProvider('valuesForDebugProvider')]
public function testDebug(mixed $actual, array $expected): void
{
$settings = new Settings(['DBG' => $actual]);
$settingsArray = $settings->asArray();
$expectedDebug = new Debug($expected);
self::assertEquals($expectedDebug, $settings->debug);
self::assertSame($expectedDebug->asArray(), $settingsArray['DBG']);
}

/** @return iterable<string, array{mixed, mixed[]}> */
public static function valuesForDebugProvider(): iterable
{
yield 'null value' => [null, []];
yield 'valid value' => [[], []];
yield 'valid value 2' => [['demo' => true], ['demo' => true]];
yield 'invalid value' => ['invalid', []];
}

/** @param array{internal: int, human: string} $expected */
#[DataProvider('valuesForMysqlMinVersionProvider')]
public function testMysqlMinVersion(mixed $actual, array $expected): void
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/DatabaseInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ public function testGetServerCollation(): void
{
$dbi = $this->createDatabaseInterface();
$config = Config::getInstance();
$config->config->DBG->sql = true;
$config->config->debug->sql = true;
self::assertSame('utf8_general_ci', $dbi->getServerCollation());
$config->config->DBG->sql = false;
$config->config->debug->sql = false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/FooterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function tearDown(): void
public function testGetDebugMessage(): void
{
$config = Config::getInstance();
$config->config->DBG->sql = true;
$config->config->debug->sql = true;
$_SESSION['debug']['queries'] = [
['count' => 1, 'time' => 0.2, 'query' => 'SELECT * FROM `pma_bookmark` WHERE 1'],
['count' => 1, 'time' => 2.5, 'query' => 'SELECT * FROM `db` WHERE 1'],
Expand All @@ -80,7 +80,7 @@ public function testGetDebugMessage(): void
. '{"count":1,"time":2.5,"query":"SELECT * FROM `db` WHERE 1"}]}',
$this->object->getDebugMessage(),
);
$config->config->DBG->sql = false;
$config->config->debug->sql = false;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/TwoFactorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ public function testSimple(): void
{
$request = new ServerRequest(self::createStub(ServerRequestInterface::class));
$config = Config::getInstance();
$config->config->DBG->simple2fa = true;
$config->config->debug->simple2fa = true;
$object = $this->getTwoFactorAndLoadConfig('user', ['type' => 'db', 'backend' => 'simple']);
$backend = $object->getBackend();
self::assertSame('simple', $backend::$id);
$config->config->DBG->simple2fa = false;
$config->config->debug->simple2fa = false;

unset($_POST['2fa_confirm']);
self::assertFalse($object->check($request, true));
Expand All @@ -203,7 +203,7 @@ public function testConfigureSimple(): void
{
$request = new ServerRequest(self::createStub(ServerRequestInterface::class));
$config = Config::getInstance();
$config->config->DBG->simple2fa = true;
$config->config->debug->simple2fa = true;
$object = $this->getTwoFactorAndLoadConfig('user', null);

$this->dummyDbi->assertAllQueriesConsumed();
Expand All @@ -228,7 +228,7 @@ public function testConfigureSimple(): void

$this->initStorageConfigAndData();// Needs a re-init

$config->config->DBG->simple2fa = false;
$config->config->debug->simple2fa = false;
$object = $this->getTwoFactorAndLoadConfig('user', null);
self::assertFalse($object->configure($request, 'simple'));
$this->dummyDbi->assertAllQueriesConsumed();
Expand Down Expand Up @@ -483,13 +483,13 @@ public function testKeyAuthentication(): void
public function testBackends(): void
{
$config = Config::getInstance();
$config->config->DBG->simple2fa = true;
$config->config->debug->simple2fa = true;
$object = $this->getTwoFactorAndLoadConfig('user', null);
$backends = $object->getAllBackends();
self::assertCount(
count($object->getAvailable()) + 1,
$backends,
);
$config->config->DBG->simple2fa = false;
$config->config->debug->simple2fa = false;
}
}

0 comments on commit 63ae297

Please sign in to comment.