diff --git a/setup/modulediscovery.class.inc.php b/setup/modulediscovery.class.inc.php index 2279a6c30..8ccb5d285 100755 --- a/setup/modulediscovery.class.inc.php +++ b/setup/modulediscovery.class.inc.php @@ -478,7 +478,7 @@ class ModuleDiscovery } //include all modules $iInDegreeCounterIncludingOutsideModules = count($oModule->GetUnresolvedDependencyModuleNames()); - $aCountDepsByModuleId[$sModuleId] = [$iInDegreeCounter, $iInDegreeCounterIncludingOutsideModules]; + $aCountDepsByModuleId[$sModuleId] = [$iInDegreeCounter, $iInDegreeCounterIncludingOutsideModules, $sModuleId]; } $aRes=[]; @@ -493,7 +493,13 @@ class ModuleDiscovery } //compare $iInDegreeCounterIncludingOutsideModules - return $aDeps1[1] - $aDeps2[1]; + $res = $aDeps1[1] - $aDeps2[1]; + if ($res != 0){ + return $res; + } + + //alphabetical order at least + return strcmp($aDeps1[2], $aDeps2[2]); }); $bOneLoopAtLeast=false; @@ -518,7 +524,7 @@ class ModuleDiscovery $aDepCount = $aCountDepsByModuleId[$sModuleId2]; $iInDegreeCounter = $aDepCount[0] - 1; $iInDegreeCounterIncludingOutsideModules = $aDepCount[1]; - $aCountDepsByModuleId[$sModuleId2] = [$iInDegreeCounter, $iInDegreeCounterIncludingOutsideModules]; + $aCountDepsByModuleId[$sModuleId2] = [$iInDegreeCounter, $iInDegreeCounterIncludingOutsideModules, $sModuleId2]; } unset($aDependsOnModuleName[$oModule->GetModuleName()]); diff --git a/tests/php-unit-tests/unitary-tests/setup/ModuleDiscoveryTest.php b/tests/php-unit-tests/unitary-tests/setup/ModuleDiscoveryTest.php index 766f64d5c..72680941f 100644 --- a/tests/php-unit-tests/unitary-tests/setup/ModuleDiscoveryTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/ModuleDiscoveryTest.php @@ -134,6 +134,10 @@ MSG; public function testOrderModulesByDependencies_ResolveOk() { $aModules=[ + "id0/1" => [ + 'dependencies' => [ 'id2/2 || id1/1'], + 'label' => 'label1', + ], "id1/1" => [ 'dependencies' => [ 'id2/2'], 'label' => 'label1', @@ -159,6 +163,45 @@ MSG; "id3/3", "id2/2", "id1/1", + "id0/1", + ]; + $this->assertEquals($aExpected, array_keys($aResult)); + $this->assertEquals(1, $iLoopCount); + } + + public function testOrderModulesByDependencies_ResolveNoDependendenciesOrderByAlphabeticalOrder() + { + $aModules=[ + "id2/2" => [ + 'dependencies' => [], + 'label' => 'label2', + ], + "id1/1" => [ + 'dependencies' => [ ], + 'label' => 'label1', + ], + "id3/3" => [ + 'dependencies' => [], + 'label' => 'label3', + ], + "id4/4" => [ + 'dependencies' => [], + 'label' => 'label4', + ], + "id0/1" => [ + 'dependencies' => [], + 'label' => 'label0', + ], + ]; + $iLoopCount=0; + $aResult = ModuleDiscovery::OrderModulesByDependencies($aModules, true, null, $iLoopCount); + + $aExpected = [ + "id0/1", + "id1/1", + "id2/2", + "id3/3", + "id4/4", ]; $this->assertEquals($aExpected, array_keys($aResult)); $this->assertEquals(1, $iLoopCount); @@ -211,7 +254,7 @@ MSG; public function testSortModulesByCountOfDepencenciesDescending_NoDependencies(){ $aUnresolvedDependencyModules = []; - foreach (['a', 'b', 'c'] as $sModuleId){ + foreach (['c', 'b', 'a'] as $sModuleId){ $this->AddModule($aUnresolvedDependencyModules, $sModuleId, []); } ModuleDiscovery::SortModulesByCountOfDepencenciesDescending($aUnresolvedDependencyModules); @@ -229,8 +272,8 @@ MSG; $this->assertEquals( [ 'itop-structure/2.7.1', - 'itop-tickets/2.0.0', 'itop-config-mgmt/123', + 'itop-tickets/2.0.0', 'itop-change-mgmt/456', ], array_keys($aUnresolvedDependencyModules)); } @@ -244,8 +287,8 @@ MSG; ModuleDiscovery::SortModulesByCountOfDepencenciesDescending($aUnresolvedDependencyModules); $this->assertEquals( [ - 'itop-tickets/2.0.0', 'itop-config-mgmt/123', + 'itop-tickets/2.0.0', 'itop-change-mgmt/456', ], array_keys($aUnresolvedDependencyModules)); @@ -263,8 +306,8 @@ MSG; [ 'moduleA/1', 'moduleC/1', - 'moduleB/1', 'moduleA/2', + 'moduleB/1', ], array_keys($aUnresolvedDependencyModules)); } diff --git a/tests/php-unit-tests/unitary-tests/setup/ressources/expected_ordered_module_ids.json b/tests/php-unit-tests/unitary-tests/setup/ressources/expected_ordered_module_ids.json index eb0b175de..d52ca0903 100644 --- a/tests/php-unit-tests/unitary-tests/setup/ressources/expected_ordered_module_ids.json +++ b/tests/php-unit-tests/unitary-tests/setup/ressources/expected_ordered_module_ids.json @@ -16,32 +16,32 @@ "itop-sla-computation\/3.2.1", "itop-structure\/3.2.1", "itop-welcome-itil\/3.2.1", - "itop-portal\/3.2.1", "combodo-db-tools\/3.2.1", "itop-config-mgmt\/3.2.1", - "itop-themes-compat\/3.2.1", - "itop-tickets\/3.2.1", - "itop-oauth-client\/3.2.1", "itop-datacenter-mgmt\/3.2.1", "itop-endusers-devices\/3.2.1", "itop-hub-connector\/3.2.1", "itop-knownerror-mgmt\/3.2.1", + "itop-oauth-client\/3.2.1", + "itop-portal\/3.2.1", "itop-storage-mgmt\/3.2.1", - "itop-virtualization-mgmt\/3.2.1", + "itop-themes-compat\/3.2.1", + "itop-tickets\/3.2.1", "itop-problem-mgmt\/3.2.1", "itop-request-mgmt-itil\/3.2.1", "itop-request-mgmt\/3.2.1", "itop-service-mgmt-provider\/3.2.1", "itop-service-mgmt\/3.2.1", - "itop-faq-light\/3.2.1", - "itop-core-update\/3.2.1", + "itop-virtualization-mgmt\/3.2.1", "itop-bridge-cmdb-ticket\/3.2.1", + "itop-bridge-virtualization-storage\/3.2.1", "itop-change-mgmt-itil\/3.2.1", "itop-change-mgmt\/3.2.1", - "itop-bridge-virtualization-storage\/3.2.1", + "itop-core-update\/3.2.1", + "itop-faq-light\/3.2.1", + "itop-bridge-cmdb-services\/3.2.1", "itop-incident-mgmt-itil\/3.2.1", "itop-full-itil\/3.2.1", - "itop-bridge-cmdb-services\/3.2.1", "itop-bridge-datacenter-mgmt-services\/3.2.1", "itop-bridge-endusers-devices-services\/3.2.1", "itop-bridge-storage-mgmt-services\/3.2.1",