Skip to content

Commit 48d7868

Browse files
authored
Merge pull request #5930 from magento-performance/MC-35885-2
MC-35885
2 parents e9a65b4 + a43417e commit 48d7868

File tree

5 files changed

+66
-71
lines changed

5 files changed

+66
-71
lines changed

dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Setup\Model;
77

8+
use Magento\Framework\Component\ComponentRegistrarInterface;
9+
use Magento\Setup\Validator\DbValidator;
10+
use Laminas\ServiceManager\ServiceLocatorInterface;
11+
812
class ConfigOptionsListCollectorTest extends \PHPUnit\Framework\TestCase
913
{
1014
/**
@@ -14,7 +18,7 @@ class ConfigOptionsListCollectorTest extends \PHPUnit\Framework\TestCase
1418

1519
protected function setUp(): void
1620
{
17-
$this->objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
21+
$this->objectManagerProvider = $this->createMock(ObjectManagerProvider::class);
1822
$this->objectManagerProvider
1923
->expects($this->any())
2024
->method('get')
@@ -24,11 +28,13 @@ protected function setUp(): void
2428
public function testCollectOptionsLists()
2529
{
2630
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
27-
$fullModuleListMock = $this->createMock(\Magento\Framework\Module\FullModuleList::class);
28-
$fullModuleListMock->expects($this->once())->method('getNames')->willReturn(['Magento_Backend']);
31+
$componentRegistrar = $this->createMock(ComponentRegistrarInterface::class);
32+
$componentRegistrar->expects($this->once())
33+
->method('getPaths')
34+
->willReturn(['Magento_Backend'=>'app/code/Magento/Backend']);
2935

30-
$dbValidator = $this->createMock(\Magento\Setup\Validator\DbValidator::class);
31-
$configGenerator = $this->createMock(\Magento\Setup\Model\ConfigGenerator::class);
36+
$dbValidator = $this->createMock(DbValidator::class);
37+
$configGenerator = $this->createMock(ConfigGenerator::class);
3238

3339
$setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
3440
->create(
@@ -39,7 +45,7 @@ public function testCollectOptionsLists()
3945
]
4046
);
4147

42-
$serviceLocator = $this->getMockForAbstractClass(\Laminas\ServiceManager\ServiceLocatorInterface::class);
48+
$serviceLocator = $this->getMockForAbstractClass(ServiceLocatorInterface::class);
4349

4450
$serviceLocator->expects($this->once())
4551
->method('get')
@@ -51,7 +57,7 @@ public function testCollectOptionsLists()
5157
\Magento\Setup\Model\ConfigOptionsListCollector::class,
5258
[
5359
'objectManagerProvider' => $this->objectManagerProvider,
54-
'fullModuleList' => $fullModuleListMock,
60+
'componentRegistrar' => $componentRegistrar,
5561
'serviceLocator' => $serviceLocator
5662
]
5763
);

lib/internal/Magento/Framework/Module/DependencyChecker.php

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,32 @@
1313
class DependencyChecker
1414
{
1515
/**
16-
* Enabled module list from configuration
17-
*
18-
* @var array
19-
*/
20-
private $enabledModuleList;
21-
22-
/**
23-
* The full module list information from filesystem
24-
*
25-
* @var array
16+
* @var PackageInfo
2617
*/
27-
private $fullModuleList;
18+
private $packageInfo;
2819

2920
/**
30-
* Graph
31-
*
32-
* @var Graph
21+
* @var ModuleList
3322
*/
34-
private $graph;
23+
private $list;
3524

3625
/**
37-
* @var PackageInfo
26+
* @var ModuleList\Loader
3827
*/
39-
protected $packageInfo;
28+
private $loader;
4029

4130
/**
4231
* Constructor
4332
*
4433
* @param ModuleList $list
4534
* @param ModuleList\Loader $loader
46-
* @param PackageInfoFactory $packageInfoFactory
35+
* @param PackageInfo $packageInfo
4736
*/
48-
public function __construct(ModuleList $list, ModuleList\Loader $loader, PackageInfoFactory $packageInfoFactory)
37+
public function __construct(ModuleList $list, ModuleList\Loader $loader, PackageInfo $packageInfo)
4938
{
50-
$this->enabledModuleList = $list->getNames();
51-
$this->fullModuleList = $loader->load();
52-
$this->packageInfo = $packageInfoFactory->create();
39+
$this->list = $list;
40+
$this->loader = $loader;
41+
$this->packageInfo = $packageInfo;
5342
}
5443

5544
/**
@@ -58,10 +47,11 @@ public function __construct(ModuleList $list, ModuleList\Loader $loader, Package
5847
* @param string[] $toBeDisabledModules
5948
* @param string[] $currentlyEnabledModules
6049
* @return array
50+
* @throws \Magento\Framework\Exception\LocalizedException
6151
*/
6252
public function checkDependenciesWhenDisableModules($toBeDisabledModules, $currentlyEnabledModules = null)
6353
{
64-
$masterList = isset($currentlyEnabledModules) ? $currentlyEnabledModules : $this->enabledModuleList;
54+
$masterList = $currentlyEnabledModules ?? $this->list->getNames();
6555
// assume disable succeeds: currently enabled modules - to-be-disabled modules
6656
$enabledModules = array_diff($masterList, $toBeDisabledModules);
6757
return $this->checkDependencyGraph(false, $toBeDisabledModules, $enabledModules);
@@ -73,10 +63,11 @@ public function checkDependenciesWhenDisableModules($toBeDisabledModules, $curre
7363
* @param string[] $toBeEnabledModules
7464
* @param string[] $currentlyEnabledModules
7565
* @return array
66+
* @throws \Magento\Framework\Exception\LocalizedException
7667
*/
77-
public function checkDependenciesWhenEnableModules($toBeEnabledModules, $currentlyEnabledModules = null)
68+
public function checkDependenciesWhenEnableModules(array $toBeEnabledModules, array $currentlyEnabledModules = null)
7869
{
79-
$masterList = isset($currentlyEnabledModules) ? $currentlyEnabledModules : $this->enabledModuleList;
70+
$masterList = $currentlyEnabledModules ?? $this->list->getNames();
8071
// assume enable succeeds: union of currently enabled modules and to-be-enabled modules
8172
$enabledModules = array_unique(array_merge($masterList, $toBeEnabledModules));
8273
return $this->checkDependencyGraph(true, $toBeEnabledModules, $enabledModules);
@@ -89,19 +80,21 @@ public function checkDependenciesWhenEnableModules($toBeEnabledModules, $current
8980
* @param string[] $moduleNames list of modules to be enabled/disabled
9081
* @param string[] $enabledModules list of enabled modules assuming enable/disable succeeds
9182
* @return array
83+
* @throws \Magento\Framework\Exception\LocalizedException
9284
*/
93-
private function checkDependencyGraph($isEnable, $moduleNames, $enabledModules)
85+
private function checkDependencyGraph(bool $isEnable, array $moduleNames, array $enabledModules)
9486
{
95-
$this->graph = $this->createGraph();
87+
$fullModuleList = $this->loader->load();
88+
$graph = $this->createGraph($fullModuleList);
9689
$dependenciesMissingAll = [];
9790
$graphMode = $isEnable ? Graph::DIRECTIONAL : Graph::INVERSE;
91+
$modules = array_merge(
92+
array_keys($fullModuleList),
93+
$this->packageInfo->getNonExistingDependencies()
94+
);
9895
foreach ($moduleNames as $moduleName) {
9996
$dependenciesMissing = [];
100-
$paths = $this->graph->findPathsToReachableNodes($moduleName, $graphMode);
101-
$modules = array_merge(
102-
array_keys($this->fullModuleList),
103-
$this->packageInfo->getNonExistingDependencies()
104-
);
97+
$paths = $graph->findPathsToReachableNodes($moduleName, $graphMode);
10598
foreach ($modules as $module) {
10699
if (isset($paths[$module])) {
107100
if ($isEnable && !in_array($module, $enabledModules)) {
@@ -119,15 +112,16 @@ private function checkDependencyGraph($isEnable, $moduleNames, $enabledModules)
119112
/**
120113
* Create the dependency graph
121114
*
115+
* @param array $fullModuleList
122116
* @return Graph
123117
*/
124-
private function createGraph()
118+
private function createGraph(array $fullModuleList): Graph
125119
{
126120
$nodes = [];
127121
$dependencies = [];
128122

129123
// build the graph data
130-
foreach (array_keys($this->fullModuleList) as $moduleName) {
124+
foreach (array_keys($fullModuleList) as $moduleName) {
131125
$nodes[] = $moduleName;
132126
foreach ($this->packageInfo->getRequire($moduleName) as $dependModuleName) {
133127
if ($dependModuleName) {

lib/internal/Magento/Framework/Module/Dir/Reader.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ private function getFiles($filename, $subDir = '')
125125
{
126126
$result = [];
127127
foreach ($this->modulesList->getNames() as $moduleName) {
128-
$moduleSubDir = $this->getModuleDir($subDir, $moduleName);
128+
try {
129+
$moduleSubDir = $this->getModuleDir($subDir, $moduleName);
130+
} catch (\InvalidArgumentException $e) {
131+
continue;
132+
}
129133
$file = $moduleSubDir . '/' . $filename;
130134
$directoryRead = $this->readFactory->create($moduleSubDir);
131135
$path = $directoryRead->getRelativePath($file);

lib/internal/Magento/Framework/Module/Test/Unit/DependencyCheckerTest.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class DependencyCheckerTest extends TestCase
2727
*/
2828
private $packageInfoMock;
2929

30-
/**
31-
* @var PackageInfoFactory|MockObject
32-
*/
33-
private $packageInfoFactoryMock;
34-
3530
/**
3631
* @var ModuleList|MockObject
3732
*/
@@ -57,13 +52,8 @@ protected function setUp(): void
5752
->method('getRequire')
5853
->willReturnMap($requireMap);
5954

60-
$this->packageInfoFactoryMock = $this->createMock(PackageInfoFactory::class);
61-
$this->packageInfoFactoryMock->expects($this->once())
62-
->method('create')
63-
->willReturn($this->packageInfoMock);
64-
65-
$this->listMock = $this->createMock(ModuleList::class);
66-
$this->loaderMock = $this->createMock(Loader::class);
55+
$this->listMock = $this->createMock(\Magento\Framework\Module\ModuleList::class);
56+
$this->loaderMock = $this->createMock(\Magento\Framework\Module\ModuleList\Loader::class);
6757
$this->loaderMock
6858
->expects($this->any())
6959
->method('load')
@@ -78,7 +68,7 @@ public function testCheckDependenciesWhenDisableModules()
7868
$this->packageInfoMock->expects($this->atLeastOnce())
7969
->method('getNonExistingDependencies')
8070
->willReturn([]);
81-
$this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoFactoryMock);
71+
$this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoMock);
8272

8373
$actual = $this->checker->checkDependenciesWhenDisableModules(['B', 'D']);
8474
$expected = ['B' => ['A' => ['A', 'B']], 'D' => ['A' => ['A', 'B', 'D']]];
@@ -90,7 +80,7 @@ public function testCheckDependenciesWhenDisableModulesWithCurEnabledModules()
9080
$this->packageInfoMock->expects($this->atLeastOnce())
9181
->method('getNonExistingDependencies')
9282
->willReturn([]);
93-
$this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoFactoryMock);
83+
$this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoMock);
9484

9585
$actual = $this->checker->checkDependenciesWhenDisableModules(['B', 'D'], ['C', 'D', 'E']);
9686
$expected = ['B' => [], 'D' => []];
@@ -105,7 +95,7 @@ public function testCheckDependenciesWhenEnableModules()
10595
$this->packageInfoMock->expects($this->atLeastOnce())
10696
->method('getNonExistingDependencies')
10797
->willReturn([]);
108-
$this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoFactoryMock);
98+
$this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoMock);
10999
$actual = $this->checker->checkDependenciesWhenEnableModules(['B', 'D']);
110100
$expected = [
111101
'B' => ['A' => ['B', 'D', 'A'], 'E' => ['B', 'E']],
@@ -119,7 +109,7 @@ public function testCheckDependenciesWhenEnableModulesWithCurEnabledModules()
119109
$this->packageInfoMock->expects($this->atLeastOnce())
120110
->method('getNonExistingDependencies')
121111
->willReturn([]);
122-
$this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoFactoryMock);
112+
$this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoMock);
123113
$actual = $this->checker->checkDependenciesWhenEnableModules(['B', 'D'], ['C']);
124114
$expected = [
125115
'B' => ['A' => ['B', 'D', 'A'], 'E' => ['B', 'E']],

setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
namespace Magento\Setup\Model;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Component\ComponentRegistrar;
10+
use Magento\Framework\Component\ComponentRegistrarInterface;
911
use Magento\Framework\Filesystem;
10-
use Magento\Framework\Module\FullModuleList;
1112
use Magento\Framework\Setup\ConfigOptionsListInterface;
1213
use Laminas\ServiceManager\ServiceLocatorInterface;
1314

@@ -30,13 +31,6 @@ class ConfigOptionsListCollector
3031
*/
3132
private $filesystem;
3233

33-
/**
34-
* Module list including enabled and disabled modules
35-
*
36-
* @var FullModuleList
37-
*/
38-
private $fullModuleList;
39-
4034
/**
4135
* Object manager provider
4236
*
@@ -51,27 +45,34 @@ class ConfigOptionsListCollector
5145
*/
5246
private $serviceLocator;
5347

48+
/**
49+
* Component list
50+
*
51+
* @var ComponentRegistrarInterface
52+
*/
53+
private $componentRegistrar;
54+
5455
/**
5556
* Constructor
5657
*
5758
* @param DirectoryList $directoryList
5859
* @param Filesystem $filesystem
59-
* @param FullModuleList $fullModuleList
60+
* @param ComponentRegistrarInterface $componentRegistrar
6061
* @param ObjectManagerProvider $objectManagerProvider
6162
* @param ServiceLocatorInterface $serviceLocator
6263
*/
6364
public function __construct(
6465
DirectoryList $directoryList,
6566
Filesystem $filesystem,
66-
FullModuleList $fullModuleList,
67+
ComponentRegistrarInterface $componentRegistrar,
6768
ObjectManagerProvider $objectManagerProvider,
6869
ServiceLocatorInterface $serviceLocator
6970
) {
7071
$this->directoryList = $directoryList;
7172
$this->filesystem = $filesystem;
72-
$this->fullModuleList = $fullModuleList;
7373
$this->objectManagerProvider = $objectManagerProvider;
7474
$this->serviceLocator = $serviceLocator;
75+
$this->componentRegistrar = $componentRegistrar;
7576
}
7677

7778
/**
@@ -86,8 +87,8 @@ public function collectOptionsLists()
8687
{
8788
$optionsList = [];
8889

89-
// go through modules
90-
foreach ($this->fullModuleList->getNames() as $moduleName) {
90+
$modulePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
91+
foreach (array_keys($modulePaths) as $moduleName) {
9192
$optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptionsList';
9293
if (class_exists($optionsClassName)) {
9394
$optionsClass = $this->objectManagerProvider->get()->create($optionsClassName);

0 commit comments

Comments
 (0)