@@ -58,6 +58,13 @@ class ModuleResolver
58
58
*/
59
59
protected $ moduleUrl = "rest/V1/modules " ;
60
60
61
+ /**
62
+ * Url for magento version information.
63
+ *
64
+ * @var string
65
+ */
66
+ protected $ versionUrl = "magento_version " ;
67
+
61
68
/**
62
69
* List of known directory that does not map to a Magento module.
63
70
*
@@ -123,13 +130,15 @@ public function getEnabledModules()
123
130
return $ this ->enabledModules ;
124
131
}
125
132
133
+ $ this ->printMagentoVersionInfo ();
134
+
126
135
$ token = $ this ->getAdminToken ();
127
136
if (!$ token || !is_string ($ token )) {
128
137
$ this ->enabledModules = [];
129
138
return $ this ->enabledModules ;
130
139
}
131
140
132
- $ url = $ _ENV ['MAGENTO_BASE_URL ' ] . $ this ->moduleUrl ;
141
+ $ url = ConfigSanitizerUtil:: sanitizeUrl ( $ _ENV ['MAGENTO_BASE_URL ' ]) . $ this ->moduleUrl ;
133
142
134
143
$ headers = [
135
144
'Authorization: Bearer ' . $ token ,
@@ -175,31 +184,60 @@ public function getModulesPath()
175
184
}
176
185
177
186
$ enabledModules = $ this ->getEnabledModules ();
187
+ $ forceGeneration = $ GLOBALS ['FORCE_PHP_GENERATE ' ] ?? false ;
188
+
189
+ if (empty ($ enabledModules ) && !$ forceGeneration ) {
190
+ trigger_error (
191
+ "Could not retrieve enabled modules from provided 'MAGENTO_BASE_URL', " .
192
+ "please make sure Magento is available at this url " ,
193
+ E_USER_ERROR
194
+ );
195
+ }
196
+
178
197
$ modulePath = defined ('TESTS_MODULE_PATH ' ) ? TESTS_MODULE_PATH : TESTS_BP ;
179
- $ allModulePaths = glob ($ modulePath . '*/* ' );
198
+
199
+ // Build an associative array of module name to existing module filepaths based on defined TEST MODULE PATH
200
+ $ allModulePaths = [];
201
+ foreach (glob ($ modulePath . '*/* ' ) as $ modPath ) {
202
+ $ modName = basename ($ modPath );
203
+ $ allModulePaths [$ modName ] = $ modPath ;
204
+ }
205
+
180
206
if (empty ($ enabledModules )) {
181
207
$ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ allModulePaths );
182
208
return $ this ->enabledModulePaths ;
183
209
}
184
210
185
211
$ enabledModules = array_merge ($ enabledModules , $ this ->getModuleWhitelist ());
186
- $ enabledDirectories = [];
187
- foreach ($ enabledModules as $ module ) {
188
- $ directoryName = explode ('_ ' , $ module )[1 ];
189
- $ enabledDirectories [$ directoryName ] = $ directoryName ;
190
- }
191
-
192
- foreach ($ allModulePaths as $ index => $ modulePath ) {
193
- $ moduleShortName = basename ($ modulePath );
194
- if (!isset ($ enabledDirectories [$ moduleShortName ]) && !isset ($ this ->knownDirectories [$ moduleShortName ])) {
195
- unset($ allModulePaths [$ index ]);
212
+ $ enabledDirectoryPaths = [];
213
+ foreach ($ enabledModules as $ magentoModuleName ) {
214
+ $ moduleShortName = explode ('_ ' , $ magentoModuleName )[1 ];
215
+ if (!isset ($ this ->knownDirectories [$ moduleShortName ]) && !isset ($ allModulePaths [$ moduleShortName ])) {
216
+ continue ;
217
+ } else {
218
+ $ enabledDirectoryPaths [$ moduleShortName ] = $ allModulePaths [$ moduleShortName ];
196
219
}
197
220
}
198
221
199
- $ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ allModulePaths );
222
+ $ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ enabledDirectoryPaths );
200
223
return $ this ->enabledModulePaths ;
201
224
}
202
225
226
+ /**
227
+ * Executes a REST call to the supplied Magento Base Url for version information to display during generation
228
+ *
229
+ * @return void
230
+ */
231
+ private function printMagentoVersionInfo ()
232
+ {
233
+ $ url = ConfigSanitizerUtil::sanitizeUrl ($ _ENV ['MAGENTO_BASE_URL ' ]) . $ this ->versionUrl ;
234
+ $ ch = curl_init ($ url );
235
+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , "GET " );
236
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
237
+ $ response = curl_exec ($ ch );
238
+ print "Version Information: {$ response }\n" ;
239
+ }
240
+
203
241
/**
204
242
* Get the API token for admin.
205
243
*
@@ -213,7 +251,7 @@ protected function getAdminToken()
213
251
return false ;
214
252
}
215
253
216
- $ url = $ _ENV ['MAGENTO_BASE_URL ' ] . $ this ->adminTokenUrl ;
254
+ $ url = ConfigSanitizerUtil:: sanitizeUrl ( $ _ENV ['MAGENTO_BASE_URL ' ]) . $ this ->adminTokenUrl ;
217
255
$ data = [
218
256
'username ' => $ login ,
219
257
'password ' => $ password
@@ -255,7 +293,13 @@ public function sortFilesByModuleSequence(array $files)
255
293
protected function applyCustomModuleMethods ($ modulesPath )
256
294
{
257
295
$ modulePathsResult = $ this ->removeBlacklistModules ($ modulesPath );
258
- return array_merge ($ modulePathsResult , $ this ->getCustomModulePaths ());
296
+ $ customModulePaths = $ this ->getCustomModulePaths ();
297
+
298
+ array_map (function ($ value ) {
299
+ print "Including module path: {$ value }\n" ;
300
+ }, $ customModulePaths );
301
+
302
+ return array_merge ($ modulePathsResult , $ customModulePaths );
259
303
}
260
304
261
305
/**
@@ -267,9 +311,10 @@ protected function applyCustomModuleMethods($modulesPath)
267
311
private function removeBlacklistModules ($ modulePaths )
268
312
{
269
313
$ modulePathsResult = $ modulePaths ;
270
- foreach ($ modulePathsResult as $ index => $ modulePath ) {
271
- if (in_array (basename ($ modulePath ), $ this ->getModuleBlacklist ())) {
272
- unset($ modulePathsResult [$ index ]);
314
+ foreach ($ modulePathsResult as $ moduleName => $ modulePath ) {
315
+ if (in_array ($ moduleName , $ this ->getModuleBlacklist ())) {
316
+ unset($ modulePathsResult [$ moduleName ]);
317
+ print "Excluding module: {$ moduleName }\n" ;
273
318
}
274
319
}
275
320
0 commit comments