Skip to content

Commit 0daf945

Browse files
committed
MQE-1650: Update MFTF configuration to read Test entities from new location
- fix unit tests
1 parent 371f22d commit 0daf945

File tree

5 files changed

+113
-41
lines changed

5 files changed

+113
-41
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Handlers/TestObjectHandlerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function testGetTestWithModuleName()
181181
->build();
182182

183183
$resolverMock = new MockModuleResolverBuilder();
184-
$resolverMock->setup(['Vendor_' . $moduleExpected => [$filepath]]);
184+
$resolverMock->setup(['Vendor_' . $moduleExpected => $filepath]);
185185

186186
$this->setMockParserOutput(['tests' => $mockData]);
187187
// Execute Test Method
@@ -209,6 +209,8 @@ public function testGetTestObjectWithInvalidExtends()
209209
->withBeforeHook()
210210
->withTestActions()
211211
->build();
212+
$resolverMock = new MockModuleResolverBuilder();
213+
$resolverMock->setup();
212214
$this->setMockParserOutput(['tests' => $testOne]);
213215

214216
$toh = TestObjectHandler::getInstance();
@@ -245,6 +247,8 @@ public function testGetAllTestObjectsWithInvalidExtends()
245247
->withTestActions()
246248
->build();
247249

250+
$resolverMock = new MockModuleResolverBuilder();
251+
$resolverMock->setup();
248252
$this->setMockParserOutput(['tests' => array_merge($testOne, $testTwo)]);
249253

250254
$toh = TestObjectHandler::getInstance();

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

