From c3547f29d077ab28b83028e33a9ab9cec05d1a5e Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Thu, 4 Jul 2024 09:38:35 +0200 Subject: [PATCH] :white_check_mark: Cosmetics on the test framework --- .../src/BaseTestCase/ItopDataTestCase.php | 28 +++---------------- .../php-unit-tests/GivenObjectInDBTest.php | 8 ++++-- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php index 3baab4203..4c4f756e5 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php @@ -127,7 +127,10 @@ abstract class ItopDataTestCase extends ItopTestCase } if (static::CREATE_TEST_ORG) { - $this->GivenTestOrganization(); + // Create a specific organization for the tests + $this->iTestOrgId = $this->GivenObjectInDB('Organization', [ + 'name' => 'UnitTestOrganization', + ]); } $oConfig = MetaModel::GetConfig(); @@ -1175,29 +1178,6 @@ abstract class ItopDataTestCase extends ItopTestCase return $iKey; } - /** - * Create an Organization in database - * - * @param string $sName - * - * @throws Exception - */ - protected function GivenOrganization($sName): string - { - $sId = $this->GivenObjectInDB('Organization', [ - 'name' => $sName, - ]); - $this->debug("Created Organization $sName"); - - return $sId; - } - - protected function GivenTestOrganization(): void - { - // Create a specific organization for the tests - $this->iTestOrgId = $this->GivenOrganization('UnitTestOrganization'); - } - /** * Create a Farm in database * diff --git a/tests/php-unit-tests/unitary-tests/tests/php-unit-tests/GivenObjectInDBTest.php b/tests/php-unit-tests/unitary-tests/tests/php-unit-tests/GivenObjectInDBTest.php index d26397e1d..7b4553959 100644 --- a/tests/php-unit-tests/unitary-tests/tests/php-unit-tests/GivenObjectInDBTest.php +++ b/tests/php-unit-tests/unitary-tests/tests/php-unit-tests/GivenObjectInDBTest.php @@ -46,17 +46,21 @@ class GivenObjectInDBTest extends ItopDataTestCase 'first_name' => 'John', ]); + $iRole = $this->GivenObjectInDB('ContactType', [ + 'name' => 'The Boss', + ]); + $iTeam = $this->GivenObjectInDB('Team', [ 'name' => 'The A Team', 'persons_list' => [ - "person_id:$iPerson;role_id:1" + "person_id:$iPerson;role_id:$iRole" ], ]); $oSet = new \DBObjectSet(\DBObjectSearch::FromOQL("SELECT lnkPersonToTeam AS lnk WHERE lnk.team_id = $iTeam AND lnk.person_id = $iPerson")); $this->assertEquals(1, $oSet->Count(), "The link between the team and the person should be there"); $oLnk = $oSet->Fetch(); - $this->assertEquals(1, $oLnk->Get('role_id'), "The role should be correctly set"); + $this->assertEquals($iRole, $oLnk->Get('role_id'), "The role should be correctly set"); } public function testItShouldFailExplicitlyWhenAnAttributeCodeIsUnknown()