diff --git a/tests/php-unit-tests/README.md b/tests/php-unit-tests/README.md index 3f556426f..22ceaec3b 100644 --- a/tests/php-unit-tests/README.md +++ b/tests/php-unit-tests/README.md @@ -7,8 +7,20 @@ - Covers the consistency of some data through the app? - Most likely in "integration-tests". -## How do I make sure that my tests are efficient? +## Tests prerequisites + +Install iTop with default setup options : +- Configuration Management options : everything checked +- Service Management for Enterprises +- Simple Ticket Management + Customer portal +- Simple Change Management + +Plus : +- Additional ITIL tickets : check Known Errors Management and FAQ + + +## How do I make sure that my tests are efficient? ### Derive from the relevant test class diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php index 8051180f3..c14340cbc 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php @@ -65,6 +65,13 @@ abstract class ItopDataTestCase extends ItopTestCase private $aCreatedObjects = []; private $aEventListeners = []; + /** + * @var bool When testing with silo, there are some cache we need to update on tearDown. Doing it all the time will cost too much, so it's opt-in ! + * @see tearDown + * @see ResetMetaModelQueyCacheGetObject + */ + protected $bIsUsingSilo = false; + /** * @var string Default environment to use for test cases */ @@ -141,9 +148,13 @@ abstract class ItopDataTestCase extends ItopTestCase CMDBObject::SetCurrentChange(null); // Leave the place clean - \UserRights::Logoff(); - $this->SetNonPublicStaticProperty(UserRights::class, 'm_aCacheUsers', []); - $this->ResetMetaModelQueyCacheGetObject(); + if (UserRights::IsLoggedIn()) { + UserRights::Logoff(); + } + $this->SetNonPublicStaticProperty(UserRights::class, 'm_aCacheUsers', []); // we could have cached rollbacked instances + if ($this->bIsUsingSilo) { + $this->ResetMetaModelQueyCacheGetObject(); + } foreach ($this->aEventListeners as $sListenerId) { EventService::UnRegisterListener($sListenerId); diff --git a/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php b/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php index 2e9e33e65..b9a887e83 100644 --- a/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php +++ b/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php @@ -191,6 +191,8 @@ class QueryTest extends ItopDataTestCase protected function tearDown(): void { $this->oUser->DBDelete(); + + parent::tearDown(); } } diff --git a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php index fcbbeb251..69ddebea8 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php @@ -455,6 +455,7 @@ class DBObjectTest extends ItopDataTestCase public function testCheckExtKeysSiloOnAttributeExternalKey() { //--- Preparing data... + $this->bIsUsingSilo = true; $oAlwaysTrueCallback = $this->GetAlwaysTrueCallback(); $oAlwaysFalseCallback = $this->GetAlwaysFalseCallback(); @@ -532,6 +533,7 @@ class DBObjectTest extends ItopDataTestCase public function testCheckExtKeysOnAttributeLinkedSetIndirect() { //--- Preparing data... + $this->bIsUsingSilo = true; /** @var Organization $oDemoOrg */ $oDemoOrg = MetaModel::GetObjectByName(Organization::class, 'Demo'); /** @var Person $oPersonOnItDepartmentOrg */ @@ -633,6 +635,7 @@ class DBObjectTest extends ItopDataTestCase public function testCheckExtKeysSiloOnAttributeObjectKey() { //--- Preparing data... + $this->bIsUsingSilo = true; /** @var Organization $oDemoOrg */ $oDemoOrg = MetaModel::GetObjectByName(Organization::class, 'Demo'); /** @var Person $oPersonOnItDepartmentOrg */