@@ -56,9 +56,10 @@ public function testGetModulePathsAlreadySet()
56
56
*/
57
57
public function testGetModulePathsAggregate ()
58
58
{
59
- $ this ->setMockResolverClass (false , null , null , null , ["example " . DIRECTORY_SEPARATOR . "paths " ]);
59
+ $ this ->mockForceGenerate (false );
60
+ $ this ->setMockResolverClass (false , null , null , null , ["example " => "example " . DIRECTORY_SEPARATOR . "paths " ]);
60
61
$ resolver = ModuleResolver::getInstance ();
61
- $ this ->setMockResolverProperties ($ resolver , null , null );
62
+ $ this ->setMockResolverProperties ($ resolver , null , [ 0 => " Magento_example " ] );
62
63
$ this ->assertEquals (
63
64
[
64
65
"example " . DIRECTORY_SEPARATOR . "paths " ,
@@ -75,12 +76,13 @@ public function testGetModulePathsAggregate()
75
76
*/
76
77
public function testGetModulePathsLocations ()
77
78
{
79
+ $ this ->mockForceGenerate (false );
78
80
$ mockResolver = $ this ->setMockResolverClass (
79
- false ,
80
- null ,
81
+ true ,
82
+ [ 0 => " magento_example " ] ,
81
83
null ,
82
84
null ,
83
- ["example " . DIRECTORY_SEPARATOR . "paths " ]
85
+ ["example " => " example " . DIRECTORY_SEPARATOR . "paths " ]
84
86
);
85
87
$ resolver = ModuleResolver::getInstance ();
86
88
$ this ->setMockResolverProperties ($ resolver , null , null );
@@ -205,6 +207,43 @@ public function testGetAdminTokenNotCalledWhenForce()
205
207
$ this ->addToAssertionCount (1 );
206
208
}
207
209
210
+ /**
211
+ * Verify the getAdminToken method returns throws an exception if ENV is not fully loaded.
212
+ */
213
+ public function testGetAdminTokenWithMissingEnv ()
214
+ {
215
+ // Set --force to true
216
+ $ this ->mockForceGenerate (false );
217
+
218
+ // Unset env
219
+ unset($ _ENV ['MAGENTO_ADMIN_USERNAME ' ]);
220
+
221
+ // Mock ModuleResolver and applyCustomModuleMethods()
222
+ $ mockResolver = $ this ->setMockResolverClass ();
223
+ $ resolver = ModuleResolver::getInstance ();
224
+
225
+ // Expect exception
226
+ $ this ->expectException (TestFrameworkException::class);
227
+ $ resolver ->getModulesPath ();
228
+ }
229
+
230
+ /**
231
+ * Verify the getAdminToken method returns throws an exception if Token was bad.
232
+ */
233
+ public function testGetAdminTokenWithBadResponse ()
234
+ {
235
+ // Set --force to true
236
+ $ this ->mockForceGenerate (false );
237
+
238
+ // Mock ModuleResolver and applyCustomModuleMethods()
239
+ $ mockResolver = $ this ->setMockResolverClass ();
240
+ $ resolver = ModuleResolver::getInstance ();
241
+
242
+ // Expect exception
243
+ $ this ->expectException (TestFrameworkException::class);
244
+ $ resolver ->getModulesPath ();
245
+ }
246
+
208
247
/**
209
248
* Function used to set mock for parser return and force init method to run between tests.
210
249
*
@@ -233,7 +272,7 @@ private function setMockResolverClass(
233
272
if (isset ($ mockToken )) {
234
273
$ mockMethods ['getAdminToken ' ] = $ mockToken ;
235
274
}
236
- if (isset ($ mockModules )) {
275
+ if (isset ($ mockGetModules )) {
237
276
$ mockMethods ['getEnabledModules ' ] = $ mockGetModules ;
238
277
}
239
278
if (isset ($ mockCustomMethods )) {
@@ -248,7 +287,7 @@ private function setMockResolverClass(
248
287
if (isset ($ mockCustomModules )) {
249
288
$ mockMethods ['getCustomModulePaths ' ] = $ mockCustomModules ;
250
289
}
251
- $ mockMethods ['printMagentoVersionInfo ' ] = null ;
290
+ // $mockMethods['printMagentoVersionInfo'] = null;
252
291
253
292
$ mockResolver = AspectMock::double (
254
293
ModuleResolver::class,
@@ -313,6 +352,11 @@ private function mockForceGenerate($forceGenerate)
313
352
*/
314
353
protected function tearDown ()
315
354
{
355
+ // re set env
356
+ if (!isset ($ _ENV ['MAGENTO_ADMIN_USERNAME ' ])) {
357
+ $ _ENV ['MAGENTO_ADMIN_USERNAME ' ] = "admin " ;
358
+ }
359
+
316
360
AspectMock::clean ();
317
361
}
318
362
}
0 commit comments