diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 391a0798c1..3bd855e4fd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -313,13 +313,7 @@ parameters: path: src/Config.php - - message: '#^Property PhpMyAdmin\\Config\:\:\$settings \(array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\}\) does not accept array\.$#' - identifier: assign.propertyType - count: 1 - path: src/Config.php - - - - message: '#^Property PhpMyAdmin\\Config\:\:\$settings \(array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\}\) does not accept non\-empty\-array\\.$#' + message: '#^Property PhpMyAdmin\\Config\:\:\$settings \(array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\}\) does not accept array\\.$#' identifier: assign.propertyType count: 1 path: src/Config.php @@ -951,12 +945,6 @@ parameters: count: 5 path: src/Config/UserPreferencesHandler.php - - - message: '#^Cannot access offset ''userprefs_mtime'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: src/Config/UserPreferencesHandler.php - - message: '#^Cannot access offset ''userprefs_type'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -1011,12 +999,6 @@ parameters: count: 1 path: src/Config/UserPreferencesHandler.php - - - message: '#^Property PhpMyAdmin\\Config\:\:\$settings \(array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\}\) does not accept array\\.$#' - identifier: assign.propertyType - count: 1 - path: src/Config/UserPreferencesHandler.php - - message: '#^Property PhpMyAdmin\\Config\\UserPreferencesHandler\:\:\$storageType \(''''\|''db''\|''session''\) does not accept mixed\.$#' identifier: assign.propertyType @@ -13809,15 +13791,6 @@ parameters: count: 1 path: tests/test_data/config.inc.php - - - message: ''' - #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: - Use dependency injection instead\.$# - ''' - identifier: staticMethod.deprecated - count: 1 - path: tests/unit/AbstractTestCase.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\: @@ -14301,15 +14274,6 @@ parameters: count: 5 path: tests/unit/ConfigStorage/RelationTest.php - - - message: ''' - #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: - Use dependency injection instead\.$# - ''' - identifier: staticMethod.deprecated - count: 1 - path: tests/unit/ConfigTest.php - - message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) with ''Server'' and array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\} will always evaluate to false\.$#' identifier: staticMethod.impossibleType @@ -16851,12 +16815,6 @@ parameters: count: 1 path: tests/unit/TwoFactorTest.php - - - message: '#^Missing call to parent\:\:tearDown\(\) method\.$#' - identifier: phpunit.callParent - count: 1 - path: tests/unit/TwoFactorTest.php - - message: '#^Parameter \#1 \$secret of method PragmaRX\\Google2FA\\Google2FA\:\:oathTotp\(\) expects string, mixed given\.$#' identifier: argument.type @@ -16921,7 +16879,7 @@ parameters: path: tests/unit/UtilTest.php - - message: '#^Cannot access offset ''server_2'' on mixed\.$#' + message: '#^Cannot access offset ''server_2_'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible count: 4 path: tests/unit/UtilTest.php @@ -16932,12 +16890,6 @@ parameters: count: 2 path: tests/unit/UtilTest.php - - - message: '#^Property PhpMyAdmin\\Config\:\:\$selectedServer \(array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\) does not accept array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\.$#' - identifier: assign.propertyType - count: 1 - path: tests/unit/UtilTest.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: @@ -16999,7 +16951,7 @@ parameters: path: tests/unit/Utils/SessionCacheTest.php - - message: '#^Cannot access offset ''server_2'' on mixed\.$#' + message: '#^Cannot access offset ''server_2_'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible count: 4 path: tests/unit/Utils/SessionCacheTest.php @@ -17028,12 +16980,6 @@ parameters: count: 2 path: tests/unit/Utils/SessionCacheTest.php - - - message: '#^Property PhpMyAdmin\\Config\:\:\$selectedServer \(array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\) does not accept array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\.$#' - identifier: assign.propertyType - count: 5 - path: tests/unit/Utils/SessionCacheTest.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7ab11575f7..e3a8bac908 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -118,15 +118,15 @@ settings]]> settings]]> + + + - settings, $this->config->asArray())]]> + settings]]> getCookieName($cookieName)]]]> - - settings]]> - @@ -420,7 +420,6 @@ - @@ -428,10 +427,8 @@ - - @@ -442,7 +439,6 @@ - config->settings]]> config->settings, $configData)]]> @@ -8792,9 +8788,6 @@ - - - @@ -9151,9 +9144,6 @@ - - - settings['Server']]]> settings['Server']]]> @@ -10836,20 +10826,17 @@ - - selectedServer]]> - - - + + - - - - - - + + + + + + @@ -10922,24 +10909,17 @@ - - selectedServer]]> - selectedServer]]> - selectedServer]]> - selectedServer]]> - selectedServer]]> - - - + + - - - - - - + + + + + + diff --git a/src/Config.php b/src/Config.php index 1f7edac2c3..6a9a3185b9 100644 --- a/src/Config.php +++ b/src/Config.php @@ -13,7 +13,7 @@ use Throwable; use function __; use function array_key_last; -use function array_replace_recursive; +use function array_shift; use function array_slice; use function count; use function defined; @@ -68,9 +68,6 @@ class Config { public static self|null $instance = null; - /** @var mixed[] default configuration settings */ - public array $default; - /** @var mixed[] configuration settings, without user preferences applied */ public array $baseSettings; @@ -102,7 +99,6 @@ class Config { $this->config = new Settings([]); $config = $this->config->asArray(); - $this->default = $config; $this->settings = $config; $this->baseSettings = $config; $this->selectedServer = (new Server())->asArray(); @@ -208,7 +204,7 @@ class Config } $this->config = new Settings($cfg); - $this->settings = array_replace_recursive($this->settings, $this->config->asArray()); + $this->settings = $this->config->asArray(); } /** @@ -288,15 +284,44 @@ class Config * * @param string $setting configuration option * @param mixed $value new value for configuration option + * + * @throws ConfigException */ public function set(string $setting, mixed $value): void { - if (isset($this->settings[$setting]) && $this->settings[$setting] === $value) { + $parts = explode('/', $setting); + if (! $this->setValueRecursive($this->settings, $parts, $value)) { return; } - $this->settings[$setting] = $value; $this->config = new Settings($this->settings); + $this->settings = $this->config->asArray(); + } + + /** + * @param mixed[] $array + * @param array-key[] $parts + * + * @throws ConfigException + */ + private function setValueRecursive(array &$array, array $parts, mixed $value): bool + { + $part = array_shift($parts); + if ($parts === []) { + if ($array[$part] === $value) { + return false; + } + + $array[$part] = $value; + + return true; + } + + if (! is_array($array[$part])) { + throw new ConfigException('Failed to set configuration value.'); + } + + return $this->setValueRecursive($array[$part], $parts, $value); } /** diff --git a/src/Config/Settings.php b/src/Config/Settings.php index 43410c0417..4cdabfc95c 100644 --- a/src/Config/Settings.php +++ b/src/Config/Settings.php @@ -3920,10 +3920,10 @@ final class Settings } return match ($settings['NavigationTreeDefaultTabTable']) { - 'sql', 'tbl_sql.php' => '/table/sql', - 'search', 'tbl_select.php' => '/table/search', - 'insert', 'tbl_change.php' => '/table/change', - 'browse', 'sql.php' => '/sql', + 'sql', 'tbl_sql.php', '/table/sql' => '/table/sql', + 'search', 'tbl_select.php', '/table/search' => '/table/search', + 'insert', 'tbl_change.php', '/table/change' => '/table/change', + 'browse', 'sql.php', '/sql' => '/sql', default => '/table/structure', }; } @@ -3940,11 +3940,11 @@ final class Settings } return match ($settings['NavigationTreeDefaultTabTable2']) { - 'structure', 'tbl_structure.php' => '/table/structure', - 'sql', 'tbl_sql.php' => '/table/sql', - 'search', 'tbl_select.php' => '/table/search', - 'insert', 'tbl_change.php' => '/table/change', - 'browse', 'sql.php' => '/sql', + 'structure', 'tbl_structure.php', '/table/structure' => '/table/structure', + 'sql', 'tbl_sql.php', '/table/sql' => '/table/sql', + 'search', 'tbl_select.php', '/table/search' => '/table/search', + 'insert', 'tbl_change.php', '/table/change' => '/table/change', + 'browse', 'sql.php', '/sql' => '/sql', default => '', }; } @@ -4520,10 +4520,10 @@ final class Settings } return match ($settings['DefaultTabServer']) { - 'databases', 'server_databases.php' => '/server/databases', - 'status', 'server_status.php' => '/server/status', - 'variables', 'server_variables.php' => '/server/variables', - 'privileges', 'server_privileges.php' => '/server/privileges', + 'databases', 'server_databases.php', '/server/databases' => '/server/databases', + 'status', 'server_status.php', '/server/status' => '/server/status', + 'variables', 'server_variables.php', '/server/variables' => '/server/variables', + 'privileges', 'server_privileges.php', '/server/privileges' => '/server/privileges', default => '/', }; } @@ -4540,9 +4540,9 @@ final class Settings } return match ($settings['DefaultTabDatabase']) { - 'sql', 'db_sql.php' => '/database/sql', - 'search', 'db_search.php' => '/database/search', - 'operations', 'db_operations.php' => '/database/operations', + 'sql', 'db_sql.php', '/database/sql' => '/database/sql', + 'search', 'db_search.php', '/database/search' => '/database/search', + 'operations', 'db_operations.php', '/database/operations' => '/database/operations', default => '/database/structure', }; } @@ -4559,10 +4559,10 @@ final class Settings } return match ($settings['DefaultTabTable']) { - 'structure', 'tbl_structure.php' => '/table/structure', - 'sql', 'tbl_sql.php' => '/table/sql', - 'search', 'tbl_select.php' => '/table/search', - 'insert', 'tbl_change.php' => '/table/change', + 'structure', 'tbl_structure.php', '/table/structure' => '/table/structure', + 'sql', 'tbl_sql.php', '/table/sql' => '/table/sql', + 'search', 'tbl_select.php', '/table/search' => '/table/search', + 'insert', 'tbl_change.php', '/table/change' => '/table/change', default => '/sql', }; } diff --git a/src/Config/UserPreferencesHandler.php b/src/Config/UserPreferencesHandler.php index c2c49eab57..e524e6473f 100644 --- a/src/Config/UserPreferencesHandler.php +++ b/src/Config/UserPreferencesHandler.php @@ -21,6 +21,9 @@ class UserPreferencesHandler /** @var ''|'db'|'session' */ public string $storageType = ''; + /** @var mixed[] default configuration settings */ + public array $defaultSettings; + public function __construct( private readonly Config $config, private readonly DatabaseInterface $dbi, @@ -28,6 +31,7 @@ class UserPreferencesHandler private readonly LanguageManager $languageManager, private readonly ThemeManager $themeManager, ) { + $this->defaultSettings = (new Settings([]))->asArray(); } /** @@ -45,7 +49,6 @@ class UserPreferencesHandler ) { $prefs = $this->userPreferences->load(); $_SESSION['cache'][$cacheKey]['userprefs'] = $this->userPreferences->apply($prefs['config_data']); - $_SESSION['cache'][$cacheKey]['userprefs_mtime'] = $prefs['mtime']; $_SESSION['cache'][$cacheKey]['userprefs_type'] = $prefs['type']; $_SESSION['cache'][$cacheKey]['config_mtime'] = $this->config->sourceMtime; } @@ -58,7 +61,6 @@ class UserPreferencesHandler $configData = $_SESSION['cache'][$cacheKey]['userprefs']; // type is 'db' or 'session' $this->storageType = $_SESSION['cache'][$cacheKey]['userprefs_type']; - $this->config->set('user_preferences_mtime', $_SESSION['cache'][$cacheKey]['userprefs_mtime']); if (isset($configData['Server']) && is_array($configData['Server'])) { $serverConfig = array_replace_recursive($this->config->selectedServer, $configData['Server']); @@ -165,7 +167,7 @@ class UserPreferencesHandler // use permanent user preferences if possible if ($this->storageType !== '') { if ($defaultValue === null) { - $defaultValue = Core::arrayRead($cfgPath, $this->config->default); + $defaultValue = Core::arrayRead($cfgPath, $this->defaultSettings); } $result = $this->userPreferences->persistOption($cfgPath, $newCfgValue, $defaultValue); @@ -180,7 +182,7 @@ class UserPreferencesHandler $this->config->setCookie($cookieName, (string) $newCfgValue, $defaultValue); } - Core::arrayWrite($cfgPath, $this->config->settings, $newCfgValue); + $this->config->set($cfgPath, $newCfgValue); return $result; } diff --git a/src/Controllers/UserPasswordController.php b/src/Controllers/UserPasswordController.php index 6c93ff708e..8fb973da06 100644 --- a/src/Controllers/UserPasswordController.php +++ b/src/Controllers/UserPasswordController.php @@ -39,11 +39,9 @@ final readonly class UserPasswordController implements InvocableController * Displays an error message and exits if the user isn't allowed to use this * script */ - if (! $this->config->settings['ShowChgPassword']) { - $this->config->settings['ShowChgPassword'] = $this->dbi->selectDb('mysql'); - } + $hasAccessPrivilege = $this->config->config->ShowChgPassword || $this->dbi->selectDb('mysql'); - if ($this->config->selectedServer['auth_type'] === 'config' || ! $this->config->settings['ShowChgPassword']) { + if ($this->config->selectedServer['auth_type'] === 'config' || ! $hasAccessPrivilege) { $this->response->addHTML(Message::error( __('You don\'t have sufficient privileges to be here right now!'), )->getDisplay()); diff --git a/src/Theme/ThemeManager.php b/src/Theme/ThemeManager.php index ddcfcfbac1..552cce34c5 100644 --- a/src/Theme/ThemeManager.php +++ b/src/Theme/ThemeManager.php @@ -176,9 +176,6 @@ class ThemeManager $this->theme->getColorMode(), $this->theme->getColorModes()[0], ); - // force a change of a dummy session variable to avoid problems - // with the caching of phpmyadmin.css.php - $config->set('theme-update', $this->theme->id); } public function loadThemes(): void diff --git a/src/Utils/SessionCache.php b/src/Utils/SessionCache.php index facbba81c1..712d7d6f7f 100644 --- a/src/Utils/SessionCache.php +++ b/src/Utils/SessionCache.php @@ -14,11 +14,8 @@ final class SessionCache $key = 'server_' . Current::$server; $config = Config::getInstance(); - if (isset($config->selectedServer['user'])) { - return $key . '_' . $config->selectedServer['user']; - } - return $key; + return $key . '_' . $config->selectedServer['user']; } public static function has(string $name): bool diff --git a/tests/unit/AbstractTestCase.php b/tests/unit/AbstractTestCase.php index d719c81dcb..5cea5832e1 100644 --- a/tests/unit/AbstractTestCase.php +++ b/tests/unit/AbstractTestCase.php @@ -65,7 +65,6 @@ abstract class AbstractTestCase extends TestCase ExportSql::$noConstraintsComments = false; // Config before DBI - $this->setGlobalConfig(); Cache::purge(); Tracker::disable(); @@ -85,22 +84,6 @@ abstract class AbstractTestCase extends TestCase return new DbiDummy(); } - protected function createConfig(): Config - { - $config = new Config(); - $config->loadFromFile(); - - return $config; - } - - protected function setGlobalConfig(): void - { - Config::$instance = null; - $config = Config::getInstance(); - $config->loadFromFile(); - $config->set('environment', 'development'); - } - protected function setLanguage(string $code = 'en'): void { Current::$lang = $code; diff --git a/tests/unit/Advisory/AdvisorTest.php b/tests/unit/Advisory/AdvisorTest.php index e24b4943da..3ce928fb95 100644 --- a/tests/unit/Advisory/AdvisorTest.php +++ b/tests/unit/Advisory/AdvisorTest.php @@ -20,8 +20,6 @@ class AdvisorTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); } diff --git a/tests/unit/Bookmarks/BookmarkRepositoryTest.php b/tests/unit/Bookmarks/BookmarkRepositoryTest.php index 4ad6b8bdd9..e228abcf44 100644 --- a/tests/unit/Bookmarks/BookmarkRepositoryTest.php +++ b/tests/unit/Bookmarks/BookmarkRepositoryTest.php @@ -24,8 +24,7 @@ final class BookmarkRepositoryTest extends AbstractTestCase ]); (new ReflectionProperty(Relation::class, 'cache'))->setValue(null, $relationParameters); $dbi = $this->createDatabaseInterface(); - $config = Config::$instance = new Config(); - $bookmarkRepository = new BookmarkRepository($dbi, new Relation($dbi, $config)); + $bookmarkRepository = new BookmarkRepository($dbi, new Relation($dbi, new Config())); $bookmark = $bookmarkRepository->createBookmark('SELECT "phpmyadmin"', 'bookmark1', 'root', 'phpmyadmin'); self::assertNotFalse($bookmark); self::assertSame(0, $bookmark->getId()); diff --git a/tests/unit/Config/DescriptionTest.php b/tests/unit/Config/DescriptionTest.php index 7736dd3b79..d39e35bbf5 100644 --- a/tests/unit/Config/DescriptionTest.php +++ b/tests/unit/Config/DescriptionTest.php @@ -20,13 +20,6 @@ use function in_array; #[RunTestsInSeparateProcesses] class DescriptionTest extends AbstractTestCase { - protected function setUp(): void - { - parent::setUp(); - - $this->setGlobalConfig(); - } - /** * @param string $item item * @param string $type type diff --git a/tests/unit/Config/FormDisplayTemplateTest.php b/tests/unit/Config/FormDisplayTemplateTest.php index 6831b0a989..c8c16e1317 100644 --- a/tests/unit/Config/FormDisplayTemplateTest.php +++ b/tests/unit/Config/FormDisplayTemplateTest.php @@ -25,7 +25,7 @@ class FormDisplayTemplateTest extends AbstractTestCase $this->setLanguage(); - $this->config = $this->createConfig(); + $this->config = new Config(); $this->formDisplayTemplate = new FormDisplayTemplate($this->config); } diff --git a/tests/unit/Config/FormDisplayTest.php b/tests/unit/Config/FormDisplayTest.php index 7382bc3ba9..124526c9e5 100644 --- a/tests/unit/Config/FormDisplayTest.php +++ b/tests/unit/Config/FormDisplayTest.php @@ -31,8 +31,6 @@ class FormDisplayTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - Current::$server = 2; $this->object = new FormDisplay(new ConfigFile()); Form::resetGroupCounter(); diff --git a/tests/unit/Config/FormTest.php b/tests/unit/Config/FormTest.php index 6a29c82716..a1cdf2ced8 100644 --- a/tests/unit/Config/FormTest.php +++ b/tests/unit/Config/FormTest.php @@ -28,8 +28,6 @@ class FormTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->object = new Form( 'pma_form_name', ['pma_form1', 'pma_form2'], diff --git a/tests/unit/Config/Forms/FormListTest.php b/tests/unit/Config/Forms/FormListTest.php index 4689926229..e779cbd8fe 100644 --- a/tests/unit/Config/Forms/FormListTest.php +++ b/tests/unit/Config/Forms/FormListTest.php @@ -24,13 +24,6 @@ use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(UserFormList::class)] class FormListTest extends AbstractTestCase { - protected function setUp(): void - { - parent::setUp(); - - $this->setGlobalConfig(); - } - /** * Tests for preferences forms. * diff --git a/tests/unit/Config/Forms/Setup/FeaturesFormTest.php b/tests/unit/Config/Forms/Setup/FeaturesFormTest.php index b3d44b6afa..e2ccb01ef6 100644 --- a/tests/unit/Config/Forms/Setup/FeaturesFormTest.php +++ b/tests/unit/Config/Forms/Setup/FeaturesFormTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Config\Forms\Setup; -use PhpMyAdmin\Config; use PhpMyAdmin\Config\ConfigFile; use PhpMyAdmin\Config\Form; use PhpMyAdmin\Config\FormDisplay; @@ -22,8 +21,6 @@ final class FeaturesFormTest extends AbstractTestCase public function testRegisteredForms(): void { Form::resetGroupCounter(); - $config = new Config(); - Config::$instance = $config; $featuresForm = new FeaturesForm(new ConfigFile([]), 1); self::assertSame('Features', FeaturesForm::getName()); diff --git a/tests/unit/Config/PageSettingsTest.php b/tests/unit/Config/PageSettingsTest.php index 56af0b79d1..57e348a3e8 100644 --- a/tests/unit/Config/PageSettingsTest.php +++ b/tests/unit/Config/PageSettingsTest.php @@ -30,8 +30,6 @@ class PageSettingsTest extends AbstractTestCase $this->setLanguage(); - $this->setGlobalConfig(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); Current::$database = 'db'; Current::$table = ''; diff --git a/tests/unit/Config/ServerConfigChecksTest.php b/tests/unit/Config/ServerConfigChecksTest.php index 8462e628bc..5419a9c853 100644 --- a/tests/unit/Config/ServerConfigChecksTest.php +++ b/tests/unit/Config/ServerConfigChecksTest.php @@ -30,8 +30,6 @@ class ServerConfigChecksTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->configFile = new ConfigFile(); $reflection = new ReflectionProperty(ConfigFile::class, 'id'); diff --git a/tests/unit/Config/UserPreferencesHandlerTest.php b/tests/unit/Config/UserPreferencesHandlerTest.php index 0bb4bc75ac..a8fe693999 100644 --- a/tests/unit/Config/UserPreferencesHandlerTest.php +++ b/tests/unit/Config/UserPreferencesHandlerTest.php @@ -29,8 +29,8 @@ final class UserPreferencesHandlerTest extends AbstractTestCase new LanguageManager($config), new ThemeManager(), ); - $userPreferencesHandler->setUserValue(null, 'lang', 'cs', 'en'); - $userPreferencesHandler->setUserValue('TEST_COOKIE_USER_VAL', '', 'cfg_val_1'); + $userPreferencesHandler->setUserValue(null, 'Lang', 'cs', 'en'); + $userPreferencesHandler->setUserValue('TEST_COOKIE_USER_VAL', 'Servers/1/hide_db', 'cfg_val_1'); self::assertSame('cfg_val_1', $userPreferencesHandler->getUserValue('TEST_COOKIE_USER_VAL', 'fail')); $userPreferencesHandler->setUserValue(null, 'NavigationWidth', 300); self::assertSame(300, $config->settings['NavigationWidth']); diff --git a/tests/unit/Config/ValidatorTest.php b/tests/unit/Config/ValidatorTest.php index fa6e65a2f9..77a5d86a61 100644 --- a/tests/unit/Config/ValidatorTest.php +++ b/tests/unit/Config/ValidatorTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Config; -use PhpMyAdmin\Config; use PhpMyAdmin\Config\ConfigFile; use PhpMyAdmin\Config\Validator; use PhpMyAdmin\Tests\AbstractTestCase; @@ -15,7 +14,6 @@ final class ValidatorTest extends AbstractTestCase { public function testGetValidators(): void { - Config::$instance = new Config(); $validator = new Validator(new ConfigFile([])); $validators = $validator->getValidators(); $expected = [ diff --git a/tests/unit/ConfigTest.php b/tests/unit/ConfigTest.php index 08b455e3bb..c74d2c2a27 100644 --- a/tests/unit/ConfigTest.php +++ b/tests/unit/ConfigTest.php @@ -26,7 +26,6 @@ use function tempnam; use function unlink; use const CHANGELOG_FILE; -use const CONFIG_FILE; use const DIRECTORY_SEPARATOR; use const PHP_OS; @@ -52,16 +51,20 @@ class ConfigTest extends AbstractTestCase $this->object = $this->createConfig(); $_SESSION['git_location'] = '.git'; $_SESSION['is_git_revision'] = true; - Config::$instance = null; - $config = Config::getInstance(); - $config->loadFromFile(CONFIG_FILE); - $config->settings['ProxyUrl'] = ''; //for testing file permissions $this->permTestObj = new Config(); $this->permTestObj->loadFromFile(ROOT_PATH . 'config.sample.inc.php'); } + protected function createConfig(): Config + { + $config = new Config(); + $config->loadFromFile(); + + return $config; + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. @@ -159,7 +162,6 @@ class ConfigTest extends AbstractTestCase $config = $settings->asArray(); self::assertIsArray($config['Servers']); self::assertEquals($settings, $object->getSettings()); - self::assertSame($config, $object->default); self::assertSame($config, $object->settings); self::assertSame($config, $object->baseSettings); } diff --git a/tests/unit/Controllers/Server/BinlogControllerTest.php b/tests/unit/Controllers/Server/BinlogControllerTest.php index be1e5bd2c2..efc5cfd689 100644 --- a/tests/unit/Controllers/Server/BinlogControllerTest.php +++ b/tests/unit/Controllers/Server/BinlogControllerTest.php @@ -27,8 +27,6 @@ class BinlogControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/CollationsControllerTest.php b/tests/unit/Controllers/Server/CollationsControllerTest.php index f55203f813..b701928aff 100644 --- a/tests/unit/Controllers/Server/CollationsControllerTest.php +++ b/tests/unit/Controllers/Server/CollationsControllerTest.php @@ -28,8 +28,6 @@ class CollationsControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/DatabasesControllerTest.php b/tests/unit/Controllers/Server/DatabasesControllerTest.php index b3fb1e66ae..6287687a4c 100644 --- a/tests/unit/Controllers/Server/DatabasesControllerTest.php +++ b/tests/unit/Controllers/Server/DatabasesControllerTest.php @@ -28,8 +28,6 @@ class DatabasesControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/EnginesControllerTest.php b/tests/unit/Controllers/Server/EnginesControllerTest.php index 4e578727cf..c49a8105e1 100644 --- a/tests/unit/Controllers/Server/EnginesControllerTest.php +++ b/tests/unit/Controllers/Server/EnginesControllerTest.php @@ -28,8 +28,6 @@ class EnginesControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/PluginsControllerTest.php b/tests/unit/Controllers/Server/PluginsControllerTest.php index 1fa2a9d69a..de312d09df 100644 --- a/tests/unit/Controllers/Server/PluginsControllerTest.php +++ b/tests/unit/Controllers/Server/PluginsControllerTest.php @@ -30,8 +30,6 @@ class PluginsControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/ShowEngineControllerTest.php b/tests/unit/Controllers/Server/ShowEngineControllerTest.php index d136e9d2a7..5ee9f06319 100644 --- a/tests/unit/Controllers/Server/ShowEngineControllerTest.php +++ b/tests/unit/Controllers/Server/ShowEngineControllerTest.php @@ -30,8 +30,6 @@ class ShowEngineControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/Status/AdvisorControllerTest.php b/tests/unit/Controllers/Server/Status/AdvisorControllerTest.php index 959e2cbd9a..85fdcd66e3 100644 --- a/tests/unit/Controllers/Server/Status/AdvisorControllerTest.php +++ b/tests/unit/Controllers/Server/Status/AdvisorControllerTest.php @@ -29,8 +29,6 @@ class AdvisorControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); $config = Config::getInstance(); diff --git a/tests/unit/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php b/tests/unit/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php index a9b80adae0..db5fb584be 100644 --- a/tests/unit/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php +++ b/tests/unit/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php @@ -30,8 +30,6 @@ class GeneralLogControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/Status/Monitor/LogVarsControllerTest.php b/tests/unit/Controllers/Server/Status/Monitor/LogVarsControllerTest.php index 13e0b5cc06..06a7a7a269 100644 --- a/tests/unit/Controllers/Server/Status/Monitor/LogVarsControllerTest.php +++ b/tests/unit/Controllers/Server/Status/Monitor/LogVarsControllerTest.php @@ -30,8 +30,6 @@ class LogVarsControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/Status/Monitor/SlowLogControllerTest.php b/tests/unit/Controllers/Server/Status/Monitor/SlowLogControllerTest.php index 2ed1bde1e2..8dca32598a 100644 --- a/tests/unit/Controllers/Server/Status/Monitor/SlowLogControllerTest.php +++ b/tests/unit/Controllers/Server/Status/Monitor/SlowLogControllerTest.php @@ -30,8 +30,6 @@ class SlowLogControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/Status/MonitorControllerTest.php b/tests/unit/Controllers/Server/Status/MonitorControllerTest.php index 68bcd7eefb..46e7ecb340 100644 --- a/tests/unit/Controllers/Server/Status/MonitorControllerTest.php +++ b/tests/unit/Controllers/Server/Status/MonitorControllerTest.php @@ -31,8 +31,6 @@ class MonitorControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/Status/Processes/RefreshControllerTest.php b/tests/unit/Controllers/Server/Status/Processes/RefreshControllerTest.php index 74ede6e831..1d17a16fff 100644 --- a/tests/unit/Controllers/Server/Status/Processes/RefreshControllerTest.php +++ b/tests/unit/Controllers/Server/Status/Processes/RefreshControllerTest.php @@ -31,8 +31,6 @@ class RefreshControllerTest extends AbstractTestCase DatabaseInterface::$instance = $this->createDatabaseInterface(); - $this->setGlobalConfig(); - Current::$database = 'db'; Current::$table = 'table'; $config = Config::getInstance(); diff --git a/tests/unit/Controllers/Server/Status/ProcessesControllerTest.php b/tests/unit/Controllers/Server/Status/ProcessesControllerTest.php index 26ca5ebfa1..ae4726c89f 100644 --- a/tests/unit/Controllers/Server/Status/ProcessesControllerTest.php +++ b/tests/unit/Controllers/Server/Status/ProcessesControllerTest.php @@ -31,8 +31,6 @@ class ProcessesControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/Status/QueriesControllerTest.php b/tests/unit/Controllers/Server/Status/QueriesControllerTest.php index 3814a998a1..1a6482c5ed 100644 --- a/tests/unit/Controllers/Server/Status/QueriesControllerTest.php +++ b/tests/unit/Controllers/Server/Status/QueriesControllerTest.php @@ -34,8 +34,6 @@ class QueriesControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/Status/StatusControllerTest.php b/tests/unit/Controllers/Server/Status/StatusControllerTest.php index d0762c9ec5..25c52599ec 100644 --- a/tests/unit/Controllers/Server/Status/StatusControllerTest.php +++ b/tests/unit/Controllers/Server/Status/StatusControllerTest.php @@ -29,8 +29,6 @@ class StatusControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/Status/VariablesControllerTest.php b/tests/unit/Controllers/Server/Status/VariablesControllerTest.php index 9d62da0cda..886e878a17 100644 --- a/tests/unit/Controllers/Server/Status/VariablesControllerTest.php +++ b/tests/unit/Controllers/Server/Status/VariablesControllerTest.php @@ -29,8 +29,6 @@ class VariablesControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Controllers/Server/VariablesControllerTest.php b/tests/unit/Controllers/Server/VariablesControllerTest.php index 083c6cc779..c5297c903b 100644 --- a/tests/unit/Controllers/Server/VariablesControllerTest.php +++ b/tests/unit/Controllers/Server/VariablesControllerTest.php @@ -35,8 +35,6 @@ class VariablesControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->setLanguage(); Current::$database = 'db'; diff --git a/tests/unit/Controllers/Table/AddFieldControllerTest.php b/tests/unit/Controllers/Table/AddFieldControllerTest.php index 2880839595..201a0bcb71 100644 --- a/tests/unit/Controllers/Table/AddFieldControllerTest.php +++ b/tests/unit/Controllers/Table/AddFieldControllerTest.php @@ -261,7 +261,7 @@ class AddFieldControllerTest extends AbstractTestCase (new AddFieldController( $response, $transformations, - $this->createConfig(), + new Config(), $dbi, new ColumnsDefinition($dbi, $relation, $transformations), new DbTableExists($dbi), diff --git a/tests/unit/Controllers/Table/CreateControllerTest.php b/tests/unit/Controllers/Table/CreateControllerTest.php index bc13c7b0ec..4a3f547e24 100644 --- a/tests/unit/Controllers/Table/CreateControllerTest.php +++ b/tests/unit/Controllers/Table/CreateControllerTest.php @@ -276,7 +276,7 @@ class CreateControllerTest extends AbstractTestCase (new CreateController( $response, $transformations, - $this->createConfig(), + new Config(), $dbi, new ColumnsDefinition($dbi, $relation, $transformations), new UserPrivilegesFactory($dbi), diff --git a/tests/unit/Controllers/Table/Maintenance/AnalyzeControllerTest.php b/tests/unit/Controllers/Table/Maintenance/AnalyzeControllerTest.php index 8b110ce156..791aa80e67 100644 --- a/tests/unit/Controllers/Table/Maintenance/AnalyzeControllerTest.php +++ b/tests/unit/Controllers/Table/Maintenance/AnalyzeControllerTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance; +use PhpMyAdmin\Config; use PhpMyAdmin\Controllers\Table\Maintenance\AnalyzeController; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Http\ServerRequest; @@ -25,7 +26,7 @@ class AnalyzeControllerTest extends AbstractTestCase $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $response = new ResponseRenderer(); - $controller = new AnalyzeController($response, new Maintenance($dbi), $this->createConfig()); + $controller = new AnalyzeController($response, new Maintenance($dbi), new Config()); $controller($request); self::assertFalse($response->hasSuccessState()); self::assertSame(['message' => 'No table selected.'], $response->getJSONResult()); diff --git a/tests/unit/Controllers/Table/Maintenance/CheckControllerTest.php b/tests/unit/Controllers/Table/Maintenance/CheckControllerTest.php index 72ade86626..9d2a0e5414 100644 --- a/tests/unit/Controllers/Table/Maintenance/CheckControllerTest.php +++ b/tests/unit/Controllers/Table/Maintenance/CheckControllerTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance; +use PhpMyAdmin\Config; use PhpMyAdmin\Controllers\Table\Maintenance\CheckController; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Http\ServerRequest; @@ -25,7 +26,7 @@ class CheckControllerTest extends AbstractTestCase $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $response = new ResponseRenderer(); - $controller = new CheckController($response, new Maintenance($dbi), $this->createConfig()); + $controller = new CheckController($response, new Maintenance($dbi), new Config()); $controller($request); self::assertFalse($response->hasSuccessState()); self::assertSame(['message' => 'No table selected.'], $response->getJSONResult()); diff --git a/tests/unit/Controllers/Table/Maintenance/ChecksumControllerTest.php b/tests/unit/Controllers/Table/Maintenance/ChecksumControllerTest.php index 85a83aab1f..85f78964a8 100644 --- a/tests/unit/Controllers/Table/Maintenance/ChecksumControllerTest.php +++ b/tests/unit/Controllers/Table/Maintenance/ChecksumControllerTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance; +use PhpMyAdmin\Config; use PhpMyAdmin\Controllers\Table\Maintenance\ChecksumController; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Http\ServerRequest; @@ -25,7 +26,7 @@ class ChecksumControllerTest extends AbstractTestCase $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $response = new ResponseRenderer(); - $controller = new ChecksumController($response, new Maintenance($dbi), $this->createConfig()); + $controller = new ChecksumController($response, new Maintenance($dbi), new Config()); $controller($request); self::assertFalse($response->hasSuccessState()); self::assertSame(['message' => 'No table selected.'], $response->getJSONResult()); diff --git a/tests/unit/Controllers/Table/Maintenance/OptimizeControllerTest.php b/tests/unit/Controllers/Table/Maintenance/OptimizeControllerTest.php index 99ab3a58d9..cb79f99b7d 100644 --- a/tests/unit/Controllers/Table/Maintenance/OptimizeControllerTest.php +++ b/tests/unit/Controllers/Table/Maintenance/OptimizeControllerTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance; +use PhpMyAdmin\Config; use PhpMyAdmin\Controllers\Table\Maintenance\OptimizeController; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Http\ServerRequest; @@ -25,7 +26,7 @@ class OptimizeControllerTest extends AbstractTestCase $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $response = new ResponseRenderer(); - $controller = new OptimizeController($response, new Maintenance($dbi), $this->createConfig()); + $controller = new OptimizeController($response, new Maintenance($dbi), new Config()); $controller($request); self::assertFalse($response->hasSuccessState()); self::assertSame(['message' => 'No table selected.'], $response->getJSONResult()); diff --git a/tests/unit/Controllers/Table/Maintenance/RepairControllerTest.php b/tests/unit/Controllers/Table/Maintenance/RepairControllerTest.php index 1ac5af54a1..2c06e6ae57 100644 --- a/tests/unit/Controllers/Table/Maintenance/RepairControllerTest.php +++ b/tests/unit/Controllers/Table/Maintenance/RepairControllerTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance; +use PhpMyAdmin\Config; use PhpMyAdmin\Controllers\Table\Maintenance\RepairController; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Http\ServerRequest; @@ -25,7 +26,7 @@ class RepairControllerTest extends AbstractTestCase $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $response = new ResponseRenderer(); - $controller = new RepairController($response, new Maintenance($dbi), $this->createConfig()); + $controller = new RepairController($response, new Maintenance($dbi), new Config()); $controller($request); self::assertFalse($response->hasSuccessState()); self::assertSame(['message' => 'No table selected.'], $response->getJSONResult()); diff --git a/tests/unit/Controllers/Transformation/OverviewControllerTest.php b/tests/unit/Controllers/Transformation/OverviewControllerTest.php index 4d21d3ca19..dc01b38168 100644 --- a/tests/unit/Controllers/Transformation/OverviewControllerTest.php +++ b/tests/unit/Controllers/Transformation/OverviewControllerTest.php @@ -25,8 +25,6 @@ class OverviewControllerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - Current::$database = 'db'; Current::$table = 'table'; } diff --git a/tests/unit/Database/CentralColumnsTest.php b/tests/unit/Database/CentralColumnsTest.php index 831c911253..d74eba1a51 100644 --- a/tests/unit/Database/CentralColumnsTest.php +++ b/tests/unit/Database/CentralColumnsTest.php @@ -103,8 +103,6 @@ class CentralColumnsTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $config = Config::getInstance(); $config->selectedServer['user'] = 'pma_user'; $config->selectedServer['DisableIS'] = true; diff --git a/tests/unit/Database/EventsTest.php b/tests/unit/Database/EventsTest.php index 3677f30ead..a1576ec716 100644 --- a/tests/unit/Database/EventsTest.php +++ b/tests/unit/Database/EventsTest.php @@ -24,8 +24,6 @@ class EventsTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->setLanguage(); DatabaseInterface::$instance = $this->createDatabaseInterface(); diff --git a/tests/unit/Database/RoutinesTest.php b/tests/unit/Database/RoutinesTest.php index 8b08d3b9ab..ffd03868f5 100644 --- a/tests/unit/Database/RoutinesTest.php +++ b/tests/unit/Database/RoutinesTest.php @@ -28,8 +28,6 @@ class RoutinesTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->setLanguage(); DatabaseInterface::$instance = $this->createDatabaseInterface(); diff --git a/tests/unit/Display/ResultsTest.php b/tests/unit/Display/ResultsTest.php index 54eef12c64..1c473a4df9 100644 --- a/tests/unit/Display/ResultsTest.php +++ b/tests/unit/Display/ResultsTest.php @@ -73,8 +73,6 @@ class ResultsTest extends AbstractTestCase $this->setLanguage(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Export/OptionsTest.php b/tests/unit/Export/OptionsTest.php index 71ccbc6cce..13cdc7f57c 100644 --- a/tests/unit/Export/OptionsTest.php +++ b/tests/unit/Export/OptionsTest.php @@ -35,8 +35,6 @@ class OptionsTest extends AbstractTestCase $this->setLanguage(); - $this->setGlobalConfig(); - $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; @@ -56,13 +54,6 @@ class OptionsTest extends AbstractTestCase $this->export = new Options($relation, new TemplateModel($dbi), $userPreferencesHandler); } - protected function tearDown(): void - { - parent::tearDown(); - - Config::$instance = null; - } - public function testGetOptions(): void { $config = Config::getInstance(); diff --git a/tests/unit/FooterTest.php b/tests/unit/FooterTest.php index d0a354cec5..0d8a093509 100644 --- a/tests/unit/FooterTest.php +++ b/tests/unit/FooterTest.php @@ -34,8 +34,6 @@ class FooterTest extends AbstractTestCase $this->setLanguage(); - $this->setGlobalConfig(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); $_SERVER['SCRIPT_NAME'] = 'index.php'; Current::$database = ''; diff --git a/tests/unit/HeaderTest.php b/tests/unit/HeaderTest.php index 677f2d3a87..6a7429ff69 100644 --- a/tests/unit/HeaderTest.php +++ b/tests/unit/HeaderTest.php @@ -44,8 +44,6 @@ class HeaderTest extends AbstractTestCase Current::$database = 'db'; Current::$table = ''; - $this->setGlobalConfig(); - $config = Config::getInstance(); $config->settings['Servers'] = []; $config->selectedServer['DisableIS'] = false; diff --git a/tests/unit/InsertEditTest.php b/tests/unit/InsertEditTest.php index 87d0f4cc44..3de6b4e706 100644 --- a/tests/unit/InsertEditTest.php +++ b/tests/unit/InsertEditTest.php @@ -65,8 +65,6 @@ class InsertEditTest extends AbstractTestCase $this->setLanguage(); - $this->setGlobalConfig(); - $this->dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; diff --git a/tests/unit/Navigation/NavigationTreeTest.php b/tests/unit/Navigation/NavigationTreeTest.php index baa4424a3b..999f7bba14 100644 --- a/tests/unit/Navigation/NavigationTreeTest.php +++ b/tests/unit/Navigation/NavigationTreeTest.php @@ -28,8 +28,6 @@ class NavigationTreeTest extends AbstractTestCase $this->setLanguage(); - $this->setGlobalConfig(); - $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $config = Config::getInstance(); diff --git a/tests/unit/PdfTest.php b/tests/unit/PdfTest.php index 182a83139b..fb0981dbcd 100644 --- a/tests/unit/PdfTest.php +++ b/tests/unit/PdfTest.php @@ -12,16 +12,6 @@ use PHPUnit\Framework\Attributes\Large; #[Large] class PdfTest extends AbstractTestCase { - /** - * SetUp for test cases - */ - protected function setUp(): void - { - parent::setUp(); - - $this->setGlobalConfig(); - } - /** * Test for Pdf::getPDFData */ diff --git a/tests/unit/Plugins/Auth/AuthenticationConfigTest.php b/tests/unit/Plugins/Auth/AuthenticationConfigTest.php index 1e6788958d..a01fa8f1c8 100644 --- a/tests/unit/Plugins/Auth/AuthenticationConfigTest.php +++ b/tests/unit/Plugins/Auth/AuthenticationConfigTest.php @@ -32,8 +32,6 @@ class AuthenticationConfigTest extends AbstractTestCase $this->setLanguage(); - $this->setGlobalConfig(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); Current::$server = 2; Current::$database = 'db'; diff --git a/tests/unit/Plugins/Auth/AuthenticationCookieTest.php b/tests/unit/Plugins/Auth/AuthenticationCookieTest.php index 75e104537c..96253b57d9 100644 --- a/tests/unit/Plugins/Auth/AuthenticationCookieTest.php +++ b/tests/unit/Plugins/Auth/AuthenticationCookieTest.php @@ -52,8 +52,6 @@ class AuthenticationCookieTest extends AbstractTestCase $this->setLanguage(); - $this->setGlobalConfig(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); Current::$database = 'db'; Current::$table = 'table'; diff --git a/tests/unit/Plugins/Auth/AuthenticationHttpTest.php b/tests/unit/Plugins/Auth/AuthenticationHttpTest.php index 0aa53ea2da..ad1a758ad8 100644 --- a/tests/unit/Plugins/Auth/AuthenticationHttpTest.php +++ b/tests/unit/Plugins/Auth/AuthenticationHttpTest.php @@ -33,8 +33,6 @@ class AuthenticationHttpTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); Config::getInstance()->settings['Servers'] = []; Current::$database = 'db'; diff --git a/tests/unit/Plugins/Auth/AuthenticationSignonTest.php b/tests/unit/Plugins/Auth/AuthenticationSignonTest.php index fe05587f00..7b03943e3a 100644 --- a/tests/unit/Plugins/Auth/AuthenticationSignonTest.php +++ b/tests/unit/Plugins/Auth/AuthenticationSignonTest.php @@ -37,8 +37,6 @@ class AuthenticationSignonTest extends AbstractTestCase $this->setLanguage(); - $this->setGlobalConfig(); - DatabaseInterface::$instance = $this->createDatabaseInterface(); Current::$database = 'db'; Current::$table = 'table'; diff --git a/tests/unit/Setup/ConfigGeneratorTest.php b/tests/unit/Setup/ConfigGeneratorTest.php index 27d499f64d..1e631a76a6 100644 --- a/tests/unit/Setup/ConfigGeneratorTest.php +++ b/tests/unit/Setup/ConfigGeneratorTest.php @@ -31,8 +31,6 @@ class ConfigGeneratorTest extends AbstractTestCase { unset($_SESSION['eol']); - $this->setGlobalConfig(); - Current::$server = 2; $cf = new ConfigFile(); $_SESSION['ConfigFile2'] = ['a', 'b', 'c']; diff --git a/tests/unit/Theme/ThemeManagerTest.php b/tests/unit/Theme/ThemeManagerTest.php index ddaf113572..59804fe991 100644 --- a/tests/unit/Theme/ThemeManagerTest.php +++ b/tests/unit/Theme/ThemeManagerTest.php @@ -19,8 +19,6 @@ class ThemeManagerTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - Current::$server = 99; } diff --git a/tests/unit/Theme/ThemeTest.php b/tests/unit/Theme/ThemeTest.php index 2b3e26da07..3b1374586a 100644 --- a/tests/unit/Theme/ThemeTest.php +++ b/tests/unit/Theme/ThemeTest.php @@ -32,8 +32,6 @@ class ThemeTest extends AbstractTestCase parent::setUp(); $this->object = new Theme(); - - $this->setGlobalConfig(); } /** diff --git a/tests/unit/Triggers/TriggersTest.php b/tests/unit/Triggers/TriggersTest.php index 77ab0b3023..126e703d5d 100644 --- a/tests/unit/Triggers/TriggersTest.php +++ b/tests/unit/Triggers/TriggersTest.php @@ -26,8 +26,6 @@ class TriggersTest extends AbstractTestCase { parent::setUp(); - $this->setGlobalConfig(); - $this->setLanguage(); DatabaseInterface::$instance = $this->createDatabaseInterface(); diff --git a/tests/unit/TwoFactorTest.php b/tests/unit/TwoFactorTest.php index 39695696c8..17cc566af7 100644 --- a/tests/unit/TwoFactorTest.php +++ b/tests/unit/TwoFactorTest.php @@ -61,6 +61,8 @@ class TwoFactorTest extends AbstractTestCase protected function tearDown(): void { $this->dummyDbi->assertAllSelectsConsumed(); + + parent::tearDown(); } private function initStorageConfigAndData(): void diff --git a/tests/unit/UtilTest.php b/tests/unit/UtilTest.php index f24fccf29b..d307a63e12 100644 --- a/tests/unit/UtilTest.php +++ b/tests/unit/UtilTest.php @@ -104,17 +104,17 @@ class UtilTest extends AbstractTestCase public function testClearUserCache(): void { - Config::getInstance()->selectedServer['user'] = null; + Config::getInstance()->selectedServer['user'] = ''; Current::$server = 2; SessionCache::set('is_superuser', 'yes'); - self::assertSame('yes', $_SESSION['cache']['server_2']['is_superuser']); + self::assertSame('yes', $_SESSION['cache']['server_2_']['is_superuser']); SessionCache::set('mysql_cur_user', 'mysql'); - self::assertSame('mysql', $_SESSION['cache']['server_2']['mysql_cur_user']); + self::assertSame('mysql', $_SESSION['cache']['server_2_']['mysql_cur_user']); Util::clearUserCache(); - self::assertArrayNotHasKey('is_superuser', $_SESSION['cache']['server_2']); - self::assertArrayNotHasKey('mysql_cur_user', $_SESSION['cache']['server_2']); + self::assertArrayNotHasKey('is_superuser', $_SESSION['cache']['server_2_']); + self::assertArrayNotHasKey('mysql_cur_user', $_SESSION['cache']['server_2_']); } /** diff --git a/tests/unit/Utils/SessionCacheTest.php b/tests/unit/Utils/SessionCacheTest.php index 07b762df5e..ce8ba61109 100644 --- a/tests/unit/Utils/SessionCacheTest.php +++ b/tests/unit/Utils/SessionCacheTest.php @@ -16,7 +16,7 @@ class SessionCacheTest extends TestCase public function testGet(): void { $_SESSION = []; - Config::getInstance()->selectedServer['user'] = null; + Config::getInstance()->selectedServer['user'] = ''; SessionCache::set('test_data', 5); SessionCache::set('test_data_2', 5); @@ -29,35 +29,35 @@ class SessionCacheTest extends TestCase public function testRemove(): void { $_SESSION = []; - Config::getInstance()->selectedServer['user'] = null; + Config::getInstance()->selectedServer['user'] = ''; Current::$server = 2; SessionCache::set('test_data', 25); SessionCache::set('test_data_2', 25); SessionCache::remove('test_data'); - self::assertArrayNotHasKey('test_data', $_SESSION['cache']['server_2']); + self::assertArrayNotHasKey('test_data', $_SESSION['cache']['server_2_']); SessionCache::remove('test_data_2'); - self::assertArrayNotHasKey('test_data_2', $_SESSION['cache']['server_2']); + self::assertArrayNotHasKey('test_data_2', $_SESSION['cache']['server_2_']); } public function testSet(): void { $_SESSION = []; - Config::getInstance()->selectedServer['user'] = null; + Config::getInstance()->selectedServer['user'] = ''; Current::$server = 2; SessionCache::set('test_data', 25); SessionCache::set('test_data', 5); - self::assertSame(5, $_SESSION['cache']['server_2']['test_data']); + self::assertSame(5, $_SESSION['cache']['server_2_']['test_data']); SessionCache::set('test_data_3', 3); - self::assertSame(3, $_SESSION['cache']['server_2']['test_data_3']); + self::assertSame(3, $_SESSION['cache']['server_2_']['test_data_3']); } public function testHas(): void { $_SESSION = []; - Config::getInstance()->selectedServer['user'] = null; + Config::getInstance()->selectedServer['user'] = ''; SessionCache::set('test_data', 5); SessionCache::set('test_data_2', 5); @@ -74,16 +74,16 @@ class SessionCacheTest extends TestCase public function testKeyWithoutUser(): void { $_SESSION = []; - Config::getInstance()->selectedServer['user'] = null; + Config::getInstance()->selectedServer['user'] = ''; Current::$server = 123; SessionCache::set('test_data', 5); self::assertArrayHasKey('cache', $_SESSION); self::assertIsArray($_SESSION['cache']); - self::assertArrayHasKey('server_123', $_SESSION['cache']); - self::assertIsArray($_SESSION['cache']['server_123']); - self::assertArrayHasKey('test_data', $_SESSION['cache']['server_123']); - self::assertSame(5, $_SESSION['cache']['server_123']['test_data']); + self::assertArrayHasKey('server_123_', $_SESSION['cache']); + self::assertIsArray($_SESSION['cache']['server_123_']); + self::assertArrayHasKey('test_data', $_SESSION['cache']['server_123_']); + self::assertSame(5, $_SESSION['cache']['server_123_']['test_data']); } public function testKeyWithUser(): void