Skip to content

Commit 87481ee

Browse files
committed
MQE-568: New .env file variable: CUSTOM_MODULE_PATHS
- add new custom module paths env - merge custom module paths to enbaledModules
1 parent 24838c5 commit 87481ee

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class ModuleResolver
1818
*/
1919
const MODULE_WHITELIST = 'MODULE_WHITELIST';
2020

21+
/**
22+
* Environment field name for custom module paths.
23+
*/
24+
const CUSTOM_MODULE_PATHS = 'CUSTOM_MODULE_PATHS';
25+
2126
/**
2227
* Enabled modules.
2328
*
@@ -166,15 +171,15 @@ protected function getModuleWhitelist()
166171
public function getModulesPath()
167172
{
168173
if (isset($this->enabledModulePaths)) {
169-
return $this->removeBlacklistModules($this->enabledModulePaths);
174+
return $this->enabledModulePaths;
170175
}
171176

172177
$enabledModules = $this->getEnabledModules();
173178
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP;
174179
$allModulePaths = glob($modulePath . '*/*');
175180
if (empty($enabledModules)) {
176-
$this->enabledModulePaths = $allModulePaths;
177-
return $this->removeBlacklistModules($this->enabledModulePaths);
181+
$this->enabledModulePaths = $this->applyCustomModuleMethods($allModulePaths);
182+
return $this->enabledModulePaths;
178183
}
179184

180185
$enabledModules = array_merge($enabledModules, $this->getModuleWhitelist());
@@ -191,8 +196,8 @@ public function getModulesPath()
191196
}
192197
}
193198

194-
$this->enabledModulePaths = $allModulePaths;
195-
return $this->removeBlacklistModules($this->enabledModulePaths);
199+
$this->enabledModulePaths = $this->applyCustomModuleMethods($allModulePaths);
200+
return $this->enabledModulePaths;
196201
}
197202

198203
/**
@@ -241,11 +246,23 @@ public function sortFilesByModuleSequence(array $files)
241246
return $this->sequenceSorter->sort($files);
242247
}
243248

249+
/**
250+
* A wrapping method for any custom logic which needs to be applied to the module list
251+
*
252+
* @param $modulesPath
253+
* @return array
254+
*/
255+
protected function applyCustomModuleMethods(&$modulesPath)
256+
{
257+
$this->removeBlacklistModules($modulesPath);
258+
return array_merge($modulesPath, $this->getCustomModulePaths());
259+
}
260+
244261
/**
245262
* Remove blacklist modules from input module paths.
246263
*
247264
* @param array &$modulePaths
248-
* @return array
265+
* @return void
249266
*/
250267
protected function removeBlacklistModules(&$modulePaths)
251268
{
@@ -254,7 +271,22 @@ protected function removeBlacklistModules(&$modulePaths)
254271
unset($modulePaths[$index]);
255272
}
256273
}
257-
return $modulePaths;
274+
}
275+
276+
/**
277+
* Returns an array of custom module paths defined by the user
278+
*
279+
* @return array
280+
*/
281+
protected function getCustomModulePaths()
282+
{
283+
$custom_module_paths = getenv(self::CUSTOM_MODULE_PATHS);
284+
285+
if (!$custom_module_paths) {
286+
return [];
287+
}
288+
289+
return array_map('trim', explode(',', $custom_module_paths));
258290
}
259291

260292
/**

0 commit comments

Comments
 (0)