Skip to content

Commit 83cbaa8

Browse files
author
Dale Sikkema
committed
Merge branch 'MAGETWO-40092-dependency-test' into develop
2 parents 4dc7e2f + 874eb7f commit 83cbaa8

File tree

10 files changed

+250
-42
lines changed

10 files changed

+250
-42
lines changed

app/code/Magento/CatalogRule/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
"magento/module-customer": "1.0.0-beta",
1010
"magento/module-backend": "1.0.0-beta",
1111
"magento/module-eav": "1.0.0-beta",
12-
"magento/module-import-export": "1.0.0-beta",
1312
"magento/framework": "1.0.0-beta",
1413
"magento/magento-composer-installer": "*"
1514
},
15+
"suggest": {
16+
"magento/module-import-export": "1.0.0-beta"
17+
},
1618
"type": "magento2-module",
1719
"version": "1.0.0-beta",
1820
"license": [

app/code/Magento/ConfigurableProduct/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"magento/module-store": "1.0.0-beta",
77
"magento/module-catalog": "1.0.0-beta",
88
"magento/module-catalog-inventory": "1.0.0-beta",
9-
"magento/module-sales": "1.0.0-beta",
109
"magento/module-checkout": "1.0.0-beta",
1110
"magento/module-msrp": "1.0.0-beta",
1211
"magento/module-backend": "1.0.0-beta",
@@ -20,7 +19,8 @@
2019
"magento/magento-composer-installer": "*"
2120
},
2221
"suggest": {
23-
"magento/module-webapi": "1.0.0-beta"
22+
"magento/module-webapi": "1.0.0-beta",
23+
"magento/module-sales": "1.0.0-beta"
2424
},
2525
"type": "magento2-module",
2626
"version": "1.0.0-beta",

