From c80dbf9bb4f637c76ee5948c352918a571f2cbc8 Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Thu, 28 May 2026 11:42:59 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B09169=20-=20Adapt=20ITSM=20designer=20con?= =?UTF-8?q?nector=20to=20the=20new=20setup=20(FIX=20some=20unit=20tests)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/exceptions/CoreException.php | 3 ++- setup/runtimeenv.class.inc.php | 16 +++++++++--- .../sequencers/DataAuditSequencerTest.php | 26 ++++++++++++------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/application/exceptions/CoreException.php b/application/exceptions/CoreException.php index 09998d069d..eba5616f3a 100644 --- a/application/exceptions/CoreException.php +++ b/application/exceptions/CoreException.php @@ -14,6 +14,8 @@ class CoreException extends Exception /** * CoreException constructor. * + * ATTENTION: Logging here will break the CI + * * @param string $sIssue error message * @param array|null $aContextData key/value array, value MUST implements _toString * @param string $sImpact @@ -56,7 +58,6 @@ class CoreException extends Exception $sMessage .= implode(', ', $aContextItems); } parent::__construct($sMessage, 0, $oPrevious); - //IssueLog::Exception($sIssue, $this, null, $aContextData ?? []); } /** diff --git a/setup/runtimeenv.class.inc.php b/setup/runtimeenv.class.inc.php index 629575f62c..ec28de9b56 100644 --- a/setup/runtimeenv.class.inc.php +++ b/setup/runtimeenv.class.inc.php @@ -1166,6 +1166,7 @@ class RunTimeEnvironment 'ExceptionClass' => get_class($e), 'ExceptionMessage' => $e->getMessage(), ]; + IssueLog::Exception($sErrorMessage, $e, null, $aExceptionContextData); throw new CoreException($sErrorMessage, $aExceptionContextData, '', $e); } } @@ -1448,12 +1449,18 @@ class RunTimeEnvironment } if (!is_dir($sSourcePath)) { - throw new CoreException("Failed to find the source directory '$sSourcePath', please check the rights of the web server"); + $sErrorMessage = "Failed to find the source directory '$sSourcePath', please check the rights of the web server"; + $e = new CoreException($sErrorMessage); + IssueLog::Exception($sErrorMessage, $e); + throw $e; } if (!is_dir($sBuildPath)) { if (!mkdir($sBuildPath)) { - throw new CoreException("Failed to create directory '$sBuildPath', please check the rights of the web server"); + $sErrorMessage = "Failed to create directory '$sBuildPath', please check the rights of the web server"; + $e = new CoreException($sErrorMessage); + IssueLog::Exception($sErrorMessage, $e); + throw $e; } else { // adjust the rights if and only if the directory was just created // owner:rwx user/group:rx @@ -1472,7 +1479,10 @@ class RunTimeEnvironment foreach ($oExtensionsMap->GetAllExtensions() as $oExtension) { if (empty($oExtension->sCode)) { $sExtensionLabel = !empty($oExtension->sLabel) ? $oExtension->sLabel : $oExtension->sSourceDir; - throw new CoreException(sprintf('Extension "%s" cannot be installed: Missing extension code', $sExtensionLabel)); + $sErrorMessage = sprintf('Extension "%s" cannot be installed: Missing extension code', $sExtensionLabel); + $e = new CoreException($sErrorMessage); + IssueLog::Exception($sErrorMessage, $e); + throw $e; } } diff --git a/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php b/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php index 9286f8ef98..758d05aff8 100644 --- a/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php @@ -37,7 +37,7 @@ class DataAuditSequencerTest extends ItopTestCase 'next-step' => 'copy', 'next-step-label' => 'Copying data model files', 'prev-step-success-message' => '', - 'percentage-completed' => 5, + 'percentage-completed' => 25, ]; $this->assertEquals($aExpected, $aRes); } @@ -70,11 +70,11 @@ class DataAuditSequencerTest extends ItopTestCase $aRes = $oSequencer->ExecuteStep('copy'); $aExpected = [ 'status' => 1, - 'message' => 'Copying...', + 'message' => '', 'next-step' => 'compile', 'next-step-label' => 'Compiling the data model', 'prev-step-success-message' => 'Data model files copied', - 'percentage-completed' => 20, + 'percentage-completed' => 50, ]; $this->assertEquals($aExpected, $aRes); } @@ -101,7 +101,7 @@ class DataAuditSequencerTest extends ItopTestCase 'next-step' => 'setup-audit', 'next-step-label' => 'Checking data consistency with the new data model', 'prev-step-success-message' => 'Data model compilation completed', - 'percentage-completed' => 70, + 'percentage-completed' => 50, ]; $this->assertEquals($aExpected, $aRes); } @@ -126,7 +126,7 @@ class DataAuditSequencerTest extends ItopTestCase 'next-step' => 'complete', 'next-step-label' => 'Check Completed', 'prev-step-success-message' => 'Data model compilation completed', - 'percentage-completed' => 100, + 'percentage-completed' => 75, ]; $this->assertEquals($aExpected, $aRes); } @@ -144,7 +144,7 @@ class DataAuditSequencerTest extends ItopTestCase 'next-step' => 'complete', 'next-step-label' => 'Check Completed', 'prev-step-success-message' => 'Data model compilation completed', - 'percentage-completed' => 100, + 'percentage-completed' => 75, ]; $this->assertEquals($aExpected, $aRes); } @@ -171,7 +171,7 @@ class DataAuditSequencerTest extends ItopTestCase 'next-step' => 'complete', 'next-step-label' => 'Check Completed', 'prev-step-success-message' => 'Data model compilation completed', - 'percentage-completed' => 100, + 'percentage-completed' => 66, ]; $this->assertEquals($aExpected, $aRes); } @@ -218,7 +218,7 @@ class DataAuditSequencerTest extends ItopTestCase 'next-step' => 'complete', 'next-step-label' => 'Check Completed', 'prev-step-success-message' => 'Data consistency check completed', - 'percentage-completed' => 100, + 'percentage-completed' => 75, ]; $this->assertEquals($aExpected, $aRes); } @@ -255,8 +255,11 @@ class DataAuditSequencerTest extends ItopTestCase $oRunTimeEnvironment->expects($this->never())->method('GetFinalEnv') ->willReturn('gabuzomeu'); $oRunTimeEnvironment->expects($this->never())->method('DataToCleanupAudit'); - - $oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment); + $aAdditionalParams = [ + 'mode' => 'update', + 'optional_steps' => ['setup-audit' => true ], + ]; + $oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment); $aRes = $oSequencer->ExecuteStep('setup-audit'); $aExpected = [ @@ -275,6 +278,9 @@ class DataAuditSequencerTest extends ItopTestCase $oParams = new PHPParameters(); $aParams = array_merge([ 'mode' => 'install', + 'optional_steps' => [ + 'copy' => true, + ], 'database' => [ 'server' => 'server', 'user' => 'user',