From 5b19593ede319ac8db01d26995be96fb51943ddd Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Thu, 16 Nov 2023 14:38:15 +0100 Subject: [PATCH 1/3] :memo: README tests : add prerequisites --- tests/php-unit-tests/README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 From 8540ec644a043a4dfee2219690c6db4b3942932c Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Thu, 16 Nov 2023 15:23:18 +0100 Subject: [PATCH 2/3] =?UTF-8?q?:white=5Fcheck=5Fmark:=20N=C2=B06458=20Impr?= =?UTF-8?q?ove=20ItopDataTestCase=20tests=20speed=20What=20was=20measured?= =?UTF-8?q?=20:=20-=201'54=20with=20previous=20code=20(always=20doing=20a?= =?UTF-8?q?=20reset=20in=20tearDown)=20-=201'44=20without=20any=20ResetMet?= =?UTF-8?q?aModelQueyCacheGetObject=20call=20(but=203=20tests=20are=20fail?= =?UTF-8?q?ing)=20-=201'44=20with=20new=20optin=20mechanism=20+=20don't=20?= =?UTF-8?q?call=20Logoff=20if=20no=20current=20user=20logged?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/BaseTestCase/ItopDataTestCase.php | 17 ++++++++++++++--- .../unitary-tests/core/DBObjectTest.php | 3 +++ 2 files changed, 17 insertions(+), 3 deletions(-) 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 */ From b9d960e89e3baee17e3ece65476851bf0ef25fd7 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Thu, 16 Nov 2023 15:35:04 +0100 Subject: [PATCH 3/3] =?UTF-8?q?:white=5Fcheck=5Fmark:=20N=C2=B06458=20Fix?= =?UTF-8?q?=20ItopDataTestCase::$bIsUsingSilo=20visibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php index 6c13ac1c2..3064ca4de 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php @@ -65,7 +65,7 @@ abstract class ItopDataTestCase extends ItopTestCase * @see tearDown * @see ResetMetaModelQueyCacheGetObject */ - private $bIsUsingSilo = false; + protected $bIsUsingSilo = false; /** * @var string Default environment to use for test cases