expectException(\Exception::class); } $sActualMinVersion = \utils::GetItopMinorVersion($sVersion); if (!is_null($sExpectedMinVersion)) { $this->assertEquals($sExpectedMinVersion, $sActualMinVersion); } } public function GetItopMinorVersionProvider() { return [['2.8.0', '2.8'], ['3.0.0', '3.0'], ['3.', null], ['3', null]]; } /** * @param string $sPhpFile iTop module file * * @return string module version */ private function GetItopModuleVersion(string $sPhpFile): ?string { $sModulePath = realpath($sPhpFile); $sModuleFileName = basename($sModulePath); $sModuleName = preg_replace('/[^.]+\.([^.]+)\.php/', '$1', $sModuleFileName); $sFileContent = file_get_contents($sPhpFile); preg_match( "#'$sModuleName/([^']+)'#", $sFileContent, $matches ); return $matches[1] ?? ''; } /** * Verify if the datamodel.*.xml files refer to the current itop version * This is an integration test * * @group skipPostBuild * @uses utils::GetItopMinorVersion() * * @since 2.7.7 3.0.1 3.1.0 N°4714 uses new {@link ITOP_CORE_VERSION} constant */ public function testITopModulesPhpVersion(): void { if (is_dir(APPROOT.'datamodels/2.x')) { $DatamodelsPath = APPROOT.'datamodels/2.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); $sExpectedVersion = ITOP_CORE_VERSION; $aModuleWithError = []; foreach ($aPhpFiles as $sPhpFile) { $sActualVersion = $this->GetItopModuleVersion($sPhpFile); if (!preg_match($sExpectedVersion, $sActualVersion)) { $aModuleWithError[$sPhpFile] = $sActualVersion; } } self::assertEquals([], $aModuleWithError, 'Some modules have wrong versions ! They should match '.$sExpectedVersion); } }