diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php index 333d50e0c..6c13ac1c2 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php @@ -60,6 +60,13 @@ abstract class ItopDataTestCase extends ItopTestCase // For cleanup private $aCreatedObjects = []; + /** + * @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 + */ + private $bIsUsingSilo = false; + /** * @var string Default environment to use for test cases */ @@ -133,9 +140,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(); + } 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 8d9500f31..b5bedb197 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php @@ -304,6 +304,7 @@ class DBObjectTest extends ItopDataTestCase public function testCheckExtKeysSiloOnAttributeExternalKey() { //--- Preparing data... + $this->bIsUsingSilo = true; $oAlwaysTrueCallback = $this->GetAlwaysTrueCallback(); $oAlwaysFalseCallback = $this->GetAlwaysFalseCallback(); @@ -381,6 +382,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 */ @@ -482,6 +484,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 */