mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 18:18:46 +02:00
Remove dataprovider in iTopModulesPhpVersionIntegrationTest::testITopModulesPhpVersion (#175)
Remove dataprovider in \Combodo\iTop\Test\UnitTest\Integration\iTopModulesPhpVersionIntegrationTest::testITopModulesPhpVersion
The dataprovider was slow, and was very fragile because it contained much PHP code : as seen in 2221e05 when an error appears here it is very difficult to trace :/
So now we have a traditional PHPUnit test method, and still we are testing everytime all modules (not stopping on the first error : we have only one assert at the end instead of an assert per module), and also we're getting the list of modules having errors at the end
This commit is contained in:
@@ -55,17 +55,11 @@ class iTopModulesPhpVersionIntegrationTest extends ItopTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the datamodel.*.xml files refer to the current itop version
|
||||
* This is an integration test
|
||||
* @param string $sPhpFile iTop module file
|
||||
*
|
||||
* @group skipPostBuild
|
||||
*
|
||||
* @dataProvider iTopModulesPhpVersionProvider
|
||||
* @return string module version
|
||||
*/
|
||||
public function testiTopModulesPhpVersion($sExpectedVersion, $sPhpFile)
|
||||
{
|
||||
$this->assertNotNull($sExpectedVersion, 'Expected version is null, something went wrong in the dataprovider !');
|
||||
|
||||
private function GetItopModuleVersion(string $sPhpFile): ?string {
|
||||
$sModulePath = realpath($sPhpFile);
|
||||
$sModuleFileName = basename($sModulePath);
|
||||
$sModuleName = preg_replace('/[^.]+\.([^.]+)\.php/', '$1', $sModuleFileName);
|
||||
@@ -78,49 +72,41 @@ class iTopModulesPhpVersionIntegrationTest extends ItopTestCase {
|
||||
$matches
|
||||
);
|
||||
|
||||
$this->assertRegExp("#$sExpectedVersion#", $matches[1],
|
||||
" $sPhpFile:2 file refer does not refer to current itop version ($sModuleName/$matches[1] does not match regexp $sModuleName/$sExpectedVersion)");
|
||||
return $matches[1] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
* Verify if the datamodel.*.xml files refer to the current itop version
|
||||
* This is an integration test
|
||||
*
|
||||
* @group skipPostBuild
|
||||
* @uses utils::GetItopMinorVersion()
|
||||
*/
|
||||
public function iTopModulesPhpVersionProvider() {
|
||||
parent::setUp();
|
||||
|
||||
require_once APPROOT.'core/config.class.inc.php';
|
||||
require_once APPROOT.'application/utils.inc.php';
|
||||
|
||||
public function testITopModulesPhpVersion(): void {
|
||||
if (is_dir(APPROOT.'datamodels/2.x')) {
|
||||
$DatamodelsPath = APPROOT.'datamodels/2.x';
|
||||
}
|
||||
elseif (is_dir(APPROOT.'datamodels/1.x'))
|
||||
{
|
||||
} elseif (is_dir(APPROOT.'datamodels/1.x')) {
|
||||
$DatamodelsPath = APPROOT.'datamodels/1.x';
|
||||
} else {
|
||||
throw new \Exception('Cannot local the datamodels directory');
|
||||
}
|
||||
|
||||
require_once APPROOT.'core/config.class.inc.php';
|
||||
$sPath = $DatamodelsPath.'/*/module.*.php';
|
||||
$aPhpFiles = glob($sPath);
|
||||
|
||||
try {
|
||||
$sExpectedVersion = \utils::GetItopMinorVersion().'\.\d+';// ie: 2.7\.\d+ (and yes, the 1st dot should be escaped, but, hey, it is good enough as it, ans less complex to read)
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$sExpectedVersion = null;
|
||||
}
|
||||
$sMinorVersion = \utils::GetItopMinorVersion();
|
||||
$sExpectedVersion = '/^'.str_replace('.', '\.', $sMinorVersion).'\.\d+$/';
|
||||
|
||||
$aTestCases = array();
|
||||
$aModuleWithError = [];
|
||||
foreach ($aPhpFiles as $sPhpFile) {
|
||||
$aTestCases[$sPhpFile] = array(
|
||||
'sExpectedVersion' => $sExpectedVersion,
|
||||
'sPhpFile' => $sPhpFile,
|
||||
);
|
||||
$sActualVersion = $this->GetItopModuleVersion($sPhpFile);
|
||||
|
||||
if (!preg_match($sExpectedVersion, $sActualVersion)) {
|
||||
$aModuleWithError[$sPhpFile] = $sActualVersion;
|
||||
}
|
||||
}
|
||||
|
||||
return $aTestCases;
|
||||
self::assertEquals([], $aModuleWithError, 'Some modules have wrong versions ! They should match '.$sExpectedVersion);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user