mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 23:08:46 +02:00
N°9144 - setup wizard sequencers test coverage + fixes
N°9144 - ci: fix hub setup test N°9144 - code style N°9144 - tests and fixes N°9144 - ci: fix tests and code style
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ApplicationInstallSequencerFake extends ApplicationInstallSequencer
|
||||
{
|
||||
public function __construct(Parameters $oParams)
|
||||
{
|
||||
$this->oParams = $oParams;
|
||||
}
|
||||
|
||||
protected function DoLogParameters($sPrefix = 'install-', $sOperation = '')
|
||||
{
|
||||
|
||||
}
|
||||
protected function DoCopy($aCopies)
|
||||
{
|
||||
|
||||
}
|
||||
protected function DoBackup($sBackupFileFormat, $sSourceConfigFile, $sMySQLBinDir = null)
|
||||
{
|
||||
|
||||
}
|
||||
protected function DoCompile($aRemovedExtensionCodes, $aSelectedModules, $sSourceDir, $sExtensionDir, $bUseSymbolicLinks = null, $bEnterMaintenanceMode = true)
|
||||
{
|
||||
|
||||
}
|
||||
protected function DoUpdateDBSchema($aSelectedModules)
|
||||
{
|
||||
|
||||
}
|
||||
protected function AfterDBCreate(
|
||||
$aAdminParams,
|
||||
$aSelectedModules
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
protected function DoLoadFiles(
|
||||
$aSelectedModules,
|
||||
$bSampleData = false
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
protected function DoCreateConfig(
|
||||
$sPreviousConfigFile,
|
||||
$sDataModelVersion,
|
||||
$aSelectedModuleCodes,
|
||||
$aSelectedExtensionCodes,
|
||||
$sInstallComment = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
protected function EnterReadOnlyMode()
|
||||
{
|
||||
}
|
||||
protected function ExitReadOnlyMode()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
class DataAuditSequencerFake extends DataAuditSequencer
|
||||
{
|
||||
public function __construct(Parameters $oParams)
|
||||
{
|
||||
$this->oParams = $oParams;
|
||||
}
|
||||
|
||||
protected function DoCopy($aCopies)
|
||||
{
|
||||
|
||||
}
|
||||
protected function DoBackup($sBackupFileFormat, $sSourceConfigFile, $sMySQLBinDir = null)
|
||||
{
|
||||
|
||||
}
|
||||
protected function DoCompile($aRemovedExtensionCodes, $aSelectedModules, $sSourceDir, $sExtensionDir, $bUseSymbolicLinks = null, $bEnterMaintenanceMode = true)
|
||||
{
|
||||
|
||||
}
|
||||
protected function DoUpdateDBSchema($aSelectedModules)
|
||||
{
|
||||
|
||||
}
|
||||
protected function AfterDBCreate(
|
||||
$aAdminParams,
|
||||
$aSelectedModules
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
protected function DoLoadFiles(
|
||||
$aSelectedModules,
|
||||
$bSampleData = false
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
protected function DoCreateConfig(
|
||||
$sPreviousConfigFile,
|
||||
$sDataModelVersion,
|
||||
$aSelectedModuleCodes,
|
||||
$aSelectedExtensionCodes,
|
||||
$sInstallComment = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
protected function DoSetupAudit()
|
||||
{
|
||||
|
||||
}
|
||||
protected function DoCleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function EnterReadOnlyMode()
|
||||
{
|
||||
}
|
||||
protected function ExitReadOnlyMode()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup;
|
||||
|
||||
use ApplicationInstallSequencerFake;
|
||||
use DataAuditSequencerFake;
|
||||
use PHPParameters;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use SetupUtils;
|
||||
|
||||
class StepSequencerTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
static::LoadRequiredItopFiles();
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->RequireOnceItopFile('/setup/sequencers/ApplicationInstallSequencer.php');
|
||||
$this->RequireOnceItopFile('/setup/sequencers/DataAuditSequencer.php');
|
||||
$this->RequireOnceItopFile('/setup/parameters.class.inc.php');
|
||||
$this->RequireOnceItopFile('/setup/setuputils.class.inc.php');
|
||||
require_once __DIR__.'/ApplicationInstallSequencerFake.php';
|
||||
require_once __DIR__.'/DataAuditSequencerFake.php';
|
||||
}
|
||||
|
||||
public function testApplicationInstallSequencer()
|
||||
{
|
||||
$oParams = new PHPParameters();
|
||||
$oParams->LoadFromHash([]);
|
||||
|
||||
$oInstallSequencer = new ApplicationInstallSequencerFake($oParams);
|
||||
$oInstallSequencer->ExecuteAllSteps();
|
||||
|
||||
$aStepSequence = [
|
||||
'',
|
||||
'copy',
|
||||
'compile',
|
||||
'db-schema',
|
||||
'after-db-create',
|
||||
'load-data',
|
||||
'create-config',
|
||||
];
|
||||
$this->AssertStepsHistoryIs($aStepSequence, $oInstallSequencer);
|
||||
}
|
||||
|
||||
public function testDataAuditSequencer()
|
||||
{
|
||||
$oParams = new PHPParameters();
|
||||
$oParams->LoadFromHash([]);
|
||||
|
||||
$oInstallSequencer = new DataAuditSequencerFake($oParams);
|
||||
$oInstallSequencer->ExecuteAllSteps();
|
||||
|
||||
$aStepSequence = [
|
||||
'',
|
||||
'compile',
|
||||
'write-config',
|
||||
'setup-audit',
|
||||
'cleanup',
|
||||
];
|
||||
$this->AssertStepsHistoryIs($aStepSequence, $oInstallSequencer);
|
||||
}
|
||||
|
||||
protected function AssertStepsHistoryIs($aExpectedStepSequence, $oSequencer)
|
||||
{
|
||||
|
||||
$aHistory = $oSequencer->GetHistory();
|
||||
$aStepSequence = [];
|
||||
foreach ($aHistory as $aStep) {
|
||||
$aStepSequence[] = $aStep['step'];
|
||||
}
|
||||
$this->assertEquals($aExpectedStepSequence, $aStepSequence, 'The step sequence should be '.implode(',', $aExpectedStepSequence));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,508 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup\Sequencers;
|
||||
|
||||
use ApplicationInstallSequencer;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use Config;
|
||||
use PHPParameters;
|
||||
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();
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->RequireOnceItopFile('/setup/sequencers/ApplicationInstallSequencer.php');
|
||||
$this->RequireOnceItopFile('/setup/sequencers/DataAuditSequencer.php');
|
||||
$this->RequireOnceItopFile('/setup/parameters.class.inc.php');
|
||||
$this->RequireOnceItopFile('/setup/setuputils.class.inc.php');
|
||||
$this->RequireOnceItopFile('/setup/runtimeenv.class.inc.php');
|
||||
}
|
||||
|
||||
public static function FirstStepProvider()
|
||||
{
|
||||
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,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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' => $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);
|
||||
|
||||
$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();
|
||||
$this->oRunTimeEnvironment->expects($this->once())->method('Commit');
|
||||
$this->oRunTimeEnvironment->expects($this->once())->method('ExitReadOnlyMode');
|
||||
|
||||
$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()
|
||||
{
|
||||
$this->GivenApplicationInstallSequencer();
|
||||
$this->oRunTimeEnvironment->expects($this->once())->method('GetBuildEnv')
|
||||
->willThrowException(new \CoreException('SHADOK MSG'));
|
||||
|
||||
$aRes = $this->oSequencer->ExecuteStep('db-schema');
|
||||
$aExpected = [
|
||||
'status' => 2,
|
||||
'message' => 'SHADOK MSG',
|
||||
'next-step' => '',
|
||||
'next-step-label' => '',
|
||||
'percentage-completed' => 100,
|
||||
'error_code' => 0,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
public function testUnknownStep()
|
||||
{
|
||||
$this->GivenApplicationInstallSequencer();
|
||||
$aRes = $this->oSequencer->ExecuteStep('gabuzomeu');
|
||||
$aExpected = [
|
||||
'status' => 2,
|
||||
'message' => '',
|
||||
'next-step' => '',
|
||||
'next-step-label' => 'Unknown setup step \'gabuzomeu\'.',
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
private function GivenParams(array $aAdditionalParams = []): PHPParameters
|
||||
{
|
||||
$oParams = new PHPParameters();
|
||||
$aParams = array_merge_recursive([
|
||||
'mode' => 'install',
|
||||
'database' => [
|
||||
'server' => 'server',
|
||||
'user' => 'user',
|
||||
'pwd' => 'pwd',
|
||||
'name' => 'name',
|
||||
'prefix' => 'prefix',
|
||||
'db_tls_enabled' => 'db_tls_enabled',
|
||||
'db_tls_ca' => 'db_tls_ca',
|
||||
],
|
||||
'application_path' => '',
|
||||
'language' => '',
|
||||
'graphviz_path' => '',
|
||||
'source_dir' => '',
|
||||
], $aAdditionalParams);
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup\Sequencers;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use DataAuditSequencer;
|
||||
use PHPParameters;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DataAuditSequencerTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
static::LoadRequiredItopFiles();
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->RequireOnceItopFile('/setup/sequencers/ApplicationInstallSequencer.php');
|
||||
$this->RequireOnceItopFile('/setup/sequencers/DataAuditSequencer.php');
|
||||
$this->RequireOnceItopFile('/setup/parameters.class.inc.php');
|
||||
$this->RequireOnceItopFile('/setup/setuputils.class.inc.php');
|
||||
$this->RequireOnceItopFile('/setup/runtimeenv.class.inc.php');
|
||||
}
|
||||
|
||||
public function testDataAuditFirstStep()
|
||||
{
|
||||
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
|
||||
$oRunTimeEnvironment->expects($this->never())->method($this->anything());
|
||||
$oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment);
|
||||
|
||||
$aRes = $oSequencer->ExecuteStep();
|
||||
$aExpected = [
|
||||
'status' => 1,
|
||||
'message' => '',
|
||||
'next-step' => 'copy',
|
||||
'next-step-label' => 'Copying data model files',
|
||||
'percentage-completed' => 5,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
public function testDataUnknownStep()
|
||||
{
|
||||
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
|
||||
$oRunTimeEnvironment->expects($this->never())->method($this->anything());
|
||||
$oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment);
|
||||
|
||||
$aRes = $oSequencer->ExecuteStep('gabuzomeu');
|
||||
$aExpected = [
|
||||
'status' => 2,
|
||||
'message' => '',
|
||||
'next-step' => '',
|
||||
'next-step-label' => 'Unknown setup step \'gabuzomeu\'.',
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
public function testCopy()
|
||||
{
|
||||
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
|
||||
$oRunTimeEnvironment->expects($this->once())->method('CopySetupFiles');
|
||||
$oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment);
|
||||
|
||||
$aRes = $oSequencer->ExecuteStep('copy');
|
||||
$aExpected = [
|
||||
'status' => 1,
|
||||
'message' => 'Copying...',
|
||||
'next-step' => 'compile',
|
||||
'next-step-label' => 'Compiling the data model',
|
||||
'percentage-completed' => 20,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
public function testCompileWithAudit()
|
||||
{
|
||||
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
|
||||
$oRunTimeEnvironment->expects($this->once())->method('DoCompile');
|
||||
$oRunTimeEnvironment->expects($this->once())->method('GetFinalEnv')
|
||||
->willReturn('production');
|
||||
|
||||
$aAdditionalParams = [
|
||||
'mode' => 'update',
|
||||
];
|
||||
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
|
||||
|
||||
$aRes = $oSequencer->ExecuteStep('compile');
|
||||
$aExpected = [
|
||||
'status' => 1,
|
||||
'message' => 'Using symbolic links instead of copying data model files (for developers only!)',
|
||||
'next-step' => 'setup-audit',
|
||||
'next-step-label' => 'Checking data consistency with the new data model',
|
||||
'percentage-completed' => 70,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
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')
|
||||
->willThrowException(new \CoreException('SHADOK MSG'));
|
||||
$oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment);
|
||||
|
||||
$aRes = $oSequencer->ExecuteStep('compile');
|
||||
$aExpected = [
|
||||
'status' => 2,
|
||||
'message' => 'SHADOK MSG',
|
||||
'next-step' => '',
|
||||
'next-step-label' => '',
|
||||
'percentage-completed' => 100,
|
||||
'error_code' => 0,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
public function testAuditCalled()
|
||||
{
|
||||
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
|
||||
$oRunTimeEnvironment->expects($this->once())->method('DataToCleanupAudit');
|
||||
$oRunTimeEnvironment->expects($this->once())->method('GetFinalEnv')
|
||||
->willReturn('production');
|
||||
|
||||
$aAdditionalParams = [
|
||||
'mode' => 'update',
|
||||
];
|
||||
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
|
||||
|
||||
$aRes = $oSequencer->ExecuteStep('setup-audit');
|
||||
$aExpected = [
|
||||
'status' => 1,
|
||||
'message' => '',
|
||||
'next-step' => '',
|
||||
'next-step-label' => 'Completed',
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
public function testNoAuditInUpgradeModeWhenNoRuntimeEnvironmentAvailable()
|
||||
{
|
||||
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
|
||||
$oRunTimeEnvironment->expects($this->never())->method('DataToCleanupAudit');
|
||||
$oRunTimeEnvironment->expects($this->once())->method('GetFinalEnv')
|
||||
->willReturn('gabuzomeu');
|
||||
|
||||
$aAdditionalParams = [
|
||||
'mode' => 'update',
|
||||
];
|
||||
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
|
||||
$aRes = $oSequencer->ExecuteStep('setup-audit');
|
||||
$aExpected = [
|
||||
'status' => 1,
|
||||
'message' => '',
|
||||
'next-step' => '',
|
||||
'next-step-label' => 'Completed',
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
public function testNoAuditInFreshInstallMode()
|
||||
{
|
||||
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
|
||||
$oRunTimeEnvironment->expects($this->never())->method('GetFinalEnv')
|
||||
->willReturn('gabuzomeu');
|
||||
$oRunTimeEnvironment->expects($this->never())->method('DataToCleanupAudit');
|
||||
|
||||
$oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment);
|
||||
|
||||
$aRes = $oSequencer->ExecuteStep('setup-audit');
|
||||
$aExpected = [
|
||||
'status' => 1,
|
||||
'message' => '',
|
||||
'next-step' => '',
|
||||
'next-step-label' => 'Completed',
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
private function GivenParams(array $aAdditionalParams = []): PHPParameters
|
||||
{
|
||||
$oParams = new PHPParameters();
|
||||
$aParams = array_merge([
|
||||
'mode' => 'install',
|
||||
'database' => [
|
||||
'server' => 'server',
|
||||
'user' => 'user',
|
||||
'pwd' => 'pwd',
|
||||
'name' => 'name',
|
||||
'prefix' => 'prefix',
|
||||
'db_tls_enabled' => 'db_tls_enabled',
|
||||
'db_tls_ca' => 'db_tls_ca',
|
||||
],
|
||||
'application_path' => '',
|
||||
'language' => '',
|
||||
'graphviz_path' => '',
|
||||
'source_dir' => '',
|
||||
], $aAdditionalParams);
|
||||
|
||||
$oParams->LoadFromHash($aParams);
|
||||
return $oParams;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user