Skip to content

Commit 3330a67

Browse files
committed
33308: Fixed verification-tests
1 parent d4af178 commit 3330a67

File tree

3 files changed

+86
-102
lines changed

3 files changed

+86
-102
lines changed

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,7 @@ public function testGetModulePathsNoAdminToken(): void
783783
{
784784
// Set --force to false
785785
$this->mockForceGenerate(false);
786-
$moduleResolverService = $this->createPartialMock(ModuleResolverService::class, ['applyCustomModuleMethods']);
787-
$moduleResolverService
788-
->method('applyCustomModuleMethods')
789-
->willReturn(["example" . DIRECTORY_SEPARATOR . "paths"]);
790786

791-
$this->setMockResolverCreatorProperties($moduleResolverService);
792787
$resolver = ModuleResolver::getInstance();
793788
$this->setMockResolverProperties($resolver);
794789

@@ -893,9 +888,9 @@ private function setMockResolverProperties(
893888
$property->setAccessible(true);
894889
$property->setValue($instance, $mockModules);
895890

896-
$property = new ReflectionProperty(ModuleResolverService::class, 'moduleBlockList');
891+
$property = new ReflectionProperty(ModuleResolver::class, 'moduleBlocklist');
897892
$property->setAccessible(true);
898-
$property->setValue($mockBlockList);
893+
$property->setValue($instance, $mockBlockList);
899894
}
900895

901896
/**

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

+84-3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ class ModuleResolver
127127
*/
128128
protected $sequenceSorter;
129129

130+
/**
131+
* List of module names that will be ignored.
132+
*
133+
* @var array
134+
*/
135+
protected $moduleBlocklist = [
136+
'SampleTests', 'SampleTemplates'
137+
];
138+
130139
/**
131140
* Get ModuleResolver instance.
132141
*
@@ -315,7 +324,6 @@ private function aggregateTestModulePathsFromComposerJson()
315324
* Retrieve all module code paths that have test module composer json files
316325
*
317326
* @param array $codePaths
318-
*
319327
* @return array
320328
*/
321329
private function getComposerJsonTestModulePaths($codePaths)
@@ -505,6 +513,24 @@ private function normalizeModuleNames($codePaths)
505513
return $normalizedCodePaths;
506514
}
507515

516+
/**
517+
* Takes a multidimensional array of module paths and flattens to return a one dimensional array of test paths
518+
*
519+
* @param array $modulePaths
520+
* @return array
521+
*/
522+
private function flattenAllModulePaths($modulePaths)
523+
{
524+
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($modulePaths));
525+
$resultArray = [];
526+
527+
foreach ($it as $value) {
528+
$resultArray[] = $value;
529+
}
530+
531+
return $resultArray;
532+
}
533+
508534
/**
509535
* Executes a REST call to the supplied Magento Base Url for version information to display during generation
510536
*
@@ -541,11 +567,66 @@ private function printMagentoVersionInfo()
541567
*
542568
* @param array $modulesPath
543569
* @return string[]
544-
* @throws TestFrameworkException
545570
*/
546571
protected function applyCustomModuleMethods($modulesPath)
547572
{
548-
return ModuleResolverService::getInstance()->applyCustomModuleMethods($modulesPath);
573+
$modulePathsResult = $this->removeBlocklistModules($modulesPath);
574+
$customModulePaths = $this->getCustomModulePaths();
575+
576+
array_map(function ($key, $value) {
577+
LoggingUtil::getInstance()->getLogger(ModuleResolver::class)->info(
578+
"including custom module",
579+
[$key => $value]
580+
);
581+
}, array_keys($customModulePaths), $customModulePaths);
582+
583+
if (!isset($this->enabledModuleNameAndPaths)) {
584+
$this->enabledModuleNameAndPaths = array_merge($modulePathsResult, $customModulePaths);
585+
}
586+
return $this->flattenAllModulePaths(array_merge($modulePathsResult, $customModulePaths));
587+
}
588+
589+
/**
590+
* Remove blocklist modules from input module paths.
591+
*
592+
* @param array $modulePaths
593+
* @return string[]
594+
*/
595+
private function removeBlocklistModules($modulePaths)
596+
{
597+
$modulePathsResult = $modulePaths;
598+
foreach ($modulePathsResult as $moduleName => $modulePath) {
599+
// Remove module if it is in blocklist
600+
if (in_array($moduleName, $this->getModuleBlocklist())) {
601+
unset($modulePathsResult[$moduleName]);
602+
LoggingUtil::getInstance()->getLogger(ModuleResolver::class)->info(
603+
"excluding module",
604+
['module' => $moduleName]
605+
);
606+
}
607+
}
608+
609+
return $modulePathsResult;
610+
}
611+
612+
/**
613+
* Returns an array of custom module paths defined by the user
614+
*
615+
* @return string[]
616+
*/
617+
private function getCustomModulePaths()
618+
{
619+
return ModuleResolverService::getInstance()->getCustomModulePaths();
620+
}
621+
622+
/**
623+
* Getter for moduleBlocklist.
624+
*
625+
* @return string[]
626+
*/
627+
private function getModuleBlocklist()
628+
{
629+
return $this->moduleBlocklist;
549630
}
550631

