Skip to content

Commit 3f1be46

Browse files
committed
MQE-1043: MFTF force flag should ignore the magento base url even when valid
- CR fixes
1 parent 5700373 commit 3f1be46

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Util/ModuleResolverTest.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use AspectMock\Proxy\Verifier;
1010
use AspectMock\Test as AspectMock;
1111

12+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
13+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1214
use Magento\FunctionalTestingFramework\ObjectManager;
1315
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1416
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
@@ -166,15 +168,41 @@ function ($arg1, $arg2) {
166168
}
167169

168170
/**
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
170172
* @throws \Exception
171173
*/
172174
public function testGetModulePathsNoAdminToken()
173175
{
176+
// Set --force to false
177+
$this->mockForceGenerate(false);
178+
179+
// Mock ModuleResolver and $enabledModulesPath
174180
$this->setMockResolverClass(false, null, ["example" . DIRECTORY_SEPARATOR . "paths"], []);
175181
$resolver = ModuleResolver::getInstance();
176182
$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);
178206
}
179207

180208
/**
@@ -260,6 +288,25 @@ private function setMockResolverProperties($instance, $mockPaths = null, $mockMo
260288
$property->setValue($instance, $mockBlacklist);
261289
}
262290

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+
263310
/**
264311
* After method functionality
265312
* @return void

0 commit comments

Comments
 (0)