From 1884596ecd0c439470297c8e8f1a2651dea890e3 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Thu, 4 May 2023 17:33:25 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B06274=20Fix=20log.class.inc.php=20crashin?= =?UTF-8?q?g=20cause=20cannot=20load=20ItopTestCase=20class=20Now=20the=20?= =?UTF-8?q?constant=20name=20is=20defined=20in=20approot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- approot.inc.php | 5 +++++ core/log.class.inc.php | 3 +-- tests/php-unit-tests/ItopTestCase.php | 15 +++++---------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/approot.inc.php b/approot.inc.php index f2a70685b..36a984ab1 100644 --- a/approot.inc.php +++ b/approot.inc.php @@ -25,4 +25,9 @@ define('ITOP_DESIGN_LATEST_VERSION', '3.0'); */ define('ITOP_CORE_VERSION', '3.0.3'); +/** + * @since 3.0.4 N°6274 Allow to test if PHPUnit is currently running. Starting with PHPUnit 9.5 we'll be able to replace it with $GLOBALS['phpunit_version'] + */ +define('ITOP_PHPUNIT_RUNNING_CONSTANT_NAME', 'ITOP_PHPUNIT_RUNNING'); + require_once APPROOT.'bootstrap.inc.php'; diff --git a/core/log.class.inc.php b/core/log.class.inc.php index c41b4e31f..29e382f20 100644 --- a/core/log.class.inc.php +++ b/core/log.class.inc.php @@ -15,7 +15,6 @@ // // You should have received a copy of the GNU Affero General Public License // along with iTop. If not, see -use Combodo\iTop\Test\UnitTest\ItopTestCase; /** @@ -1081,7 +1080,7 @@ class DeprecatedCallsLog extends LogAPI parent::Enable($sTargetFile); if ( - (false === defined(ItopTestCase::ITOP_PHPUNIT_RUNNING_CONSTANT_NAME)) + (false === defined(ITOP_PHPUNIT_RUNNING_CONSTANT_NAME)) && static::IsLogLevelEnabledSafe(self::LEVEL_WARNING, self::ENUM_CHANNEL_PHP_LIBMETHOD) ) { set_error_handler([static::class, 'DeprecatedNoticesErrorHandler'], E_DEPRECATED | E_USER_DEPRECATED); diff --git a/tests/php-unit-tests/ItopTestCase.php b/tests/php-unit-tests/ItopTestCase.php index 5dec2a274..c2792bf22 100644 --- a/tests/php-unit-tests/ItopTestCase.php +++ b/tests/php-unit-tests/ItopTestCase.php @@ -33,19 +33,9 @@ use SetupUtils; define('DEBUG_UNIT_TEST', true); class ItopTestCase extends TestCase { - /** - * @since 3.0.4 N°6274 Allow to test if PHPUnit is currently running. Starting with PHPUnit 9.5 we'll be able to replace it with $GLOBALS['phpunit_version'] - */ - public const ITOP_PHPUNIT_RUNNING_CONSTANT_NAME = 'ITOP_PHPUNIT_RUNNING'; - public const TEST_LOG_DIR = 'test'; protected function setUp(): void { - if (false === defined(static::ITOP_PHPUNIT_RUNNING_CONSTANT_NAME)) { - // setUp might be called multiple times, so protecting the define() call ! - define(static::ITOP_PHPUNIT_RUNNING_CONSTANT_NAME, true); - } - $sAppRootRelPath = 'approot.inc.php'; $sDepthSeparator = '../'; for ($iDepth = 0; $iDepth < 8; $iDepth++) { @@ -56,6 +46,11 @@ class ItopTestCase extends TestCase { $sAppRootRelPath = $sDepthSeparator.$sAppRootRelPath; } + + if (false === defined(ITOP_PHPUNIT_RUNNING_CONSTANT_NAME)) { + // setUp might be called multiple times, so protecting the define() call ! + define(ITOP_PHPUNIT_RUNNING_CONSTANT_NAME, true); + } } /**