7
7
namespace Magento \FunctionalTestingFramework \Util ;
8
8
9
9
use Magento \FunctionalTestingFramework \Config \MftfApplicationConfig ;
10
+ use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
10
11
use Magento \FunctionalTestingFramework \Util \Logger \LoggingUtil ;
11
12
12
13
/**
@@ -138,10 +139,6 @@ public function getEnabledModules()
138
139
}
139
140
140
141
$ token = $ this ->getAdminToken ();
141
- if (!$ token || !is_string ($ token )) {
142
- $ this ->enabledModules = [];
143
- return $ this ->enabledModules ;
144
- }
145
142
146
143
$ url = ConfigSanitizerUtil::sanitizeUrl (getenv ('MAGENTO_BASE_URL ' )) . $ this ->moduleUrl ;
147
144
@@ -157,10 +154,17 @@ public function getEnabledModules()
157
154
$ response = curl_exec ($ ch );
158
155
159
156
if (!$ response ) {
160
- $ this ->enabledModules = [];
161
- } else {
162
- $ this ->enabledModules = json_decode ($ response );
157
+ $ message = "Could not retrieve Modules from Magento Instance. " ;
158
+ $ context = [
159
+ "Admin Module List Url " => $ url ,
160
+ "MAGENTO_ADMIN_USERNAME " => getenv ("MAGENTO_ADMIN_USERNAME " ),
161
+ "MAGENTO_ADMIN_PASSWORD " => getenv ("MAGENTO_ADMIN_PASSWORD " ),
162
+ ];
163
+ throw new TestFrameworkException ($ message , $ context );
163
164
}
165
+
166
+ $ this ->enabledModules = json_decode ($ response );
167
+
164
168
return $ this ->enabledModules ;
165
169
}
166
170
@@ -190,25 +194,14 @@ public function getModulesPath()
190
194
return $ this ->enabledModulePaths ;
191
195
}
192
196
193
- $ enabledModules = $ this ->getEnabledModules ();
194
- if (empty ($ enabledModules ) && !MftfApplicationConfig::getConfig ()->forceGenerateEnabled ()) {
195
- $ errorMsg = 'Could not retrieve enabled modules from provided MAGENTO_BASE_URL ' .
196
- 'please make sure Magento is available at this url ' ;
197
- LoggingUtil::getInstance ()->getLogger (ModuleResolver::class)->error (
198
- $ errorMsg ,
199
- ['MAGENTO_BASE_URL ' => getenv ('MAGENTO_BASE_URL ' )]
200
- );
201
- trigger_error ($ errorMsg , E_USER_ERROR );
202
- }
203
-
204
197
$ allModulePaths = $ this ->aggregateTestModulePaths ();
205
198
206
- if (empty ( $ enabledModules )) {
199
+ if (MftfApplicationConfig:: getConfig ()-> forceGenerateEnabled ( )) {
207
200
$ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ allModulePaths );
208
201
return $ this ->enabledModulePaths ;
209
202
}
210
203
211
- $ enabledModules = array_merge ($ enabledModules , $ this ->getModuleWhitelist ());
204
+ $ enabledModules = array_merge ($ this -> getEnabledModules () , $ this ->getModuleWhitelist ());
212
205
$ enabledDirectoryPaths = $ this ->getEnabledDirectoryPaths ($ enabledModules , $ allModulePaths );
213
206
214
207
$ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ enabledDirectoryPaths );
@@ -325,9 +318,15 @@ private function getEnabledDirectoryPaths($enabledModules, $allModulePaths)
325
318
{
326
319
$ enabledDirectoryPaths = [];
327
320
foreach ($ enabledModules as $ magentoModuleName ) {
328
- $ moduleShortName = explode ('_ ' , $ magentoModuleName )[1 ];
321
+ // Magento_Backend -> Backend or DevDocs -> DevDocs (if whitelisted has no underscore)
322
+ $ moduleShortName = explode ('_ ' , $ magentoModuleName )[1 ] ?? $ magentoModuleName ;
329
323
if (!isset ($ this ->knownDirectories [$ moduleShortName ]) && !isset ($ allModulePaths [$ moduleShortName ])) {
330
324
continue ;
325
+ } elseif (isset ($ this ->knownDirectories [$ moduleShortName ]) && !isset ($ allModulePaths [$ moduleShortName ])) {
326
+ LoggingUtil::getInstance ()->getLogger (ModuleResolver::class)->warn (
327
+ "Known directory could not match to an existing path. " ,
328
+ ['knownDirectory ' => $ moduleShortName ]
329
+ );
331
330
} else {
332
331
$ enabledDirectoryPaths [$ moduleShortName ] = $ allModulePaths [$ moduleShortName ];
333
332
}
@@ -342,7 +341,6 @@ private function getEnabledDirectoryPaths($enabledModules, $allModulePaths)
342
341
*/
343
342
private function printMagentoVersionInfo ()
344
343
{
345
-
346
344
if (MftfApplicationConfig::getConfig ()->forceGenerateEnabled ()) {
347
345
return ;
348
346
}
@@ -377,7 +375,13 @@ protected function getAdminToken()
377
375
$ login = $ _ENV ['MAGENTO_ADMIN_USERNAME ' ] ?? null ;
378
376
$ password = $ _ENV ['MAGENTO_ADMIN_PASSWORD ' ] ?? null ;
379
377
if (!$ login || !$ password || !isset ($ _ENV ['MAGENTO_BASE_URL ' ])) {
380
- return false ;
378
+ $ message = "Cannot retrieve API token without credentials and base url, please fill out .env. " ;
379
+ $ context = [
380
+ "MAGENTO_BASE_URL " => getenv ("MAGENTO_BASE_URL " ),
381
+ "MAGENTO_ADMIN_USERNAME " => getenv ("MAGENTO_ADMIN_USERNAME " ),
382
+ "MAGENTO_ADMIN_PASSWORD " => getenv ("MAGENTO_ADMIN_PASSWORD " ),
383
+ ];
384
+ throw new TestFrameworkException ($ message , $ context );
381
385
}
382
386
383
387
$ url = ConfigSanitizerUtil::sanitizeUrl ($ _ENV ['MAGENTO_BASE_URL ' ]) . $ this ->adminTokenUrl ;
@@ -398,9 +402,17 @@ protected function getAdminToken()
398
402
curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , false );
399
403
400
404
$ response = curl_exec ($ ch );
405
+
401
406
if (!$ response ) {
402
- return $ response ;
407
+ $ message = "Could not retrieve API token from Magento Instance. " ;
408
+ $ context = [
409
+ "Admin Integration Token Url " => $ url ,
410
+ "MAGENTO_ADMIN_USERNAME " => getenv ("MAGENTO_ADMIN_USERNAME " ),
411
+ "MAGENTO_ADMIN_PASSWORD " => getenv ("MAGENTO_ADMIN_PASSWORD " ),
412
+ ];
413
+ throw new TestFrameworkException ($ message , $ context );
403
414
}
415
+
404
416
return json_decode ($ response );
405
417
}
406
418
0 commit comments