Skip to content

Commit 803d6e3

Browse files
eddielauOlga Kopylova
authored andcommitted
MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI
- fixed PackageInfo loading fails when composer.json doesn't exist
1 parent bc2c3b9 commit 803d6e3

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public function setUp()
3131
->will($this->returnValue(['A' => [], 'B' => [], 'C' => [], 'D' => [], 'E' => []]));
3232

3333
$composerData = [
34-
'A' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}, "version":"0.1"}',
35-
'B' => '{"name":"b", "require":{"d":"0.3"}, "version":"0.2"}',
36-
'C' => '{"name":"c", "require":{"e":"0.1"}, "version":"0.1"}',
37-
'D' => '{"name":"d", "conflict":{"c":"0.1"}, "version":"0.3"}',
38-
'E' => '{"name":"e", "version":"0.4"}',
34+
'A/composer.json' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}, "version":"0.1"}',
35+
'B/composer.json' => '{"name":"b", "require":{"d":"0.3"}, "version":"0.2"}',
36+
'C/composer.json' => '{"name":"c", "require":{"e":"0.1"}, "version":"0.1"}',
37+
'D/composer.json' => '{"name":"d", "conflict":{"c":"0.1"}, "version":"0.3"}',
38+
'E/composer.json' => '{"name":"e", "version":"0.4"}',
3939
];
4040
$fileIteratorMock = $this->getMock('Magento\Framework\Config\FileIterator', [], [], '', false);
4141
$fileIteratorMock->expects($this->once())
@@ -45,7 +45,7 @@ public function setUp()
4545
->method('getComposerJsonFiles')
4646
->will($this->returnValue($fileIteratorMock));
4747

48-
$this->packageInfo = new PackageInfo($this->loader, $this->reader);
48+
$this->packageInfo = new PackageInfo($this->loader, $this->reader, new \Magento\Framework\Stdlib\String());
4949
}
5050

5151
public function testGetModuleName()

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Framework\Module;
77

8-
use Composer\Package\LinkConstraint\VersionConstraint;
98
use Composer\Package\Version\VersionParser;
109

1110
/**

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Framework\Module;
77

8+
use Magento\Framework\Stdlib\String;
9+
810
/**
911
* Provide information of dependencies and conflicts in composer.json files, mapping of package name to module name,
1012
* and mapping of module name to package version
@@ -53,16 +55,24 @@ class PackageInfo
5355
*/
5456
private $reader;
5557

58+
/**
59+
* String utilities
60+
*
61+
* @var String
62+
*/
63+
private $string;
64+
5665
/**
5766
* Constructor
5867
*
5968
* @param ModuleList\Loader $loader
6069
* @param Dir\Reader $reader
6170
*/
62-
public function __construct(ModuleList\Loader $loader, Dir\Reader $reader)
71+
public function __construct(ModuleList\Loader $loader, Dir\Reader $reader, String $string)
6372
{
6473
$this->loader = $loader;
6574
$this->reader = $reader;
75+
$this->string = $string;
6676
}
6777

6878
/**
@@ -77,13 +87,21 @@ private function load()
7787
* array keys: module name in module.xml; array values: raw content from composer.json
7888
* this raw data is used to create a dependency graph and also a package name-module name mapping
7989
*/
80-
$rawData = array_combine(
81-
array_keys($this->loader->load()),
82-
$this->reader->getComposerJsonFiles()->toArray()
83-
);
90+
$rawData = [];
91+
$jsonData = $this->reader->getComposerJsonFiles()->toArray();
92+
foreach (array_keys($this->loader->load()) as $moduleName) {
93+
$key = $this->string->upperCaseWords($moduleName, '_', '/') . '/composer.json';
94+
if (isset($jsonData[$key])) {
95+
$rawData[$moduleName] = $jsonData[$key];
96+
} else {
97+
$rawData[$moduleName] = '{}';
98+
}
99+
}
84100
foreach ($rawData as $moduleName => $jsonData) {
85101
$jsonData = \Zend_Json::decode($jsonData);
86-
$this->packageModuleMap[$jsonData['name']] = $moduleName;
102+
if (isset($jsonData['name'])) {
103+
$this->packageModuleMap[$jsonData['name']] = $moduleName;
104+
}
87105
if (isset($jsonData['version'])) {
88106
$this->modulePackageVersionMap[$moduleName] = $jsonData['version'];
89107
}

0 commit comments

Comments
 (0)