app/code/Magento/Cron/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
"description": "N/A",
44
"require": {
55
"php": "~5.5.0|~5.6.0|~7.0.0",
6-
"magento/module-config": "1.0.0-beta",
76
"magento/module-store": "1.0.0-beta",
87
"magento/framework": "1.0.0-beta",
98
"magento/magento-composer-installer": "*"
109
},
10+
"suggest": {
11+
"magento/module-config": "1.0.0-beta"
12+
},
1113
"type": "magento2-module",
1214
"version": "1.0.0-beta",
1315
"license": [

app/code/Magento/Dhl/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
"magento/module-backend": "1.0.0-beta",
1010
"magento/module-directory": "1.0.0-beta",
1111
"magento/module-sales": "1.0.0-beta",
12-
"magento/module-checkout": "1.0.0-beta",
1312
"magento/module-catalog": "1.0.0-beta",
1413
"magento/module-catalog-inventory": "1.0.0-beta",
1514
"magento/module-quote": "1.0.0-beta",
1615
"magento/framework": "1.0.0-beta",
1716
"lib-libxml": "*",
1817
"magento/magento-composer-installer": "*"
1918
},
19+
"suggest": {
20+
"magento/module-checkout": "1.0.0-beta"
21+
},
2022
"type": "magento2-module",
2123
"version": "1.0.0-beta",
2224
"license": [

app/code/Magento/GiftMessage/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"magento/module-store": "1.0.0-beta",
77
"magento/module-catalog": "1.0.0-beta",
88
"magento/module-checkout": "1.0.0-beta",
9-
"magento/module-multishipping": "1.0.0-beta",
109
"magento/module-sales": "1.0.0-beta",
1110
"magento/module-backend": "1.0.0-beta",
1211
"magento/module-customer": "1.0.0-beta",
@@ -15,6 +14,9 @@
1514
"magento/framework": "1.0.0-beta",
1615
"magento/magento-composer-installer": "*"
1716
},
17+
"suggest": {
18+
"magento/module-multishipping": "1.0.0-beta"
19+
},
1820
"type": "magento2-module",
1921
"version": "1.0.0-beta",
2022
"license": [

app/code/Magento/Msrp/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"require": {
55
"php": "~5.5.0|~5.6.0|~7.0.0",
66
"magento/module-store": "1.0.0-beta",
7-
"magento/module-bundle": "1.0.0-beta",
87
"magento/module-catalog": "1.0.0-beta",
98
"magento/module-downloadable": "1.0.0-beta",
109
"magento/module-eav": "1.0.0-beta",
@@ -14,6 +13,9 @@
1413
"magento/framework": "1.0.0-beta",
1514
"magento/magento-composer-installer": "*"
1615
},
16+
"suggest": {
17+
"magento/module-bundle": "1.0.0-beta"
18+
},
1719
"type": "magento2-module",
1820
"version": "1.0.0-beta",
1921
"license": [

app/code/Magento/OfflineShipping/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
"magento/module-sales": "1.0.0-beta",
1212
"magento/module-sales-rule": "1.0.0-beta",
1313
"magento/module-directory": "1.0.0-beta",
14-
"magento/module-checkout": "1.0.0-beta",
1514
"magento/module-quote": "1.0.0-beta",
1615
"magento/framework": "1.0.0-beta",
1716
"magento/magento-composer-installer": "*"
1817
},
18+
"suggest": {
19+
"magento/module-checkout": "1.0.0-beta"
20+
},
1921
"type": "magento2-module",
2022
"version": "1.0.0-beta",
2123
"license": [

app/code/Magento/Swatches/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
"magento/module-backend": "1.0.0-beta",
1212
"magento/module-media-storage": "1.0.0-beta",
1313
"magento/module-config": "1.0.0-beta",
14-
"magento/module-layered-navigation": "1.0.0-beta",
1514
"magento/module-theme": "1.0.0-beta",
1615
"magento/framework": "1.0.0-beta",
1716
"magento/magento-composer-installer": "*"
1817
},
18+
"suggest": {
19+
"magento/module-layered-navigation": "1.0.0-beta"
20+
},
1921
"type": "magento2-module",
2022
"version": "1.0.0-beta",
2123
"license": [

dev/tests/static/framework/Magento/TestFramework/Dependency/PhpRule.php

Lines changed: 110 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,25 @@
77
*/
88
namespace Magento\TestFramework\Dependency;
99

10-
class PhpRule implements \Magento\TestFramework\Dependency\RuleInterface
10+
use Magento\Framework\App\Utility\Files;
11+
use Magento\TestFramework\Dependency\RuleInterface;
12+
13+
class PhpRule implements RuleInterface
1114
{
15+
/**
16+
* List of filepaths for DI files
17+
*
18+
* @var array
19+
*/
20+
private $diFiles;
21+
22+
/**
23+
* Map from plugin classes to the subjects they modify
24+
*
25+
* @var array
26+
*/
27+
private $pluginMap;
28+
1229
/**
1330
* List of routers
1431
*
@@ -47,12 +64,14 @@ class PhpRule implements \Magento\TestFramework\Dependency\RuleInterface
4764
*
4865
* @param array $mapRouters
4966
* @param array $mapLayoutBlocks
67+
* @param array $pluginMap
5068
*/
51-
public function __construct(array $mapRouters, array $mapLayoutBlocks)
69+
public function __construct(array $mapRouters, array $mapLayoutBlocks, array $pluginMap = [])
5270
{
5371
$this->_mapRouters = $mapRouters;
5472
$this->_mapLayoutBlocks = $mapLayoutBlocks;
5573
$this->_namespaces = implode('|', \Magento\Framework\App\Utility\Files::init()->getNamespaces());
74+
$this->pluginMap = $pluginMap ?: null;
5675
}
5776

5877
/**
@@ -72,7 +91,7 @@ public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
7291

7392
$pattern = '~\b(?<class>(?<module>(' . implode(
7493
'_|',
75-
\Magento\Framework\App\Utility\Files::init()->getNamespaces()
94+
Files::init()->getNamespaces()
7695
) . '[_\\\\])[a-zA-Z0-9]+)[a-zA-Z0-9_\\\\]*)\b~';
7796

7897
$dependenciesInfo = [];
@@ -83,10 +102,16 @@ public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
83102
if ($currentModule == $referenceModule) {
84103
continue;
85104
}
105+
$dependencyClass = trim($matches['class'][$i]);
106+
$currentClass = $this->getClassFromFilepath($file, $currentModule);
107+
$dependencyType = $this->isPluginDependency($currentClass, $dependencyClass)
108+
? RuleInterface::TYPE_SOFT
109+
: RuleInterface::TYPE_HARD;
110+
86111
$dependenciesInfo[] = [
87112
'module' => $referenceModule,
88-
'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD,
89-
'source' => trim($matches['class'][$i]),
113+
'type' => $dependencyType,
114+
'source' => $dependencyClass,
90115
];
91116
}
92117
}
@@ -102,6 +127,84 @@ public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
102127
return $dependenciesInfo;
103128
}
104129

130+
/**
131+
* Get class name from filename based on class/file naming conventions
132+
*
133+
* @param string $filepath
134+
* @param string $module
135+
* @return string
136+
*/
137+
private function getClassFromFilepath($filepath, $module)
138+
{
139+
$class = strstr($filepath, str_replace(['_', '\\', '/'], DIRECTORY_SEPARATOR, $module));
140+
$class = str_replace(DIRECTORY_SEPARATOR, '\\', strstr($class, '.php', true));
141+
return $class;
142+
}
143+
144+
/**
145+
* @return array
146+
* @throws \Exception
147+
*/
148+
private function loadDiFiles()
149+
{
150+
if (!$this->diFiles) {
151+
$this->diFiles = Files::init()->getDiConfigs();
152+
}
153+
return $this->diFiles;
154+
}
155+
156+
/**
157+
* Generate an array of plugin info
158+
*
159+
* @return array
160+
*/
161+
private function loadPluginMap()
162+
{
163+
if (!$this->pluginMap) {
164+
foreach ($this->loadDiFiles() as $filepath) {
165+
$dom = new \DOMDocument();
166+
$dom->loadXML(file_get_contents($filepath));
167+
$typeNodes = $dom->getElementsByTagName('type');
168+
/** @var \DOMElement $type */
169+
foreach ($typeNodes as $type) {
170+
/** @var \DOMElement $plugin */
171+
foreach ($type->getElementsByTagName('plugin') as $plugin) {
172+
$subject = $type->getAttribute('name');
173+
$pluginType = $plugin->getAttribute('type');
174+
$this->pluginMap[$pluginType] = $subject;
175+
}
176+
}
177+
}
178+
}
179+
return $this->pluginMap;
180+
}
181+
182+
/**
183+
* Determine whether a the dependency relation is because of a plugin
184+
*
185+
* True IFF the dependent is a plugin for some class in the same module as the dependency.
186+
*
187+
* @param string $dependent
188+
* @param string $dependency
189+
* @return bool
190+
*/
191+
private function isPluginDependency($dependent, $dependency)
192+
{
193+
$pluginMap = $this->loadPluginMap();
194+
$subject = isset($pluginMap[$dependent])
195+
? $pluginMap[$dependent]
196+
: null;
197+
if ($subject === $dependency) {
198+
return true;
199+
} else if ($subject) {
200+
$subjectModule = substr($subject, 0, strpos($subject, '\\', 9)); // (strlen('Magento\\') + 1) === 9
201+
return strpos($dependency, $subjectModule) === 0;
202+
} else {
203+
return false;
204+
}
205+
}
206+
207+
105208
/**
106209
* Check get URL method
107210
*
@@ -128,7 +231,7 @@ protected function _caseGetUrl($currentModule, &$contents)
128231
foreach ($modules as $module) {
129232
$dependencies[] = [
130233
'module' => $module,
131-
'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD,
234+
'type' => RuleInterface::TYPE_HARD,
132235
'source' => $item['source'],
133236
];
134237
}
@@ -166,7 +269,7 @@ protected function _caseLayoutBlock($currentModule, $fileType, $file, &$contents
166269
$module = isset($check['module']) ? $check['module'] : null;
167270
if ($module) {
168271
$result[$module] = [
169-
'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD,
272+
'type' => RuleInterface::TYPE_HARD,
170273
'source' => $match['source'],
171274
];
172275
}

0 commit comments

Comments
 (0)