N°9144 - tests and fixes

This commit is contained in:
odain
2026-04-08 12:00:49 +02:00
parent b3a640564b
commit 83ff3b1629
8 changed files with 606 additions and 95 deletions

View File

@@ -462,14 +462,6 @@ class iTopExtensionsMap
}
}
public function MarkAsUninstallable($sExtensionCode, $bMark = true)
{
$oExtension = $this->GetFromExtensionCode($sExtensionCode);
if (!is_null($oExtension)) {
$oExtension->bUninstallable = $bMark;
}
}
/**
* Tells if a given extension(code) is marked as chosen
* @param string $sExtensionCode

View File

@@ -648,6 +648,15 @@ class RunTimeEnvironment
}
}
public function SetDbUUID() : void {
// Set a DBProperty with a unique ID to identify this instance of iTop
$sUUID = DBProperty::GetProperty('database_uuid', '');
if ($sUUID === '') {
$sUUID = utils::CreateUUID('database');
DBProperty::SetProperty('database_uuid', $sUUID, 'Installation/upgrade of '.ITOP_APPLICATION, 'Unique ID of this '.ITOP_APPLICATION.' Database');
}
}
/**
* @param \Config $oConfig
* @param array|null $aSelectedModules null means all
@@ -1530,6 +1539,32 @@ class RunTimeEnvironment
$oBackup->CreateCompressedBackup($sTargetFile, $sSourceConfigFile);
}
public function EnterReadOnlyMode(Config $oConfig)
{
if ($this->GetFinalEnv() != 'production') {
return;
}
if (SetupUtils::IsInReadOnlyMode()) {
return;
}
SetupUtils::EnterReadOnlyMode($oConfig);
}
public function ExitReadOnlyMode()
{
if ($this->GetFinalEnv() != 'production') {
return;
}
if (!SetupUtils::IsInReadOnlyMode()) {
return;
}
SetupUtils::ExitReadOnlyMode();
}
public function GetFinalEnv(): string
{
return $this->sFinalEnv;

View File

@@ -40,33 +40,45 @@ require_once(APPROOT.'setup/SetupDBBackup.php');
*/
class ApplicationInstallSequencer extends StepSequencer
{
protected const LABELS = [
'log-parameters' => 'Log parameters',
'backup' => 'Performing a backup of the database',
'migrate-before' => 'Migrate data before database upgrade',
'db-schema' => 'Updating database schema',
'migrate-after' => 'Migrate data after database upgrade',
'after-db-create' => 'Load data after database create',
'load-data' => 'Loading data',
'create-config' => 'Creating the configuration File',
'commit' => 'Finalize',
];
/**
* @inherit
*/
public function ExecuteStep($sStep = '', $sInstallComment = null): array
{
try {
$fStart = microtime(true);
/**
* @since 3.2.0 move the ContextTag init at the very beginning of the method
* @noinspection PhpUnusedLocalVariableInspection
*/
$oContextTag = new ContextTag(ContextTag::TAG_SETUP);
$fStart = microtime(true);
SetupLog::Info("##### STEP {$sStep} start");
$this->EnterReadOnlyMode();
$this->oRunTimeEnvironment->EnterReadOnlyMode($this->GetConfig());
switch ($sStep) {
case '':
return $this->GetNextStep('log-parameters', 'Log parameters', 0);
return $this->ComputeNextStep($sStep);
case 'log-parameters':
if (array_key_exists('log-parameters', $this->oParams->Get('optional_steps', []))) {
if (array_key_exists($sStep, $this->oParams->Get('optional_steps', []))) {
$this->DoLogParameters();
}
return $this->GetNextStep('backup', 'Performing a backup of the database', 20);
return $this->ComputeNextStep($sStep);
case 'backup':
if (array_key_exists('backup', $this->oParams->Get('optional_steps', []))) {
if (array_key_exists($sStep, $this->oParams->Get('optional_steps', []))) {
$aBackupOptions = $this->oParams->Get('optional_steps')['backup'];
// __DB__-%Y-%m-%d
$sDestination = $aBackupOptions['destination'];
@@ -75,25 +87,24 @@ class ApplicationInstallSequencer extends StepSequencer
$this->oRunTimeEnvironment->Backup($this->oConfig, $sDestination, $sSourceConfigFile, $sMySQLBinDir);
}
return $this->GetNextStep('migrate-before', 'Migrate data before database upgrade', 30);
return $this->ComputeNextStep($sStep);
case 'migrate-before':
if (array_key_exists('migrate-before', $this->oParams->Get('optional_steps', []))) {
if (array_key_exists($sStep, $this->oParams->Get('optional_steps', []))) {
$this->oRunTimeEnvironment->MigrateDataBeforeUpdateStructure($this->oParams->Get('mode'), $this->GetConfig());
}
return $this->GetNextStep('db-schema', 'Updating database schema', 40);
return $this->ComputeNextStep($sStep);
case 'db-schema':
$aSelectedModules = $this->oParams->Get('selected_modules', []);
$this->DoUpdateDBSchema($this->GetConfig(), $aSelectedModules);
return $this->GetNextStep('migrate-after', 'Migrate data after database upgrade', 50);
return $this->ComputeNextStep($sStep);
case 'migrate-after':
if (array_key_exists('migrate-after', $this->oParams->Get('optional_steps', []))) {
if (array_key_exists($sStep, $this->oParams->Get('optional_steps', []))) {
$this->oRunTimeEnvironment->MigrateDataAfterUpdateStructure($this->oParams->Get('mode'), $this->GetConfig());
}
return $this->GetNextStep('after-db-create', 'Load data after database create', 60);
return $this->ComputeNextStep($sStep);
case 'after-db-create':
$aAdminParams = $this->oParams->Get('admin_account');
@@ -101,8 +112,7 @@ class ApplicationInstallSequencer extends StepSequencer
$sMode = $this->oParams->Get('mode');
$this->oRunTimeEnvironment->AfterDBCreate($this->GetConfig(), $sMode, $aSelectedModules, $aAdminParams);
return $this->GetNextStep('load-data', 'Loading data', 70);
return $this->ComputeNextStep($sStep);
case 'load-data':
$aSelectedModules = $this->oParams->Get('selected_modules', []);
@@ -110,7 +120,7 @@ class ApplicationInstallSequencer extends StepSequencer
$this->oRunTimeEnvironment->DoLoadData($this->GetConfig(), $bSampleData, $aSelectedModules);
return $this->GetNextStep('create-config', 'Creating the configuration File', 80, 'All data loaded');
return $this->ComputeNextStep($sStep, 'All data loaded');
case 'create-config':
$sDataModelVersion = $this->oParams->Get('datamodel_version', '0.0.0');
@@ -124,8 +134,8 @@ class ApplicationInstallSequencer extends StepSequencer
$aSelectedExtensionCodes,
$sInstallComment
);
return $this->GetNextStep('commit', 'Finalize', 95);
$this->oRunTimeEnvironment->ExitReadOnlyMode();
return $this->ComputeNextStep($sStep);
case 'commit':
$this->oRunTimeEnvironment->Commit();
@@ -140,37 +150,9 @@ class ApplicationInstallSequencer extends StepSequencer
$aResult['error_code'] = $e->getCode();
return $aResult;
} finally {
$this->ExitReadOnlyMode();
$fDuration = round(microtime(true) - $fStart, 2);
SetupLog::Info("##### STEP {$sStep} duration: {$fDuration}s");
}
}
protected function EnterReadOnlyMode()
{
if ($this->oRunTimeEnvironment->GetFinalEnv() != 'production') {
return;
}
if (SetupUtils::IsInReadOnlyMode()) {
return;
}
SetupUtils::EnterReadOnlyMode($this->GetConfig());
}
protected function ExitReadOnlyMode()
{
if ($this->oRunTimeEnvironment->GetFinalEnv() != 'production') {
return;
}
if (!SetupUtils::IsInReadOnlyMode()) {
return;
}
SetupUtils::ExitReadOnlyMode();
}
/**
@@ -195,13 +177,58 @@ class ApplicationInstallSequencer extends StepSequencer
$oConfig->Set('access_mode', ACCESS_FULL);
// Set a DBProperty with a unique ID to identify this instance of iTop
$sUUID = DBProperty::GetProperty('database_uuid', '');
if ($sUUID === '') {
$sUUID = utils::CreateUUID('database');
DBProperty::SetProperty('database_uuid', $sUUID, 'Installation/upgrade of '.ITOP_APPLICATION, 'Unique ID of this '.ITOP_APPLICATION.' Database');
}
$this->oRunTimeEnvironment->SetDbUUID();
SetupLog::Info("Database Schema Successfully Updated for environment '$sTargetEnvironment'.");
}
public function GetStepNames(): array
{
$aStepNames = [ ''];
foreach (['log-parameters', 'backup', 'migrate-before'] as $sStepName) {
if (array_key_exists($sStepName, $this->oParams->Get('optional_steps', []))) {
$aStepNames [] = $sStepName;
}
}
$aStepNames [] = 'db-schema';
if (array_key_exists('migrate-after', $this->oParams->Get('optional_steps', []))) {
$aStepNames [] = 'migrate-after';
}
$aOthers = [
'after-db-create',
'load-data',
'create-config',
'commit',
];
$aStepNames = array_merge($aStepNames, $aOthers);
return $aStepNames;
}
public function GetStepAfterWithPercent($sCurrentStep): array
{
$aAllStepNames = $this->GetStepNames();
$iKey = array_search($sCurrentStep, $aAllStepNames);
$iNextStepIndex = $iKey + 1;
$sNextStep = $aAllStepNames[$iNextStepIndex] ?? '';
return [$sNextStep, $this->ComputePercent($aAllStepNames, $iNextStepIndex)];
}
public function ComputePercent(array $aAllStepNames, $iKey): int
{
$iCount = count($aAllStepNames);
if ($iKey >= $iCount) {
return 100;
}
$iRes = 100 * $iKey / $iCount;
return (int) $iRes;
}
private function ComputeNextStep(string $sCurrentStep, string $sMessage = ''): array
{
[$sNextStep, $iPercent] = $this->GetStepAfterWithPercent($sCurrentStep);
$sLabel = self::LABELS[$sNextStep] ?? '';
return $this->GetNextStep($sNextStep, $sLabel, $iPercent, $sMessage);
}
}

View File

@@ -34,12 +34,13 @@ class DataAuditSequencer extends StepSequencer
public function ExecuteStep($sStep = '', $sInstallComment = null): array
{
try {
$fStart = microtime(true);
/**
* @since 3.2.0 move the ContextTag init at the very beginning of the method
* @noinspection PhpUnusedLocalVariableInspection
*/
$oContextTag = new ContextTag(ContextTag::TAG_SETUP);
$fStart = microtime(true);
SetupLog::Info("##### STEP {$sStep} start");
switch ($sStep) {
case '':
@@ -64,7 +65,11 @@ class DataAuditSequencer extends StepSequencer
$sExtensionDir,
$bUseSymbolicLinks
);
return $this->GetNextStep('setup-audit', 'Checking data consistency with the new data model', 70, $sMessage);
if ($this->IsDataAuditRequired()) {
return $this->GetNextStep('setup-audit', 'Checking data consistency with the new data model', 70, $sMessage);
}
return $this->GetNextStep('', 'Completed', 100);
case 'setup-audit':
if ($this->IsDataAuditRequired()) {

View File

@@ -162,18 +162,23 @@ abstract class StepSequencer
protected function GetConfig()
{
if (! is_null($this->oConfig)) {
return $this->oConfig;
}
$sTargetEnvironment = $this->oRunTimeEnvironment->GetBuildEnv();
$sConfigFile = APPCONF.$sTargetEnvironment.'/'.ITOP_CONFIG_FILE;
try {
$oConfig = new Config($sConfigFile);
$this->oConfig = new Config($sConfigFile);
} catch (Exception $e) {
return null;
SetupLog::Exception("Setup error", $e);
throw $e;
}
$aParamValues = $this->oParams->GetParamForConfigArray();
$oConfig->UpdateFromParams($aParamValues);
$this->oConfig->UpdateFromParams($aParamValues);
return $oConfig;
return $this->oConfig;
}
/**

View File

@@ -56,8 +56,8 @@ abstract class AbstractWizStepInstall extends WizardStep
$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
$aCopies[] = ['source' => $sPreviousVersionDir.'/portal', 'destination' => 'portal']; // Source is an absolute path, destination is relative to APPROOT
//$aCopies[] = ['source' => $sSourceDir, 'destination' => 'modules']; // Source is an absolute path, destination is relative to APPROOT
//$aCopies[] = ['source' => $sPreviousVersionDir.'/portal', 'destination' => 'portal']; // Source is an absolute path, destination is relative to APPROOT
$sSourceDir = APPROOT.'modules';
}

View File

@@ -4,11 +4,16 @@ namespace Combodo\iTop\Test\UnitTest\Setup\Sequencers;
use ApplicationInstallSequencer;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Config;
use PHPParameters;
use PHPUnit\Framework\TestCase;
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
{
static::LoadRequiredItopFiles();
@@ -22,34 +27,319 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
$this->RequireOnceItopFile('/setup/runtimeenv.class.inc.php');
}
public function testFirstStep()
public static function FirstStepProvider()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->exactly(2))->method('GetFinalEnv')
->willReturn('production');
$oSequencer = new ApplicationInstallSequencer($this->GivenParams(), $oRunTimeEnvironment);
return [
'next is db-update' => [
'next-step' => 'db-schema',
'next-step-label' => 'Updating database schema',
'percentage-completed' => 16,
'optional_steps' => [],
],
'next is log-parameters' => [
'next-step' => 'log-parameters',
'next-step-label' => 'Log parameters',
'percentage-completed' => 11,
'optional_steps' => [
'log-parameters' => true,
'backup' => true,
'migrate-before' => true,
],
],
'next is backup' => [
'next-step' => 'backup',
'next-step-label' => 'Performing a backup of the database',
'percentage-completed' => 12,
'optional_steps' => [
'backup' => true,
'migrate-before' => true,
],
],
'next is migrate-before' => [
'next-step' => 'migrate-before',
'next-step-label' => 'Migrate data before database upgrade',
'percentage-completed' => 14,
'optional_steps' => [
'migrate-before' => true,
],
],
];
}
$aRes = $oSequencer->ExecuteStep();
/**
* @dataProvider FirstStepProvider
*/
public function testFirstStep($sNextStep, $sNextLabel, $iPercent, $aOptionalSteps)
{
$aAdditionalParams = [
'optional_steps' => $aOptionalSteps,
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$aRes = $this->oSequencer->ExecuteStep();
$aExpected = [
'status' => 1,
'message' => '',
'next-step' => 'log-parameters',
'next-step-label' => 'Log parameters',
'percentage-completed' => 0,
'next-step' => $sNextStep,
'next-step-label' => $sNextLabel,
'percentage-completed' => $iPercent,
];
$this->assertEquals($aExpected, $aRes);
}
public function testLogStep()
{
$this->GivenApplicationInstallSequencer();
$aRes = $this->oSequencer->ExecuteStep('log-parameters');
$aExpected = [
'status' => 1,
'message' => '',
'next-step' => 'db-schema',
'next-step-label' => 'Updating database schema',
'percentage-completed' => 16,
];
$this->assertEquals($aExpected, $aRes);
}
public static function BackupStepProvider()
{
return [
'next is db-update' => [
'next-step' => 'db-schema',
'next-step-label' => 'Updating database schema',
'percentage-completed' => 28,
'optional_steps' => [
'backup' => true,
],
],
'next is migrate-before' => [
'next-step' => 'migrate-before',
'next-step-label' => 'Migrate data before database upgrade',
'percentage-completed' => 25,
'optional_steps' => [
'backup' => true,
'migrate-before' => true,
],
],
];
}
/**
* @dataProvider BackupStepProvider
*/
public function testBackup($sNextStep, $sNextLabel, $iPercent, $aOptionalSteps)
{
$aAdditionalParams = [
'optional_steps' => $aOptionalSteps,
];
$aAdditionalParams['optional_steps']['backup'] = [
'destination' => '/my_backup_file_path',
'configuration_file' => '/my_config_file_path',
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$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 = [
'status' => 1,
'message' => '',
'next-step' => $sNextStep,
'next-step-label' => $sNextLabel,
'percentage-completed' => $iPercent,
];
$this->assertEquals($aExpected, $aRes);
}
public function testMigrateBefore()
{
$aAdditionalParams = [
'optional_steps' => [
'migrate-before' => true,
],
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataBeforeUpdateStructure')
->with('install', $this->oConfig);
$aRes = $this->oSequencer->ExecuteStep('migrate-before');
$aExpected = [
'status' => 1,
'message' => '',
'next-step' => 'db-schema',
'next-step-label' => 'Updating database schema',
'percentage-completed' => 28,
];
$this->assertEquals($aExpected, $aRes);
}
public static function DbUpdateStepProvider()
{
return [
'next is migrate-after' => [
'next-step' => 'migrate-after',
'next-step-label' => 'Migrate data after database upgrade',
'percentage-completed' => 28,
'optional_steps' => [
'migrate-after' => true,
],
],
'next is after-db-create' => [
'next-step' => 'after-db-create',
'next-step-label' => 'Load data after database create',
'percentage-completed' => 33,
'optional_steps' => [],
],
];
}
/**
* @dataProvider DbUpdateStepProvider
*/
public function testDbUpdate($sNextStep, $sNextLabel, $iPercent, $aOptionalSteps)
{
$aAdditionalParams = [
'selected_modules' => ["a" => "b"],
'optional_steps' => $aOptionalSteps,
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('UpdateDBSchema')
->with($this->oConfig, 'install', ["a" => "b"]);
$this->oRunTimeEnvironment->expects($this->once())->method('SetDbUUID')
->with();
$aRes = $this->oSequencer->ExecuteStep('db-schema');
$aExpected = [
'status' => 1,
'message' => '',
'next-step' => $sNextStep,
'next-step-label' => $sNextLabel,
'percentage-completed' => $iPercent,
];
$this->assertEquals($aExpected, $aRes);
}
public function testMigrateAfter()
{
$aAdditionalParams = [
'optional_steps' => [
'migrate-after' => true,
],
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataAfterUpdateStructure')
->with('install', $this->oConfig);
$aRes = $this->oSequencer->ExecuteStep('migrate-after');
$aExpected = [
'status' => 1,
'message' => '',
'next-step' => 'after-db-create',
'next-step-label' => 'Load data after database create',
'percentage-completed' => 42,
];
$this->assertEquals($aExpected, $aRes);
}
public function testAfterDbCreate()
{
$aAdminParams = [
'user' => "ga",
'pwd' => "zo",
'language' => "meu",
];
$aAdditionalParams = [
'selected_modules' => ["a" => "b"],
'admin_account' => $aAdminParams,
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('AfterDBCreate')
->with($this->oConfig, 'install', ["a" => "b"], $aAdminParams);
$aRes = $this->oSequencer->ExecuteStep('after-db-create');
$aExpected = [
'status' => 1,
'message' => '',
'next-step' => 'load-data',
'next-step-label' => 'Loading data',
'percentage-completed' => 50,
];
$this->assertEquals($aExpected, $aRes);
}
public function testLoadData()
{
$aAdditionalParams = [
'selected_modules' => ["a" => "b"],
'sample_data' => 1,
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('DoLoadData')
->with($this->oConfig, true, ["a" => "b"]);
$aRes = $this->oSequencer->ExecuteStep('load-data');
$aExpected = [
'message' => 'All data loaded',
'next-step' => 'create-config',
'next-step-label' => 'Creating the configuration File',
'percentage-completed' => 66,
'status' => 1,
];
$this->assertEquals($aExpected, $aRes);
}
public function testCreateConfig()
{
$aAdditionalParams = [
'datamodel_version' => "6.6.6",
'selected_extensions' => ["c" => "d"],
'selected_modules' => ["a" => "b"],
'sample_data' => 1,
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('DoCreateConfig')
->with($this->oConfig, "6.6.6", ["a" => "b"], ["c" => "d"], null);
$this->oRunTimeEnvironment->expects($this->once())->method('ExitReadOnlyMode');
$aRes = $this->oSequencer->ExecuteStep('create-config');
$aExpected = [
'message' => '',
'next-step' => 'commit',
'next-step-label' => 'Finalize',
'percentage-completed' => 83,
'status' => 1,
];
$this->assertEquals($aExpected, $aRes);
}
public function testCommit()
{
$this->GivenApplicationInstallSequencer();
$aRes = $this->oSequencer->ExecuteStep('commit');
$aExpected = [
'message' => '',
'next-step' => '',
'next-step-label' => 'Completed',
'percentage-completed' => 100,
'status' => 1,
];
$this->assertEquals($aExpected, $aRes);
}
public function testAnyFailure()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->exactly(2))->method('GetFinalEnv')
->willReturn('production');
$oRunTimeEnvironment->expects($this->once())->method('GetBuildEnv')
$this->GivenApplicationInstallSequencer();
$this->oRunTimeEnvironment->expects($this->once())->method('GetBuildEnv')
->willThrowException(new \CoreException('SHADOK MSG'));
$oSequencer = new ApplicationInstallSequencer($this->GivenParams(), $oRunTimeEnvironment);
$aRes = $oSequencer->ExecuteStep('db-schema');
$aRes = $this->oSequencer->ExecuteStep('db-schema');
$aExpected = [
'status' => 2,
'message' => 'SHADOK MSG',
@@ -63,12 +353,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
public function testUnknownStep()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->exactly(2))->method('GetFinalEnv')
->willReturn('production');
$oSequencer = new ApplicationInstallSequencer($this->GivenParams(), $oRunTimeEnvironment);
$aRes = $oSequencer->ExecuteStep('gabuzomeu');
$this->GivenApplicationInstallSequencer();
$aRes = $this->oSequencer->ExecuteStep('gabuzomeu');
$aExpected = [
'status' => 2,
'message' => '',
@@ -82,7 +368,7 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
private function GivenParams(array $aAdditionalParams = []): PHPParameters
{
$oParams = new PHPParameters();
$aParams = array_merge([
$aParams = array_merge_recursive([
'mode' => 'install',
'database' => [
'server' => 'server',
@@ -102,4 +388,119 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
$oParams->LoadFromHash($aParams);
return $oParams;
}
public function testGetStepNamesWithAllSteps()
{
$aAdditionalParams = [
'optional_steps' => [
'log-parameters' => true,
'backup' => true,
'migrate-before' => true,
'migrate-after' => true,
],
];
$this->GivenApplicationInstallSequencer($aAdditionalParams, true);
$expected = [
'',
'log-parameters',
'backup',
'migrate-before',
'db-schema',
'migrate-after',
'after-db-create',
'load-data',
'create-config',
'commit',
];
$this->assertEquals($expected, $this->oSequencer->GetStepNames());
}
public static function WithoutOneStepProvider()
{
return [
['log-parameters'],
['backup'],
['migrate-before'],
['migrate-after'],
];
}
/**
* @dataProvider WithoutOneStepProvider
*/
public function testAllWithoutOneStep($sMissingStepName)
{
$aAdditionalParams = [
'optional_steps' => [
'log-parameters' => true,
'backup' => true,
'migrate-before' => true,
'migrate-after' => true,
],
];
unset($aAdditionalParams['optional_steps'][$sMissingStepName]);
$this->GivenApplicationInstallSequencer($aAdditionalParams, true);
$expected = [
'' => true,
'log-parameters' => true,
'backup' => true,
'migrate-before' => true,
'db-schema' => true,
'migrate-after' => true,
'after-db-create' => true,
'load-data' => true,
'create-config' => true,
'commit' => true,
];
unset($expected[$sMissingStepName]);
$this->assertEquals(array_keys($expected), $this->oSequencer->GetStepNames());
}
public function testGetStepNamesWithOnlyMandatorySteps()
{
$this->GivenApplicationInstallSequencer([], true);
$expected = [
'',
'db-schema',
'after-db-create',
'load-data',
'create-config',
'commit',
];
$this->assertEquals($expected, $this->oSequencer->GetStepNames());
}
public function testGetStepAfterWithPercent()
{
$this->GivenApplicationInstallSequencer([], true);
$this->assertEquals(['db-schema', 16], $this->oSequencer->GetStepAfterWithPercent(''));
$this->assertEquals(['after-db-create', 33], $this->oSequencer->GetStepAfterWithPercent('db-schema'));
$this->assertEquals(['load-data', 50], $this->oSequencer->GetStepAfterWithPercent('after-db-create'));
$this->assertEquals(['create-config', 66], $this->oSequencer->GetStepAfterWithPercent('load-data'));
$this->assertEquals(['commit', 83], $this->oSequencer->GetStepAfterWithPercent('create-config'));
$this->assertEquals(['', 100], $this->oSequencer->GetStepAfterWithPercent('commit'));
}
private function GivenRunTimeEnvironment(bool $bStepComputationOnly = false): void
{
$this->oRunTimeEnvironment = $this->createMock(RunTimeEnvironment::class);
if (! $bStepComputationOnly) {
$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, 'oConfig', $this->oConfig);
}
}

View File

@@ -73,11 +73,17 @@ class DataAuditSequencerTest extends ItopTestCase
$this->assertEquals($aExpected, $aRes);
}
public function testCompile()
public function testCompileWithAudit()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->once())->method('DoCompile');
$oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment);
$oRunTimeEnvironment->expects($this->once())->method('GetFinalEnv')
->willReturn('production');
$aAdditionalParams = [
'mode' => 'update',
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
$aRes = $oSequencer->ExecuteStep('compile');
$aExpected = [
@@ -90,7 +96,47 @@ class DataAuditSequencerTest extends ItopTestCase
$this->assertEquals($aExpected, $aRes);
}
public function testCompileFailure()
public function testCompileNoAuditInFreshInstall()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->once())->method('DoCompile');
$oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment);
$aRes = $oSequencer->ExecuteStep('compile');
$aExpected = [
'status' => 1,
'message' => '',
'next-step' => '',
'next-step-label' => 'Completed',
'percentage-completed' => 100,
];
$this->assertEquals($aExpected, $aRes);
}
public function testCompileNoAuditInUpgradeWithoutAnyRuntimeEnv()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->once())->method('DoCompile');
$oRunTimeEnvironment->expects($this->once())->method('GetFinalEnv')
->willReturn('gabuzomeu');
$aAdditionalParams = [
'mode' => 'update',
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
$aRes = $oSequencer->ExecuteStep('compile');
$aExpected = [
'status' => 1,
'message' => '',
'next-step' => '',
'next-step-label' => 'Completed',
'percentage-completed' => 100,
];
$this->assertEquals($aExpected, $aRes);
}
public function testCompileFailureInFreshInstallNoAudit()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->once())->method('DoCompile')