Optimize tests execution time (no need for process isolation as long as we leave the premises clean)

This commit is contained in:
Romain Quetiez
2023-10-26 21:23:47 +02:00
parent 442721bcb5
commit 798cd10d6b
2 changed files with 49 additions and 22 deletions

View File

@@ -30,9 +30,6 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Dict;
use Exception;
/**
* @runClassInSeparateProcess
*/
class dictTest extends ItopTestCase
{
private $sEnvName;
@@ -42,7 +39,9 @@ class dictTest extends ItopTestCase
$this->RequireOnceItopFile('core'.DIRECTORY_SEPARATOR.'apc-service.class.inc.php');
$this->sEnvName = time();
// This id will be used as path to the dictionary files
// It must be unique enough for the magic of Dict to operate (due to the use of require_once to load dictionaries)
$this->sEnvName = uniqid();
$sDictionaryFolder = APPROOT."env-$this->sEnvName".DIRECTORY_SEPARATOR."dictionaries";
@mkdir($sDictionaryFolder, 0777, true);
@@ -68,6 +67,12 @@ PHP;
file_put_contents($sDictionaryFolder.DIRECTORY_SEPARATOR."en-en.dict.php", $sContent);
$_SESSION['itop_env'] = $this->sEnvName;
// Preserve the dictionary for test that will be executed later on
static::BackupStaticProperties('Dict');
// Reset the dictionary
static::SetNonPublicStaticProperty('Dict', 'm_aData', []);
}
protected function tearDown(): void
@@ -78,6 +83,8 @@ PHP;
rmdir(APPROOT."env-$this->sEnvName".DIRECTORY_SEPARATOR."dictionaries");
rmdir(APPROOT."env-$this->sEnvName");
static::RestoreStaticProperties('Dict');
parent::tearDown();
}