Skip to content

Commit 7974e39

Browse files
committed
SEARCH-1968: Static tests to check for dependency of Elasticsearch modules.
1 parent 41631d5 commit 7974e39

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,4 +1202,92 @@ protected function _isFake($module)
12021202
{
12031203
return isset(self::$mapDependencies[$module]) ? false : true;
12041204
}
1205+
1206+
/**
1207+
* Test modules don't have direct dependencies on modules that might be disabled by 3rd-party Magento extensions.
1208+
*
1209+
* @inheritdoc
1210+
* @throws \Exception
1211+
* @return void
1212+
*/
1213+
public function testDirectExtensionDependencies()
1214+
{
1215+
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
1216+
1217+
// @todo - move to config
1218+
$extensionConflictList = [
1219+
// the following modules must be disabled when Live Search is used
1220+
// so core modules must not be dependent on them
1221+
'Magento\LiveSearch' => [
1222+
'Magento\Elasticsearch',
1223+
'Magento\Elasticsearch6',
1224+
'Magento\Elasticsearch7',
1225+
'Magento\ElasticsearchCatalogPermissions',
1226+
],
1227+
];
1228+
1229+
// @todo - move to config
1230+
$allowedDependencies = [
1231+
'Magento\Elasticsearch' => [
1232+
'Magento\Elasticsearch',
1233+
'Magento\Elasticsearch6',
1234+
'Magento\Elasticsearch7'
1235+
]
1236+
];
1237+
1238+
$invoker(
1239+
/**
1240+
* Check modules dependencies for specified file
1241+
*
1242+
* @param string $fileType
1243+
* @param string $file
1244+
*/
1245+
function ($fileType, $file) use ($extensionConflictList, $allowedDependencies) {
1246+
$module = $this->getModuleNameForRelevantFile($file);
1247+
if (!$module) {
1248+
return;
1249+
}
1250+
1251+
$contents = $this->_getCleanedFileContents($fileType, $file);
1252+
1253+
$dependencies = $this->getDependenciesFromFiles($module, $fileType, $file, $contents);
1254+
1255+
$modules = [];
1256+
foreach ($dependencies as $dependency) {
1257+
$modules[] = $dependency['modules'];
1258+
}
1259+
1260+
$modulesDependencies = array_merge(...$modules);
1261+
1262+
foreach ($extensionConflictList as $extension => $disabledModules) {
1263+
$foundedModules = \array_unique(array_intersect($modulesDependencies, $disabledModules));
1264+
if (!empty($foundedModules)) {
1265+
1266+
foreach ($foundedModules as $foundedModule) {
1267+
if (!empty($allowedDependencies[$foundedModule])
1268+
&& \in_array($module, $allowedDependencies[$foundedModule])
1269+
) {
1270+
// skip, this dependency is allowed
1271+
continue;
1272+
}
1273+
1274+
$this->fail(
1275+
\sprintf(
1276+
'Module "%s" has dependency on: "%s".' .
1277+
' No direct dependencies must be added on "%s",' .
1278+
' because it must be disabled when "%s" extension is used.' .
1279+
' See AC-2516 for more details',
1280+
$module,
1281+
\implode(', ', $foundedModules),
1282+
$module,
1283+
$extension
1284+
)
1285+
);
1286+
}
1287+
}
1288+
}
1289+
},
1290+
$this->getAllFiles()
1291+
);
1292+
}
12051293
}

0 commit comments

Comments
 (0)