Skip to content

Commit

Permalink
Replace $GLOBALS['cfg']['ZeroConf'] in Common class
Browse files Browse the repository at this point in the history
Replaces it with PhpMyAdmin\Config\Settings::$zeroConf access.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Mar 2, 2023
1 parent 5c5e8c2 commit 687c51d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/setup.rst
Expand Up @@ -824,7 +824,7 @@ Zero configuration

In many cases, this database structure can be automatically created and
configured. This is called “Zero Configuration” mode and can be particularly
useful in shared hosting situations. “Zeroconf” mode is on by default, to
useful in shared hosting situations. “ZeroConf” mode is on by default, to
disable set :config:option:`$cfg['ZeroConf']` to false.

The following three scenarios are covered by the Zero Configuration mode:
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Common.php
Expand Up @@ -306,7 +306,7 @@ public static function run(bool $isSetupPage = false): void
/* Tell tracker that it can actually work */
Tracker::enable();

if (! empty($GLOBALS['server']) && isset($GLOBALS['cfg']['ZeroConf']) && $GLOBALS['cfg']['ZeroConf']) {
if (! empty($GLOBALS['server']) && $settings->zeroConf) {
/** @var Relation $relation */
$relation = $container->get('relation');
$GLOBALS['dbi']->postConnectControl($relation);
Expand Down
6 changes: 3 additions & 3 deletions libraries/classes/Config/Settings.php
Expand Up @@ -2284,7 +2284,7 @@ final class Settings
*
* @link https://docs.phpmyadmin.net/en/latest/config.html#cfg_ZeroConf
*/
public bool $ZeroConf;
public bool $zeroConf;

/**
* Developers ONLY!
Expand Down Expand Up @@ -2590,7 +2590,7 @@ public function __construct(array $settings)
$this->DisableMultiTableMaintenance = $this->setDisableMultiTableMaintenance($settings);
$this->SendErrorReports = $this->setSendErrorReports($settings);
$this->ConsoleEnterExecutes = $this->setConsoleEnterExecutes($settings);
$this->ZeroConf = $this->setZeroConf($settings);
$this->zeroConf = $this->setZeroConf($settings);
$this->DBG = $this->setDBG($settings);
$this->environment = $this->setEnvironment($settings);
$this->DefaultFunctions = $this->setDefaultFunctions($settings);
Expand Down Expand Up @@ -2787,7 +2787,7 @@ public function asArray(): array
'DisableMultiTableMaintenance' => $this->DisableMultiTableMaintenance,
'SendErrorReports' => $this->SendErrorReports,
'ConsoleEnterExecutes' => $this->ConsoleEnterExecutes,
'ZeroConf' => $this->ZeroConf,
'ZeroConf' => $this->zeroConf,
'DBG' => $this->DBG->asArray(),
'environment' => $this->environment,
'DefaultFunctions' => $this->DefaultFunctions,
Expand Down
23 changes: 19 additions & 4 deletions test/classes/Config/SettingsTest.php
Expand Up @@ -253,7 +253,6 @@ class SettingsTest extends TestCase
'DisableMultiTableMaintenance' => false,
'SendErrorReports' => 'ask',
'ConsoleEnterExecutes' => false,
'ZeroConf' => true,
'DBG' => null,
'environment' => 'production',
'DefaultFunctions' => [
Expand Down Expand Up @@ -546,7 +545,6 @@ public static function providerForTestConstructor(): array
['DisableMultiTableMaintenance', null, false],
['SendErrorReports', null, 'ask'],
['ConsoleEnterExecutes', null, false],
['ZeroConf', null, true],
['DBG', null, null],
['environment', null, 'production'],
['DefaultFunctions', null, ['FUNC_CHAR' => '', 'FUNC_DATE' => '', 'FUNC_NUMBER' => '', 'FUNC_SPATIAL' => 'GeomFromText', 'FUNC_UUID' => 'UUID', 'first_timestamp' => 'NOW']],
Expand Down Expand Up @@ -740,7 +738,6 @@ public static function providerForTestConstructor(): array
['DisableMultiTableMaintenance', true, true],
['SendErrorReports', 'never', 'never'],
['ConsoleEnterExecutes', true, true],
['ZeroConf', false, false],
['DBG', [], null],
['environment', 'development', 'development'],
['DefaultFunctions', ['key' => 'value', 'key2' => 'value2'], ['key' => 'value', 'key2' => 'value2']],
Expand Down Expand Up @@ -1030,7 +1027,6 @@ public static function providerForTestConstructor(): array
['CSPAllow', 1234, '1234'],
['DisableMultiTableMaintenance', 1, true],
['ConsoleEnterExecutes', 1, true],
['ZeroConf', 0, false],
['DefaultFunctions', ['test' => 1234], ['test' => '1234']],
['maxRowPlotLimit', '1', 1],
['ShowGitRevision', 0, false],
Expand Down Expand Up @@ -1134,6 +1130,25 @@ public static function providerForTestConstructor(): array
];
}

/** @dataProvider booleanWithDefaultTrueProvider */
public function testZeroConf(mixed $actual, bool $expected): void
{
$settings = new Settings(['ZeroConf' => $actual]);
$settingsArray = $settings->asArray();
$this->assertSame($expected, $settings->zeroConf);
$this->assertArrayHasKey('ZeroConf', $settingsArray);
$this->assertSame($expected, $settingsArray['ZeroConf']);
}

/** @return iterable<string, array{mixed, bool}> */
public static function booleanWithDefaultTrueProvider(): iterable
{
yield 'null value' => [null, true];
yield 'valid value' => [true, true];
yield 'valid value 2' => [false, false];
yield 'valid value with type coercion' => [0, false];
}

/**
* @param array{internal: int, human: string} $expected
*
Expand Down

0 comments on commit 687c51d

Please sign in to comment.