💚 fix test to make conversion functions exist for any one found in datamodels files

This commit is contained in:
odain
2020-08-28 16:48:04 +02:00
parent d1af851fcd
commit 0d878a52a2

View File

@@ -4,6 +4,7 @@ namespace Combodo\iTop\Test\UnitTest\ReleaseChecklist;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use iTopDesignFormat;
use PHPUnit\Exception;
/**
@@ -50,33 +51,61 @@ class TestForITopDesignFormatClass extends ItopTestCase
//make sure there is only one found
$this->assertTrue(is_array($aDatamodelCurrentVersions));
$this->assertEquals(1, count($aDatamodelCurrentVersions), "Found too much XML versions: " . json_encode($aDatamodelCurrentVersions));
//check we have migration function from new version to previous one
$sCurrentVersion = array_values($aDatamodelCurrentVersions)[0];
$this->assertTrue(array_key_exists($sCurrentVersion, iTopDesignFormat::$aVersions), "Missing $sCurrentVersion conversion functions in iTopDesignFormat.");
$aCurrentVersionInfo = iTopDesignFormat::$aVersions[$sCurrentVersion];
$this->assertTrue(is_array($aCurrentVersionInfo), "Wrong $sCurrentVersion config in iTopDesignFormat.");
$this->assertTrue(array_key_exists('previous', $aCurrentVersionInfo), "Missing previous for $sCurrentVersion config in iTopDesignFormat.");
$this->TestDefinedFunction($aCurrentVersionInfo, 'go_to_previous', $sCurrentVersion);
$aErrors = [];
//check we have migration function from N-1 version to new one
$sPreviousVersion = $aCurrentVersionInfo['previous'];
$this->assertTrue(array_key_exists($sPreviousVersion, iTopDesignFormat::$aVersions), "Missing $sPreviousVersion config in iTopDesignFormat.");
$aPreviousVersionInfo = iTopDesignFormat::$aVersions[$sPreviousVersion];
$this->assertTrue(is_array($aPreviousVersionInfo), "wrong $sPreviousVersion config in iTopDesignFormat.");
$this->assertTrue(array_key_exists('previous', $aPreviousVersionInfo), "Missing previous for $sPreviousVersion config in iTopDesignFormat.");
$this->TestDefinedFunction($aPreviousVersionInfo, 'go_to_previous', $sPreviousVersion);
$this->TestDefinedFunction($aPreviousVersionInfo, 'go_to_next', $sPreviousVersion);
foreach ($aDatamodelCurrentVersions as $sCurrentVersion)
{
try{
//check we have migration function from current version to previous
$this->CheckCondition(array_key_exists($sCurrentVersion, iTopDesignFormat::$aVersions), "Missing $sCurrentVersion conversion functions in iTopDesignFormat.");
$aCurrentVersionInfo = iTopDesignFormat::$aVersions[$sCurrentVersion];
$this->CheckCondition(is_array($aCurrentVersionInfo), "Wrong $sCurrentVersion config in iTopDesignFormat.");
$this->CheckCondition(array_key_exists('previous', $aCurrentVersionInfo), "Missing previous for $sCurrentVersion config in iTopDesignFormat.");
$this->TestDefinedFunction($aCurrentVersionInfo, 'go_to_previous', $sCurrentVersion);
//check we have migration function from N-1 version to current one
$sPreviousVersion = $aCurrentVersionInfo['previous'];
$this->CheckCondition(array_key_exists($sPreviousVersion, iTopDesignFormat::$aVersions), "Missing $sPreviousVersion config in iTopDesignFormat.");
$aPreviousVersionInfo = iTopDesignFormat::$aVersions[$sPreviousVersion];
$this->CheckCondition(is_array($aPreviousVersionInfo), "wrong $sPreviousVersion config in iTopDesignFormat.");
$this->CheckCondition(array_key_exists('previous', $aPreviousVersionInfo), "Missing previous for $sPreviousVersion config in iTopDesignFormat.");
$this->TestDefinedFunction($aPreviousVersionInfo, 'go_to_previous', $sPreviousVersion);
$this->TestDefinedFunction($aPreviousVersionInfo, 'go_to_next', $sPreviousVersion);
}
catch(Exception $e)
{
$aErrors[] = $e->getMessage();
}
}
if (count($aErrors)!=0)
{
$sMsg = "Issue with conversion functions:\n";
$sMsg .= implode("\n", $aErrors);
$this->fail($sMsg);
}
else
{
$this->assertTrue(true);
}
}
private function CheckCondition($bCondition, $sMsg)
{
if ($bCondition === false)
{
throw new \Exception($sMsg);
}
}
private function TestDefinedFunction($aCurrentVersionInfo, $sFunctionKey, $sVersion)
{
$sInfo = json_encode($aCurrentVersionInfo, true);
$this->assertTrue(array_key_exists($sFunctionKey, $aCurrentVersionInfo), "Missing $sFunctionKey in $sVersion config in iTopDesignFormat: " . $sInfo);
$this->CheckCondition(array_key_exists($sFunctionKey, $aCurrentVersionInfo), "Missing $sFunctionKey in $sVersion config in iTopDesignFormat: " . $sInfo);
echo $aCurrentVersionInfo[$sFunctionKey].'\n';
$oReflectionClass = new \ReflectionClass(iTopDesignFormat::class);
$this->assertTrue($oReflectionClass->hasMethod($aCurrentVersionInfo[$sFunctionKey]), "wrong go_to_previous function '".$aCurrentVersionInfo[$sFunctionKey]."'' for $sVersion config in iTopDesignFormat." . $sInfo);
$this->CheckCondition($oReflectionClass->hasMethod($aCurrentVersionInfo[$sFunctionKey]), "wrong go_to_previous function '".$aCurrentVersionInfo[$sFunctionKey]."'' for $sVersion config in iTopDesignFormat." . $sInfo);
}
public function GetDataModelFiles($sFolder)