Lines changed: 93 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,29 @@ public function testGetModulePathsAlreadySet()
5656
*/
5757
public function testGetModulePathsAggregate()
5858
{
59+
5960
$this->mockForceGenerate(false);
6061
$this->setMockResolverClass(
6162
false,
6263
null,
6364
null,
6465
null,
65-
["Magento_example" => "example" . DIRECTORY_SEPARATOR . "paths"]
66+
[
67+
'some' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'example' => ['example'],
68+
'other' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'sample' => ['sample'],
69+
],
70+
null,
71+
[
72+
'Magento_example' => 'some' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'example',
73+
'Magento_sample' => 'other' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'sample',
74+
]
6675
);
6776
$resolver = ModuleResolver::getInstance();
68-
$this->setMockResolverProperties($resolver, null, [0 => "Magento_example"]);
77+
$this->setMockResolverProperties($resolver, null, [0 => 'Magento_example', 1 => 'Magento_sample']);
6978
$this->assertEquals(
7079
[
71-
"example" . DIRECTORY_SEPARATOR . "paths",
72-
"example" . DIRECTORY_SEPARATOR . "paths",
73-
"example" . DIRECTORY_SEPARATOR . "paths",
74-
"example" . DIRECTORY_SEPARATOR . "paths"
80+
'some' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'example',
81+
'other' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'sample'
7582
],
7683
$resolver->getModulesPath()
7784
);
@@ -91,20 +98,28 @@ public function testGetModulePathsLocations()
9198
$this->mockForceGenerate(false);
9299
$mockResolver = $this->setMockResolverClass(
93100
true,
94-
[0 => "example"],
101+
[],
95102
null,
96103
null,
97-
["example" => "example" . DIRECTORY_SEPARATOR . "paths"]
104+
[],
105+
[],
106+
[],
107+
[],
108+
[],
109+
[],
110+
[],
111+
null,
112+
function ($arg) {
113+
return $arg;
114+
},
115+
function ($arg) {
116+
return $arg;
117+
}
98118
);
99119
$resolver = ModuleResolver::getInstance();
100120
$this->setMockResolverProperties($resolver, null, null);
101121
$this->assertEquals(
102-
[
103-
"example" . DIRECTORY_SEPARATOR . "paths",
104-
"example" . DIRECTORY_SEPARATOR . "paths",
105-
"example" . DIRECTORY_SEPARATOR . "paths",
106-
"example" . DIRECTORY_SEPARATOR . "paths"
107-
],
122+
[],
108123
$resolver->getModulesPath()
109124
);
110125

@@ -114,8 +129,6 @@ public function testGetModulePathsLocations()
114129
// Define the Module paths from default TESTS_MODULE_PATH
115130
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP;
116131

117-
118-
119132
$mockResolver->verifyInvoked('globRelevantPaths', [$modulePath, '']);
120133
$mockResolver->verifyInvoked(
121134
'globRelevantPaths',
@@ -150,14 +163,21 @@ public function testGetModulePathsLocations()
150163
*/
151164
public function testGetCustomModulePath()
152165
{
153-
$this->setMockResolverClass(false, ["Magento_TestModule"], null, null, [], ['otherPath']);
166+
$this->setMockResolverClass(
167+
false,
168+
null,
169+
null,
170+
null,
171+
[],
172+
['Magento_Module' => 'otherPath']
173+
);
154174
$resolver = ModuleResolver::getInstance();
155175
$this->setMockResolverProperties($resolver, null, null, null);
156176
$this->assertEquals(['otherPath'], $resolver->getModulesPath());
157177
TestLoggingUtil::getInstance()->validateMockLogStatement(
158178
'info',
159179
'including custom module',
160-
['module' => 'otherPath']
180+
['Magento_Module' => 'otherPath']
161181
);
162182
}
163183

@@ -172,25 +192,36 @@ public function testGetModulePathsBlacklist()
172192
null,
173193
null,
174194
null,
175-
function ($arg1, $arg2) {
176-
if ($arg2 === "") {
177-
$mockValue = ["somePath" => "somePath"];
178-
} else {
179-
$mockValue = ["lastPath" => "lastPath"];
180-
}
181-
return $mockValue;
195+
[],
196+
[],
197+
[],
198+
[],
199+
[],
200+
[],
201+
[],
202+
[
203+
"vendor" => "vendor",
204+
"appCode" => "appCode",
205+
"devTests" => "devTests",
206+
"thisPath" => "thisPath"
207+
],
208+
function ($arg) {
209+
return $arg;
210+
},
211+
function ($arg) {
212+
return $arg;
182213
}
183214
);
184215
$resolver = ModuleResolver::getInstance();
185-
$this->setMockResolverProperties($resolver, null, null, ["somePath"]);
216+
$this->setMockResolverProperties($resolver, null, null, ["devTests" => "devTests"]);
186217
$this->assertEquals(
187-
["lastPath", "lastPath"],
218+
["vendor", "appCode", "thisPath"],
188219
$resolver->getModulesPath()
189220
);
190221
TestLoggingUtil::getInstance()->validateMockLogStatement(
191222
'info',
192223
'excluding module',
193-
['module' => 'somePath']
224+
['module' => 'devTests']
194225
);
195226
}
196227

@@ -278,6 +309,14 @@ public function testGetAdminTokenWithBadResponse()
278309
* @param string[] $mockGlob
279310
* @param string[] $mockRelativePaths
280311
* @param string[] $mockCustomModules
312+
* @param string[] $mockGetRegisteredModuleList
313+
* @param string[] $mockAggregateTestModulePathsFromComposerJson
314+
* @param string[] $mockAggregateTestModulePathsFromComposerInstaller
315+
* @param string[] $mockGetComposerJsonTestModulePaths
316+
* @param string[] $mockGetComposerInstalledTestModulePaths
317+
* @param string[] $mockAggregateTestModulePaths
318+
* @param string[] $mockNormalizeModuleNames
319+
* @param string[] $mockFlipAndFilterModulePathsArray
281320
* @throws \Exception
282321
* @return Verifier ModuleResolver double
283322
*/
@@ -287,7 +326,15 @@ private function setMockResolverClass(
287326
$mockCustomMethods = null,
288327
$mockGlob = null,
289328
$mockRelativePaths = null,
290-
$mockCustomModules = null
329+
$mockCustomModules = null,
330+
$mockGetRegisteredModuleList = null,
331+
$mockAggregateTestModulePathsFromComposerJson = [],
332+
$mockAggregateTestModulePathsFromComposerInstaller = [],
333+
$mockGetComposerJsonTestModulePaths = [],
334+
$mockGetComposerInstalledTestModulePaths = [],
335+
$mockAggregateTestModulePaths = null,
336+
$mockNormalizeModuleNames = null,
337+
$mockFlipAndFilterModulePathsArray = null
291338
) {
292339
$property = new \ReflectionProperty(ModuleResolver::class, 'instance');
293340
$property->setAccessible(true);
@@ -312,7 +359,23 @@ private function setMockResolverClass(
312359
if (isset($mockCustomModules)) {
313360
$mockMethods['getCustomModulePaths'] = $mockCustomModules;
314361
}
315-
// $mockMethods['printMagentoVersionInfo'] = null;
362+
if (isset($mockGetRegisteredModuleList)) {
363+
$mockMethods['getRegisteredModuleList'] = $mockGetRegisteredModuleList;
364+
}
365+
$mockMethods['aggregateTestModulePathsFromComposerJson'] = $mockAggregateTestModulePathsFromComposerJson ?? [];
366+
$mockMethods['aggregateTestModulePathsFromComposerInstaller'] =
367+
$mockAggregateTestModulePathsFromComposerInstaller ?? [];
368+
$mockMethods['getComposerJsonTestModulePaths'] = $mockGetComposerJsonTestModulePaths ?? [];
369+
$mockMethods['getComposerInstalledTestModulePaths'] = $mockGetComposerInstalledTestModulePaths ?? [];
370+
if (isset($mockAggregateTestModulePaths)) {
371+
$mockMethods['aggregateTestModulePaths'] = $mockAggregateTestModulePaths;
372+
}
373+
if (isset($mockNormalizeModuleNames)) {
374+
$mockMethods['normalizeModuleNames'] = $mockNormalizeModuleNames;
375+
}
376+
if (isset($mockFlipAndFilterModulePathsArray)) {
377+
$mockMethods['flipAndFilterModulePathsArray'] = $mockFlipAndFilterModulePathsArray;
378+
}
316379

317380
$mockResolver = AspectMock::double(
318381
ModuleResolver::class,

dev/tests/unit/Util/MockModuleResolverBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MockModuleResolverBuilder
1818
*
1919
* @var array
2020
*/
21-
private $defaultPaths = ['Magento_Module' => ['/base/path/app/code/Magento/Module/Test/Mftf']];
21+
private $defaultPaths = ['Magento_Module' => '/base/path/some/other/path/Magento/Module'];
2222

2323
/**
2424
* Mock ModuleResolver builder
@@ -29,7 +29,7 @@ class MockModuleResolverBuilder
2929
*/
3030
public function setup($paths = null)
3131
{
32-
if (!empty($path)) {
32+
if (empty($paths)) {
3333
$paths = $this->defaultPaths;
3434
}
3535

dev/tests/unit/Util/TestDataArrayBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function withFileName($filename = null)
225225
*/
226226
public function withTestReference($reference = null)
227227
{
228-
if ($reference != null) {
228+
if ($reference !== null) {
229229
$this->testReference = $reference;
230230
}
231231

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,12 @@ protected function applyCustomModuleMethods($modulesPath)
718718
$modulePathsResult = $this->removeBlacklistModules($modulesPath);
719719
$customModulePaths = $this->getCustomModulePaths();
720720

721-
array_map(function ($value) {
721+
array_map(function ($key, $value) {
722722
LoggingUtil::getInstance()->getLogger(ModuleResolver::class)->info(
723723
"including custom module",
724-
['module' => $value]
724+
[$key => $value]
725725
);
726-
}, $customModulePaths);
726+
}, array_keys($customModulePaths), $customModulePaths);
727727

728728
if (!isset($this->enabledModuleNameAndPaths)) {
729729
$this->enabledModuleNameAndPaths = array_merge($modulePathsResult, $customModulePaths);
@@ -761,13 +761,18 @@ private function removeBlacklistModules($modulePaths)
761761
*/
762762
private function getCustomModulePaths()
763763
{
764-
$customModulePaths = getenv(self::CUSTOM_MODULE_PATHS);
764+
$customModulePaths = [];
765+
$paths = getenv(self::CUSTOM_MODULE_PATHS);
765766

766-
if (!$customModulePaths) {
767-
return [];
767+
if (!$paths) {
768+
return $customModulePaths;
769+
}
770+
771+
foreach (explode(',', $paths) as $path) {
772+
$customModulePaths = [$this->findVendorAndModuleNameFromPath(trim($path)) => $path];
768773
}
769774

770-
return array_map('trim', explode(',', $customModulePaths));
775+
return $customModulePaths;
771776
}
772777

773778
/**

0 commit comments

Comments
 (0)