Skip to content

Commit e3c733a

Browse files
committed
MAGETWO-56042: The module which do not have composer.json file shows on the grid with empty data
- Update unit test
1 parent 92997ce commit e3c733a

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

setup/src/Magento/Setup/Model/Grid/Module.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
*/
2020
class Module
2121
{
22+
/**
23+
* Const for unknown package name and version
24+
*/
25+
const UNKNOWN_PACKAGE_NAME = 'unknown';
26+
const UNKNOWN_VERSION = '';
27+
2228
/**
2329
* @var ComposerInformation
2430
*/
@@ -128,11 +134,11 @@ private function getModuleRequiredBy($name)
128134
foreach ($modules as $moduleName) {
129135
$packageName = $this->packageInfo->getPackageName($moduleName);
130136
$result[] = [
131-
'name' => $packageName ?: 'unknown',
137+
'name' => $packageName ?: self::UNKNOWN_PACKAGE_NAME,
132138
'moduleName' => $moduleName,
133139
'type' => $this->typeMapper->map($packageName, ComposerInformation::MODULE_PACKAGE_TYPE),
134140
'enable' => $this->moduleList->has($moduleName),
135-
'version' => $this->packageInfo->getVersion($moduleName) ?: ''
141+
'version' => $this->packageInfo->getVersion($moduleName) ?: self::UNKNOWN_VERSION
136142
];
137143
}
138144

@@ -151,10 +157,10 @@ private function getInstalledModules()
151157
foreach ($allModules as $module) {
152158
$packageName = $this->packageInfo->getPackageName($module);
153159
$name = $packageName ?: $module;
154-
$modules[$name]['name'] = $packageName ?: 'unknown';
160+
$modules[$name]['name'] = $packageName ?: self::UNKNOWN_PACKAGE_NAME;
155161
$modules[$name]['moduleName'] = $module;
156162
$modules[$name]['type'] = ComposerInformation::MODULE_PACKAGE_TYPE;
157-
$modules[$name]['version'] = $this->packageInfo->getVersion($module) ?: '';
163+
$modules[$name]['version'] = $this->packageInfo->getVersion($module) ?: self::UNKNOWN_VERSION;
158164
}
159165

160166
return $modules;

setup/src/Magento/Setup/Test/Unit/Model/Grid/ModuleTest.php

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,12 @@ public function setUp()
9191
'version' => '1.0.0'
9292
]
9393
];
94-
$this->allComponentData = [
95-
'magento/sample-module-one' => [
96-
'name' => 'magento/sample-module-one',
97-
'type' => 'magento2-module',
98-
'version' => '1.0.0'
99-
],
100-
'magento/sample-module-two' => [
101-
'name' => 'magento/sample-module-two',
102-
'type' => 'magento2-module',
103-
'version' => '1.0.0'
104-
]
94+
95+
$fullModuleList = [
96+
'Sample_ModuleOne', 'Sample_ModuleTwo'
10597
];
10698

99+
107100
$this->composerInformationMock = $this->getMockBuilder(ComposerInformation::class)
108101
->disableOriginalConstructor()
109102
->getMock();
@@ -126,7 +119,7 @@ public function setUp()
126119
->getMock();
127120
$this->fullModuleListMock->expects(static::any())
128121
->method('getNames')
129-
->willReturn(array_keys($this->allComponentData));
122+
->willReturn($fullModuleList);
130123

131124
$this->packageInfoMock = $this->getMockBuilder(PackageInfo::class)
132125
->disableOriginalConstructor()
@@ -165,18 +158,14 @@ public function testGetList()
165158
->method('create')
166159
->willReturn($this->packageInfoMock);
167160

168-
$this->packageInfoMock->expects(static::exactly(2))
169-
->method('getModuleName')
170-
->willReturnMap([
171-
['magento/sample-module-one', 'Sample_Module_One'],
172-
['magento/sample-module-two', 'Sample_Module_Two'],
173-
]);
161+
$this->packageInfoMock->expects(static::never())
162+
->method('getModuleName');
174163

175164
$this->typeMapperMock->expects(static::exactly(2))
176165
->method('map')
177166
->willReturnMap([
178167
['magento/sample-module-one', 'magento2-module', 'Module'],
179-
['magento/sample-module-two', 'magento2-module', 'Module'],
168+
['Sample_ModuleTwo', 'magento2-module', 'Module'],
180169
]);
181170

182171
$this->packageInfoMock->expects(static::exactly(2))
@@ -185,14 +174,14 @@ public function testGetList()
185174
$this->packageInfoMock->expects(static::exactly(2))
186175
->method('getPackageName')
187176
->willReturnMap([
188-
['magento/sample-module-one', $this->allComponentData['magento/sample-module-one']['name']],
189-
['magento/sample-module-two', $this->allComponentData['magento/sample-module-two']['name']],
177+
['Sample_ModuleOne', 'magento/sample-module-one'],
178+
['Sample_ModuleTwo', ''],
190179
]);
191180
$this->packageInfoMock->expects(static::exactly(2))
192181
->method('getVersion')
193182
->willReturnMap([
194-
['magento/sample-module-one', $this->allComponentData['magento/sample-module-one']['version']],
195-
['magento/sample-module-two', $this->allComponentData['magento/sample-module-two']['version']],
183+
['Sample_ModuleOne', '1.0.0'],
184+
['Sample_ModuleTwo', ''],
196185
]);
197186
$this->moduleListMock->expects(static::exactly(2))
198187
->method('has')
@@ -207,16 +196,16 @@ public function testGetList()
207196
'type' => 'Module',
208197
'version' => '1.0.0',
209198
'vendor' => 'Magento',
210-
'moduleName' => 'Sample_Module_One',
199+
'moduleName' => 'Sample_ModuleOne',
211200
'enable' => true,
212201
'requiredBy' => []
213202
],
214203
[
215-
'name' => 'magento/sample-module-two',
204+
'name' => Module::UNKNOWN_PACKAGE_NAME,
216205
'type' => 'Module',
217-
'version' => '1.0.0',
218-
'vendor' => 'Magento',
219-
'moduleName' => 'Sample_Module_Two',
206+
'version' => Module::UNKNOWN_VERSION,
207+
'vendor' => 'Sample',
208+
'moduleName' => 'Sample_ModuleTwo',
220209
'enable' => true,
221210
'requiredBy' => []
222211
]

0 commit comments

Comments
 (0)