Skip to content

Commit

Permalink
test/bin/installModule : Add test for module reinstall mode
Browse files Browse the repository at this point in the history
  • Loading branch information
bulton-fr committed Nov 17, 2018
1 parent 2231240 commit 2730563
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 72 deletions.
21 changes: 15 additions & 6 deletions test/bin/ExpectedModuleInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,21 @@ public function getScriptFiles()

public function generateInstallOutput(bool $reinstall = false): string
{
$output = $this->moduleName." : Run install.\n"
." > Create symbolic link ... \033[1;32mDone\n\033[0m"
." > Copy config files :\n"
." >> Create config directory for this module ... \033[1;32mDone\n\033[0m"
." >> Copy manifest.json ... \033[1;32mDone\n\033[0m"
;
$output = $this->moduleName." : Run install.\n";

if ($reinstall === false) {
$output .= " > Create symbolic link ... \033[1;32mDone\n\033[0m"
." > Copy config files :\n"
." >> Create config directory for this module ... \033[1;32mDone\n\033[0m"
." >> Copy manifest.json ... \033[1;32mDone\n\033[0m"
;
} else {
$output .= " > Create symbolic link ... [Force Reinstall: Remove symlink] \033[1;32mDone\n\033[0m"
." > Copy config files :\n"
." >> Create config directory for this module ... [Force Reinstall: Remove directory] \033[1;32mDone\n\033[0m"
." >> Copy manifest.json ... \033[1;32mDone\n\033[0m"
;
}

foreach ($this->configFiles as $configFilename) {
$output .= " >> Copy ".$configFilename." ... \033[1;32mDone\n\033[0m";
Expand Down
141 changes: 75 additions & 66 deletions test/bin/installModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,78 +18,87 @@
]
);

echo "\033[0;33mCheck hello-world module install\033[0m\n";

$moduleInstallOutput = [];
exec('cd '.$installDir.' && ./vendor/bin/bfwInstallModules', $moduleInstallOutput);

$moduleInstallOutput = implode("\n", $moduleInstallOutput)."\n";

$expectedStart = "\033[0;33mRun BFW Modules Install\033[0m\n";
$expectedRunScript = "Read all modules to run install script...\n";
$expectedEndScript = "All modules have been read.\n";

$matrix = [];
foreach ($moduleToInstall as $mod1) {
foreach ($moduleToInstall as $mod2) {
if ($mod1 === $mod2) {
continue;
}

$matrix[] = [$mod1, $mod2];
}
}
$reinstallModes = [false, true];
foreach ($reinstallModes as $reinstallStatus) {
$reinstallDisplay = ($reinstallStatus === true) ? 'true' : 'false';

echo "\033[0;33mCheck modules install - reinstall : ".$reinstallDisplay."\033[0m\n";

$moduleInstallOutput = [];
$cmd = 'cd '.$installDir.' && ./vendor/bin/bfwInstallModules';
if ($reinstallStatus === true) {
$cmd .= ' --reinstall';
}
exec($cmd, $moduleInstallOutput);

$moduleInstallOutput = implode("\n", $moduleInstallOutput)."\n";

$expectedModuleOutput = [];

foreach ($matrix as $modComb1) {
foreach ($matrix as $modComb2) {
$expectedModuleOutput[] = $expectedStart
.$modComb1[0]->generateInstallOutput()
.$modComb1[1]->generateInstallOutput()
.$expectedRunScript
.$modComb2[0]->generateScriptOutput()
.$modComb2[1]->generateScriptOutput()
.$expectedEndScript
;
$expectedStart = "\033[0;33mRun BFW Modules Install\033[0m\n";
$expectedRunScript = "Read all modules to run install script...\n";
$expectedEndScript = "All modules have been read.\n";

$matrix = [];
foreach ($moduleToInstall as $mod1) {
foreach ($moduleToInstall as $mod2) {
if ($mod1 === $mod2) {
continue;
}

$matrix[] = [$mod1, $mod2];
}
}
}

echo 'Test output returned by script : ';

/*
echo "\n[TRAVIS DEBUG]\n--------------------------\n";
print_r($moduleInstallOutput);
echo "\n--------------------------\n";
print_r($expectedModuleOutput);
echo "\n--------------------------\n";
*/

$expectedIsFound = false;
foreach ($expectedModuleOutput as $expectedOutput) {
if ($expectedOutput === $moduleInstallOutput) {
$expectedIsFound = true;
break;
$expectedModuleOutput = [];

foreach ($matrix as $modComb1) {
foreach ($matrix as $modComb2) {
$expectedModuleOutput[] = $expectedStart
.$modComb1[0]->generateInstallOutput($reinstallStatus)
.$modComb1[1]->generateInstallOutput($reinstallStatus)
.$expectedRunScript
.$modComb2[0]->generateScriptOutput()
.$modComb2[1]->generateScriptOutput()
.$expectedEndScript
;
}
}
}

if ($expectedIsFound === false) {
echo "\033[1;31m[Fail]\033[0m\n";
fwrite(STDERR, 'Text returned is not equal to expected text.');
exit(1);
}
echo 'Test output returned by script : ';

/*
echo "\n[TRAVIS DEBUG]\n--------------------------\n";
print_r($moduleInstallOutput);
echo "\n--------------------------\n";
print_r($expectedModuleOutput);
echo "\n--------------------------\n";
*/

$expectedIsFound = false;
foreach ($expectedModuleOutput as $expectedOutput) {
if ($expectedOutput === $moduleInstallOutput) {
$expectedIsFound = true;
break;
}
}

echo "\033[1;32m[OK]\033[0m\n";
if ($expectedIsFound === false) {
echo "\033[1;31m[Fail]\033[0m\n";
fwrite(STDERR, 'Text returned is not equal to expected text.');
exit(1);
}

echo "\033[1;32m[OK]\033[0m\n";

echo 'Test structure :'."\n";
echo 'Test structure :'."\n";

testDirectoryOrFile($installDir, 'app/config/bfw-hello-world/hello-world.json');
testDirectoryOrFile($installDir, 'app/config/bfw-hello-world/manifest.json');
testDirectoryOrFile($installDir, 'app/modules/bfw-hello-world/helloWorld.php');
testDirectoryOrFile($installDir, 'app/modules/bfw-hello-world/module.json');
testDirectoryOrFile($installDir, 'app/config/bfw-hello-world/hello-world.json');
testDirectoryOrFile($installDir, 'app/config/bfw-hello-world/manifest.json');
testDirectoryOrFile($installDir, 'app/modules/bfw-hello-world/helloWorld.php');
testDirectoryOrFile($installDir, 'app/modules/bfw-hello-world/module.json');

testDirectoryOrFile($installDir, 'app/config/bfw-test-install/test-install.json');
testDirectoryOrFile($installDir, 'app/config/bfw-test-install/manifest.json');
testDirectoryOrFile($installDir, 'app/modules/bfw-test-install/runner.php');
testDirectoryOrFile($installDir, 'app/modules/bfw-test-install/module.json');
testDirectoryOrFile($installDir, 'web/install_test.php');
testDirectoryOrFile($installDir, 'app/config/bfw-test-install/test-install.json');
testDirectoryOrFile($installDir, 'app/config/bfw-test-install/manifest.json');
testDirectoryOrFile($installDir, 'app/modules/bfw-test-install/runner.php');
testDirectoryOrFile($installDir, 'app/modules/bfw-test-install/module.json');
testDirectoryOrFile($installDir, 'web/install_test.php');
}

0 comments on commit 2730563

Please sign in to comment.