GetTestEnvironment().'.log'; IssueLog::Enable($sLogFileAbsPath); } /** * @return string Abs path to the XML delta to use for the tests of that class */ abstract public function GetDatamodelDeltaAbsPath(): string; /** * @inheritDoc */ protected function LoadRequiredFiles(): void { $this->RequireOnceItopFile('setup/setuputils.class.inc.php'); $this->RequireOnceItopFile('setup/runtimeenv.class.inc.php'); $this->RequireOnceUnitTestFile('UnitTestRunTimeEnvironment.php'); } /** * @return string Environment used as a base (conf. file, modules, DB, ...) to prepare the test environment */ protected function GetSourceEnvironment(): string { return 'production'; } /** * @inheritDoc * * This is final for now as we don't support yet to have several environments in // to test incompatible DMs / deltas. * When / if we do this, keep in mind that should ONLY be overloaded if your test case XML deltas are NOT compatible with the others, as it will create / compile another environment, increasing the global test time. */ final public function GetTestEnvironment(): string { return 'php-unit-tests'; } /** * @inheritDoc */ protected function PrepareEnvironment(): void { $sSourceEnv = $this->GetSourceEnvironment(); $sTestEnv = $this->GetTestEnvironment(); // Check if test env. if already set and only prepare it if it doesn't already exist // // Note: To improve performances, we compile all XML deltas from test cases derived from this class and make a single environment where everything will be ran at once. // This requires XML deltas to be compatible, but it is a known and accepted trade-off. See PR #457 if (false === static::$bIsCustomEnvironmentReady) { //---------------------------------------------------- // Clear any previous "$sTestEnv" environment //---------------------------------------------------- // - Configuration file $sConfFile = utils::GetConfigFilePath($sTestEnv); $sConfFolder = dirname($sConfFile); if (is_file($sConfFile)) { chmod($sConfFile, 0777); SetupUtils::tidydir($sConfFolder); } // - Datamodel delta files // - Cache folder // - Compiled folder // We don't need to clean them as they are already by the compilation // - Drop database // We don't do that now, it will be done before re-creating the DB, once the metamodel is started //---------------------------------------------------- // Prepare "$sTestEnv" environment //---------------------------------------------------- // All the following is greatly inspired by the toolkit's sandbox script // - Prepare config file $oSourceConf = new Config(utils::GetConfigFilePath($sSourceEnv)); if ($oSourceConf->Get('source_dir') === '') { throw new Exception('Missing entry source_dir from the config file'); } $oTestConfig = clone($oSourceConf); $oTestConfig->ChangeModulesPath($sSourceEnv, $sTestEnv); // - Switch DB name to a dedicated one so we don't mess with the original one $sTestEnvSanitizedForDBName = preg_replace('/[^\d\w]/', '', $sTestEnv); $oTestConfig->Set('db_name', $oTestConfig->Get('db_name').'_'.$sTestEnvSanitizedForDBName); // - Compile env. based on the existing 'production' env. $oEnvironment = new UnitTestRunTimeEnvironment($sTestEnv); $oEnvironment->WriteConfigFileSafe($oTestConfig); $oEnvironment->CompileFrom($sSourceEnv, false); // - Force re-creating of the DB // // TODO: Create tmp DB // But how to use it now when the metamodel is not started yet ?? // MetaModel::LoadConfig($oTestConfig); // if (MetaModel::DBExists()) { // MetaModel::DBDrop(); // } // MetaModel::DBCreate(); static::$bIsCustomEnvironmentReady = true; } parent::PrepareEnvironment(); } }