diff --git a/setup/sequencers/ApplicationInstallSequencer.php b/setup/sequencers/ApplicationInstallSequencer.php index fb271d392c..dd867a7d98 100644 --- a/setup/sequencers/ApplicationInstallSequencer.php +++ b/setup/sequencers/ApplicationInstallSequencer.php @@ -84,7 +84,7 @@ class ApplicationInstallSequencer extends StepSequencer $sDestination = $aBackupOptions['destination']; $sSourceConfigFile = $aBackupOptions['configuration_file']; $sMySQLBinDir = $this->oParams->Get('mysql_bindir', null); - $this->oRunTimeEnvironment->Backup($this->oConfig, $sDestination, $sSourceConfigFile, $sMySQLBinDir); + $this->oRunTimeEnvironment->Backup($this->GetConfig(), $sDestination, $sSourceConfigFile, $sMySQLBinDir); } return $this->ComputeNextStep($sStep); @@ -176,8 +176,6 @@ class ApplicationInstallSequencer extends StepSequencer $this->oRunTimeEnvironment->UpdateDBSchema($oConfig, $sMode, $aSelectedModules); - $oConfig->Set('access_mode', ACCESS_FULL); - $this->oRunTimeEnvironment->SetDbUUID(); SetupLog::Info("Database Schema Successfully Updated for environment '$sTargetEnvironment'."); diff --git a/setup/sequencers/StepSequencer.php b/setup/sequencers/StepSequencer.php index eef3431a3d..e80d986f12 100644 --- a/setup/sequencers/StepSequencer.php +++ b/setup/sequencers/StepSequencer.php @@ -25,7 +25,7 @@ abstract class StepSequencer public const INFO = 4; protected array $aStepsHistory = []; protected Parameters $oParams; - protected Config $oConfig; + protected ?Config $oTestConfig = null; protected RunTimeEnvironment $oRunTimeEnvironment; protected string $sSourceDesc; @@ -46,11 +46,7 @@ abstract class StepSequencer } $this->oParams = $oParams; - - $aParamValues = $oParams->GetParamForConfigArray(); - $this->oConfig = new Config(); - $this->oConfig->UpdateFromParams($aParamValues); - utils::SetConfig($this->oConfig); + utils::SetConfig($this->GetConfig()); $this->sSourceDesc = $sSourceDesc; } @@ -165,24 +161,30 @@ abstract class StepSequencer protected function GetConfig() { + if (! is_null($this->oTestConfig)) { + return $this->oTestConfig; + } + // Caching config here is a bad idea, the first config loaded does not contain module settings $sTargetEnvironment = $this->oRunTimeEnvironment->GetBuildEnv(); $sConfigFile = APPCONF.$sTargetEnvironment.'/'.ITOP_CONFIG_FILE; try { if (file_exists($sConfigFile)) { - $this->oConfig = new Config($sConfigFile); + $oConfig = new Config($sConfigFile); } else { - $this->oConfig = new Config(); + $oConfig = new Config(); } + + $oConfig->Set('access_mode', ACCESS_FULL); } catch (Exception $e) { SetupLog::Exception("Setup error", $e); throw $e; } $aParamValues = $this->oParams->GetParamForConfigArray(); - $this->oConfig->UpdateFromParams($aParamValues); + $oConfig->UpdateFromParams($aParamValues); - return $this->oConfig; + return $oConfig; } /** diff --git a/setup/wizardsteps/AbstractWizStepInstall.php b/setup/wizardsteps/AbstractWizStepInstall.php index 575a5894c1..f6fb5918ab 100644 --- a/setup/wizardsteps/AbstractWizStepInstall.php +++ b/setup/wizardsteps/AbstractWizStepInstall.php @@ -53,7 +53,6 @@ abstract class AbstractWizStepInstall extends WizardStep } $sSourceDir = $this->oWizard->GetParameter('source_dir'); - $aCopies = []; if (($sMode == 'upgrade') && ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous')) { $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir'); //$aCopies[] = ['source' => $sSourceDir, 'destination' => 'modules']; // Source is an absolute path, destination is relative to APPROOT diff --git a/tests/php-unit-tests/unitary-tests/setup/sequencers/ApplicationInstallerSequencerTest.php b/tests/php-unit-tests/unitary-tests/setup/sequencers/ApplicationInstallerSequencerTest.php index 56794df946..654f6a0bc6 100644 --- a/tests/php-unit-tests/unitary-tests/setup/sequencers/ApplicationInstallerSequencerTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/sequencers/ApplicationInstallerSequencerTest.php @@ -11,6 +11,7 @@ use RunTimeEnvironment; class ApplicationInstallerSequencerTest extends ItopTestCase { private \RunTimeEnvironment&\PHPUnit\Framework\MockObject\MockObject $oRunTimeEnvironment; + private \Config&\PHPUnit\Framework\MockObject\MockObject $oConfig; private ApplicationInstallSequencer $oSequencer; protected function setUp(): void @@ -24,9 +25,6 @@ class ApplicationInstallerSequencerTest extends ItopTestCase $this->RequireOnceItopFile('/setup/parameters.class.inc.php'); $this->RequireOnceItopFile('/setup/setuputils.class.inc.php'); $this->RequireOnceItopFile('/setup/runtimeenv.class.inc.php'); - - // Copy conf to production-test - \SetupUtils::copydir(APPROOT.'conf/production', APPROOT.'conf/production-test'); } public static function FirstStepProvider() @@ -141,7 +139,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase ]; $this->GivenApplicationInstallSequencer($aAdditionalParams); - $this->oRunTimeEnvironment->expects($this->once())->method('Backup'); + $this->oRunTimeEnvironment->expects($this->once())->method('Backup') + ->with($this->oConfig, '/my_backup_file_path', '/my_config_file_path', null); $aRes = $this->oSequencer->ExecuteStep('backup'); $aExpected = [ @@ -163,7 +162,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase ]; $this->GivenApplicationInstallSequencer($aAdditionalParams); - $this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataBeforeUpdateStructure'); + $this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataBeforeUpdateStructure') + ->with('install', $this->oConfig); $aRes = $this->oSequencer->ExecuteStep('migrate-before'); $aExpected = [ @@ -207,7 +207,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase ]; $this->GivenApplicationInstallSequencer($aAdditionalParams); - $this->oRunTimeEnvironment->expects($this->once())->method('UpdateDBSchema'); + $this->oRunTimeEnvironment->expects($this->once())->method('UpdateDBSchema') + ->with($this->oConfig, 'install', ["a" => "b"]); $this->oRunTimeEnvironment->expects($this->once())->method('SetDbUUID') ->with(); @@ -231,7 +232,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase ]; $this->GivenApplicationInstallSequencer($aAdditionalParams); - $this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataAfterUpdateStructure'); + $this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataAfterUpdateStructure') + ->with('install', $this->oConfig); $aRes = $this->oSequencer->ExecuteStep('migrate-after'); $aExpected = [ @@ -257,7 +259,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase ]; $this->GivenApplicationInstallSequencer($aAdditionalParams); - $this->oRunTimeEnvironment->expects($this->once())->method('AfterDBCreate'); + $this->oRunTimeEnvironment->expects($this->once())->method('AfterDBCreate') + ->with($this->oConfig, 'install', ["a" => "b"], $aAdminParams); $aRes = $this->oSequencer->ExecuteStep('after-db-create'); $aExpected = [ @@ -278,7 +281,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase ]; $this->GivenApplicationInstallSequencer($aAdditionalParams); - $this->oRunTimeEnvironment->expects($this->once())->method('DoLoadData'); + $this->oRunTimeEnvironment->expects($this->once())->method('DoLoadData') + ->with($this->oConfig, true, ["a" => "b"]); $aRes = $this->oSequencer->ExecuteStep('load-data'); $aExpected = [ @@ -300,7 +304,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase 'sample_data' => 1, ]; $this->GivenApplicationInstallSequencer($aAdditionalParams); - $this->oRunTimeEnvironment->expects($this->once())->method('DoCreateConfig'); + $this->oRunTimeEnvironment->expects($this->once())->method('DoCreateConfig') + ->with($this->oConfig, "6.6.6", ["a" => "b"], ["c" => "d"], null); $aRes = $this->oSequencer->ExecuteStep('create-config'); $aExpected = [ @@ -333,7 +338,7 @@ class ApplicationInstallerSequencerTest extends ItopTestCase public function testAnyFailure() { $this->GivenApplicationInstallSequencer(); - $this->oRunTimeEnvironment->expects($this->once())->method('UpdateDBSchema') + $this->oRunTimeEnvironment->expects($this->once())->method('GetBuildEnv') ->willThrowException(new \CoreException('SHADOK MSG')); $aRes = $this->oSequencer->ExecuteStep('db-schema'); @@ -483,14 +488,21 @@ class ApplicationInstallerSequencerTest extends ItopTestCase { $this->oRunTimeEnvironment = $this->createMock(RunTimeEnvironment::class); if (! $bStepComputationOnly) { - $this->oRunTimeEnvironment->expects($this->once())->method('EnterReadOnlyMode'); - $this->oRunTimeEnvironment->expects($this->any())->method('GetBuildEnv')->willReturn('production-test'); + $this->oRunTimeEnvironment->expects($this->once())->method('EnterReadOnlyMode') + ->with($this->oConfig); } } + private function GivenConfig(): void + { + $this->oConfig = $this->createMock(Config::class); + } + private function GivenApplicationInstallSequencer(array $aAdditionalParams = [], bool $bStepComputationOnly = false): void { + $this->GivenConfig(); $this->GivenRunTimeEnvironment($bStepComputationOnly); $this->oSequencer = new ApplicationInstallSequencer($this->GivenParams($aAdditionalParams), $this->oRunTimeEnvironment); + $this->SetNonPublicProperty($this->oSequencer, 'oTestConfig', $this->oConfig); } } 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 ae6e8e2347..950ab793d3 100644 --- a/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php @@ -24,7 +24,8 @@ class DataAuditSequencerTest extends ItopTestCase public function testDataAuditFirstStep() { $oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class); - $oRunTimeEnvironment->expects($this->never())->method($this->anything()); + $oRunTimeEnvironment->expects($this->once())->method('GetBuildEnv') + ->willReturn('production-test'); $oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment); $aRes = $oSequencer->ExecuteStep(); @@ -41,7 +42,8 @@ class DataAuditSequencerTest extends ItopTestCase public function testDataUnknownStep() { $oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class); - $oRunTimeEnvironment->expects($this->never())->method($this->anything()); + $oRunTimeEnvironment->expects($this->once())->method('GetBuildEnv') + ->willReturn('production-test'); $oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment); $aRes = $oSequencer->ExecuteStep('gabuzomeu');