N°6658 - Boost PHPUnit tests execution

This commit is contained in:
Romain Quetiez
2023-08-04 14:06:44 +02:00
parent d951d3b872
commit 65bb76b9e3
74 changed files with 690 additions and 416 deletions

View File

@@ -51,12 +51,6 @@ define('TAG_ATTCODE', 'domains');
*
* Helper class to extend for tests needing access to iTop's metamodel
*
* **⚠ Warning** Each class extending this one needs to add the following annotations :
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
*
* @since 2.7.7 3.0.1 3.1.0 N°4624 processIsolation is disabled by default and must be enabled in each test needing it (basically all tests using
* iTop datamodel)
*/
@@ -64,7 +58,8 @@ abstract class ItopDataTestCase extends ItopTestCase
{
private $iTestOrgId;
// For cleanup
private $aCreatedObjects = array();
private $aCreatedObjects = [];
private $aEventListeners = [];
/**
* @var string Default environment to use for test cases
@@ -73,6 +68,23 @@ abstract class ItopDataTestCase extends ItopTestCase
const USE_TRANSACTION = true;
const CREATE_TEST_ORG = false;
/**
* This method is called before the first test of this test class is run (in the current process).
*/
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
}
/**
* This method is called after the last test of this test class is run (in the current process).
*/
public static function tearDownAfterClass(): void
{
\UserRights::FlushPrivileges();
parent::tearDownAfterClass();
}
/**
* @throws Exception
*/
@@ -118,6 +130,15 @@ abstract class ItopDataTestCase extends ItopTestCase
}
}
}
// As soon as a rollback has been performed, each object memoized should be discarded
CMDBObject::SetCurrentChange(null);
// Leave the place clean
\UserRights::Logoff();
foreach ($this->aEventListeners as $sListenerId) {
EventService::UnRegisterListener($sListenerId);
}
parent::tearDown();
}
@@ -890,6 +911,17 @@ abstract class ItopDataTestCase extends ItopTestCase
}
}
protected function assertDBChangeOpCount(string $sClass, $iId, int $iExpectedCount)
{
$oSearch = new \DBObjectSearch('CMDBChangeOp');
$oSearch->AddCondition('objclass', $sClass);
$oSearch->AddCondition('objkey', $iId);
$oSearch->AllowAllData();
$oSet = new \DBObjectSet($oSearch);
$iCount = $oSet->Count();
$this->assertEquals($iExpectedCount, $iCount, "Found $iCount changes for object $sClass::$iId");
}
/**
* Import a set of XML files describing a consistent set of iTop objects
* @param string[] $aFiles