551632
/**

src/Magento/FunctionalTestingFramework/Util/ModuleResolver/ModuleResolverService.php

-92
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
1717
use Magento\FunctionalTestingFramework\Util\ModuleResolver;
1818
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
19-
use RecursiveArrayIterator;
20-
use RecursiveIteratorIterator;
2119

2220
class ModuleResolverService
2321
{
@@ -42,15 +40,6 @@ class ModuleResolverService
4240
*/
4341
private $composerInstalledModulePaths = null;
4442

45-
/**
46-
* List of module names that will be ignored.
47-
*
48-
* @var array
49-
*/
50-
private static $moduleBlockList = [
51-
'SampleTests', 'SampleTemplates'
52-
];
53-
5443
/**
5544
* ModuleResolverService constructor.
5645
*/
@@ -333,16 +322,6 @@ private function findVendorNameFromPath(string $path): string
333322
return $possibleVendorName;
334323
}
335324

336-
/**
337-
* Getter for moduleBlockList.
338-
*
339-
* @return string[]
340-
*/
341-
private function getModuleBlockList(): array
342-
{
343-
return self::$moduleBlockList;
344-
}
345-
346325
/**
347326
* Get admin token.
348327
*
@@ -353,75 +332,4 @@ public function getAdminToken(): string
353332
{
354333
return WebApiAuth::getAdminToken();
355334
}
356-
357-
/**
358-
* A wrapping method for any custom logic which needs to be applied to the module list.
359-
*
360-
* @param array $modulesPath
361-
*
362-
* @return string[]
363-
* @throws TestFrameworkException
364-
*/
365-
public function applyCustomModuleMethods(array $modulesPath): array
366-
{
367-
$modulePathsResult = $this->removeBlockListModules($modulesPath);
368-
$customModulePaths = $this->getCustomModulePaths();
369-
370-
array_map(function ($key, $value) {
371-
LoggingUtil::getInstance()->getLogger(ModuleResolver::class)->info(
372-
"including custom module",
373-
[$key => $value]
374-
);
375-
}, array_keys($customModulePaths), $customModulePaths);
376-
377-
if (!isset($this->enabledModuleNameAndPaths)) {
378-
$this->enabledModuleNameAndPaths = array_merge($modulePathsResult, $customModulePaths);
379-
}
380-
return $this->flattenAllModulePaths(array_merge($modulePathsResult, $customModulePaths));
381-
}
382-
383-
/**
384-
* Remove blockList modules from input module paths.
385-
*
386-
* @param array $modulePaths
387-
*
388-
* @return string[]
389-
* @throws TestFrameworkException
390-
*/
391-
private function removeBlockListModules(array $modulePaths): array
392-
{
393-
$modulePathsResult = $modulePaths;
394-
395-
foreach ($modulePathsResult as $moduleName => $modulePath) {
396-
// Remove module if it is in blocklist
397-
if (in_array($moduleName, $this->getModuleBlockList())) {
398-
unset($modulePathsResult[$moduleName]);
399-
LoggingUtil::getInstance()->getLogger(ModuleResolver::class)->info(
400-
"excluding module",
401-
['module' => $moduleName]
402-
);
403-
}
404-
}
405-
406-
return $modulePathsResult;
407-
}
408-
409-
/**
410-
* Takes a multidimensional array of module paths and flattens to return a one dimensional array of test paths.
411-
*
412-
* @param array $modulePaths
413-
*
414-
* @return array
415-
*/
416-
private function flattenAllModulePaths(array $modulePaths): array
417-
{
418-
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($modulePaths));
419-
$resultArray = [];
420-
421-
foreach ($it as $value) {
422-
$resultArray[] = $value;
423-
}
424-
425-
return $resultArray;
426-
}
427335
}

0 commit comments

Comments
 (0)