From ae2072f4d502774c9f2c4a79265f368e83f457d1 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 21 Sep 2021 13:56:15 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B03002=20Get=20developer=5Fmode.enabled=20?= =?UTF-8?q?config=20param=20first=20normally,=20and=20if=20not=20set=20fro?= =?UTF-8?q?m=20disk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/utils.inc.php | 36 ++++++++++++++++++++++++++---- test/core/Log/ExceptionLogTest.php | 16 +++---------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/application/utils.inc.php b/application/utils.inc.php index 23fca6cb9..c87192658 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -2827,13 +2827,12 @@ HTML; * @since 2.6.0 method creation * @since 3.0.0 add the `developer_mode.enabled` config parameter * - * @uses developer_mode.enabled config parameter, but always read it from disk + * @uses GetDeveloperModeParam * @uses ITOP_REVISION constant (check 'svn' value) */ public static function IsDevelopmentEnvironment() { - $oConfig = utils::GetConfig(true); - $bIsDevEnvInConfig = $oConfig->Get('developer_mode.enabled'); + $bIsDevEnvInConfig = static::GetDeveloperModeParam(); if ($bIsDevEnvInConfig === true) { return true; } @@ -2851,7 +2850,36 @@ HTML; } /** - * @return bool : indicate whether we run under a windows environnement or not + * In the setup there are times when the MetaModel config attribute is loaded but partially (only setup parameters are set, others have the default value) + * So we need to load from disk then ! + * + * But in other scenario we want to read from memory : for example when changing the option in a PHPUnit setUp method + * + * This method will first try to get the `developer_mode.enabled` config parameter the standard way (call to GetConfig without modification). + * If we are getting null (not defined parameter), then we will load config from disk only (GetConfig(true)) + * + * @return bool|null + * @throws \ConfigException + * @throws \CoreException + * + * @uses developer_mode.enabled config parameter + */ + private static function GetDeveloperModeParam(): ?bool + { + $oConfig = static::GetConfig(false); + $bIsDevEnvInConfig = $oConfig->Get('developer_mode.enabled'); + + if (!is_null($bIsDevEnvInConfig)) { + return $bIsDevEnvInConfig; + } + + $oConfigFromDisk = static::GetConfig(true); + + return $oConfigFromDisk->Get('developer_mode.enabled'); + } + + /** + * @return bool true if we are running under a Windows environment * @since 2.7.4 : N°3412 */ public static function IsWindowsEnvironment() diff --git a/test/core/Log/ExceptionLogTest.php b/test/core/Log/ExceptionLogTest.php index dc1c5e242..fb6c943ac 100644 --- a/test/core/Log/ExceptionLogTest.php +++ b/test/core/Log/ExceptionLogTest.php @@ -16,9 +16,7 @@ namespace Combodo\iTop\Test\UnitTest\Core\Log; use Combodo\iTop\Test\UnitTest\ItopDataTestCase; -use DeprecatedCallsLog; use ExceptionLog; -use LogAPI; use MetaModel; @@ -32,18 +30,10 @@ class ExceptionLogTest extends ItopDataTestCase parent::setUp(); // We are using PHPUnit\Framework\MockObject\Generator::generateMock that is throwing notice ! - // Changing the log config so that those won't be caught by \DeprecatedCallsLog::DeprecatedNoticesErrorHandler + // Changing config so that those won't be caught by \DeprecatedCallsLog::DeprecatedNoticesErrorHandler + // disabling devenv is easier than changing log config O:) $oConfig = MetaModel::GetConfig(); - $mLogLevelMin = $oConfig->Get('log_level_min'); - if (is_string($mLogLevelMin)) { - $aLogLevelMin[''] = $mLogLevelMin; - } else if (is_array($mLogLevelMin)) { - $aLogLevelMin = $mLogLevelMin; - } else { - $aLogLevelMin = []; - } - $aLogLevelMin[DeprecatedCallsLog::ENUM_CHANNEL_PHP_LIBMETHOD] = LogAPI::LEVEL_ERROR; - $oConfig->Set('log_level_min', $aLogLevelMin); + $oConfig->Set('developer_mode.enabled', false); } /**