|
9 | 9 | use AspectMock\Proxy\Verifier;
|
10 | 10 | use AspectMock\Test as AspectMock;
|
11 | 11 |
|
| 12 | +use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; |
| 13 | +use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; |
12 | 14 | use Magento\FunctionalTestingFramework\ObjectManager;
|
13 | 15 | use Magento\FunctionalTestingFramework\ObjectManagerFactory;
|
14 | 16 | use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
|
@@ -166,15 +168,41 @@ function ($arg1, $arg2) {
|
166 | 168 | }
|
167 | 169 |
|
168 | 170 | /**
|
169 |
| - * Validate that getEnabledModules returns correctly with no admin token |
| 171 | + * Validate that getEnabledModules errors out when no Admin Token is returned and --force is false |
170 | 172 | * @throws \Exception
|
171 | 173 | */
|
172 | 174 | public function testGetModulePathsNoAdminToken()
|
173 | 175 | {
|
| 176 | + // Set --force to false |
| 177 | + $this->mockForceGenerate(false); |
| 178 | + |
| 179 | + // Mock ModuleResolver and $enabledModulesPath |
174 | 180 | $this->setMockResolverClass(false, null, ["example" . DIRECTORY_SEPARATOR . "paths"], []);
|
175 | 181 | $resolver = ModuleResolver::getInstance();
|
176 | 182 | $this->setMockResolverProperties($resolver, null, null);
|
177 |
| - $this->assertEquals(["example" . DIRECTORY_SEPARATOR . "paths"], $resolver->getModulesPath()); |
| 183 | + |
| 184 | + // Cannot Generate if no --force was passed in and no Admin Token is returned succesfully |
| 185 | + $this->expectException(TestFrameworkException::class); |
| 186 | + $resolver->getModulesPath(); |
| 187 | + } |
| 188 | + |
| 189 | + /** |
| 190 | + * Validates that getAdminToken is not called when --force is enabled |
| 191 | + */ |
| 192 | + public function testGetAdminTokenNotCalledWhenForce() |
| 193 | + { |
| 194 | + // Set --force to true |
| 195 | + $this->mockForceGenerate(true); |
| 196 | + |
| 197 | + // Mock ModuleResolver and applyCustomModuleMethods() |
| 198 | + $mockResolver = $this->setMockResolverClass(); |
| 199 | + $resolver = ModuleResolver::getInstance(); |
| 200 | + $this->setMockResolverProperties($resolver, null, null); |
| 201 | + $resolver->getModulesPath(); |
| 202 | + $mockResolver->verifyNeverInvoked("getAdminToken"); |
| 203 | + |
| 204 | + // verifyNeverInvoked does not add to assertion count |
| 205 | + $this->addToAssertionCount(1); |
178 | 206 | }
|
179 | 207 |
|
180 | 208 | /**
|
@@ -260,6 +288,25 @@ private function setMockResolverProperties($instance, $mockPaths = null, $mockMo
|
260 | 288 | $property->setValue($instance, $mockBlacklist);
|
261 | 289 | }
|
262 | 290 |
|
| 291 | + /** |
| 292 | + * Mocks MftfApplicationConfig->forceGenerateEnabled() |
| 293 | + * @param $forceGenerate |
| 294 | + * @throws \Exception |
| 295 | + * @return void |
| 296 | + */ |
| 297 | + private function mockForceGenerate($forceGenerate) |
| 298 | + { |
| 299 | + $mockConfig = AspectMock::double( |
| 300 | + MftfApplicationConfig::class, |
| 301 | + ['forceGenerateEnabled' => $forceGenerate] |
| 302 | + ); |
| 303 | + $instance = AspectMock::double( |
| 304 | + ObjectManager::class, |
| 305 | + ['create' => $mockConfig->make(), 'get' => null] |
| 306 | + )->make(); |
| 307 | + AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]); |
| 308 | + } |
| 309 | + |
263 | 310 | /**
|
264 | 311 | * After method functionality
|
265 | 312 | * @return void
|
|
0 commit comments