Skip to content

Commit 024a017

Browse files
authored
Merge branch 'develop' into mftf_components_upgrade
2 parents 7ae3458 + 3ad2d85 commit 024a017

File tree

2 files changed

+79
-6
lines changed

2 files changed

+79
-6
lines changed

src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php

+45-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ class TestDependencyCheck implements StaticCheckInterface
2424
const EXTENDS_REGEX_PATTERN = '/extends=["\']([^\'"]*)/';
2525
const ACTIONGROUP_REGEX_PATTERN = '/ref=["\']([^\'"]*)/';
2626

27-
const ERROR_LOG_FILENAME = 'mftf-dependency-checks';
27+
const ERROR_LOG_FILENAME = 'mftf-dependency-checks-errors';
2828
const ERROR_LOG_MESSAGE = 'MFTF File Dependency Check';
29+
const WARNING_LOG_FILENAME = 'mftf-dependency-checks-warnings';
30+
31+
const ALLOW_LIST_FILENAME = 'test-dependency-allowlist';
2932

3033
/**
3134
* Array of FullModuleName => [dependencies], including flattened dependency tree
@@ -51,6 +54,17 @@ class TestDependencyCheck implements StaticCheckInterface
5154
*/
5255
private $errors = [];
5356

57+
/**
58+
* Array containing all warnings found after running the execute() function.
59+
* @var array
60+
*/
61+
private $warnings = [];
62+
/**
63+
* Array containing warnings found while iterating through files
64+
* @var array
65+
*/
66+
private $tempWarnings = [];
67+
5468
/**
5569
* String representing the output summary found after running the execute() function.
5670
* @var string
@@ -75,6 +89,11 @@ class TestDependencyCheck implements StaticCheckInterface
7589
*/
7690
private $testDependencyUtil;
7791

92+
/**
93+
* @var array $allowFailureEntities
94+
*/
95+
private $allowFailureEntities = [];
96+
7897
/**
7998
* Checks test dependencies, determined by references in tests versus the dependencies listed in the Magento module
8099
*
@@ -93,6 +112,18 @@ public function execute(InputInterface $input)
93112
"TEST DEPENDENCY CHECK ABORTED: MFTF must be attached or pointing to Magento codebase."
94113
);
95114
}
115+
116+
// Build array of entities found in allow-list files
117+
// Expect one entity per file line, no commas or anything else
118+
foreach ($allModules as $modulePath) {
119+
if (file_exists($modulePath . DIRECTORY_SEPARATOR . self::ALLOW_LIST_FILENAME)) {
120+
$contents = file_get_contents($modulePath . DIRECTORY_SEPARATOR . self::ALLOW_LIST_FILENAME);
121+
foreach (explode("\n", $contents) as $entity) {
122+
$this->allowFailureEntities[$entity] = true;
123+
}
124+
}
125+
}
126+
96127
$registrar = new \Magento\Framework\Component\ComponentRegistrar();
97128
$this->moduleNameToPath = $registrar->getPaths(\Magento\Framework\Component\ComponentRegistrar::MODULE);
98129
$this->moduleNameToComposerName = $this->testDependencyUtil->buildModuleNameToComposerName(
@@ -124,6 +155,13 @@ public function execute(InputInterface $input)
124155
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
125156
self::ERROR_LOG_MESSAGE
126157
);
158+
if (!empty($this->warnings)) {
159+
$this->output .= "\n " . $this->scriptUtil->printWarningsToFile(
160+
$this->warnings,
161+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::WARNING_LOG_FILENAME . '.txt',
162+
self::ERROR_LOG_MESSAGE
163+
);
164+
}
127165
}
128166

129167
/**
@@ -199,6 +237,7 @@ private function findErrorsInFileSet(Finder $files): array
199237
// Find violating references and set error output
200238
$violatingReferences = $this->findViolatingReferences($moduleName);
201239
$testErrors = array_merge($testErrors, $this->setErrorOutput($violatingReferences, $filePath));
240+
$this->warnings = array_merge($this->warnings, $this->setErrorOutput($this->tempWarnings, $filePath));
202241
}
203242
return $testErrors;
204243
}
@@ -221,6 +260,7 @@ private function findViolatingReferences(string $moduleName): array
221260
);
222261
$moduleDependencies = $this->flattenedDependencies[$moduleName];
223262
foreach ($modulesReferencedInTest as $entityName => $files) {
263+
$isInAllowList = array_key_exists($entityName, $this->allowFailureEntities);
224264
$valid = false;
225265
foreach ($files as $module) {
226266
if (array_key_exists($module, $moduleDependencies) || $module === $currentModule) {
@@ -229,6 +269,10 @@ private function findViolatingReferences(string $moduleName): array
229269
}
230270
}
231271
if (!$valid) {
272+
if ($isInAllowList) {
273+
$this->tempWarnings[$entityName] = $files;
274+
continue;
275+
}
232276
$violatingReferences[$entityName] = $files;
233277
}
234278
}

src/Magento/FunctionalTestingFramework/Util/Script/ScriptUtil.php

+34-5
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,51 @@ public function printErrorsToFile(array $errors, string $filePath, string $messa
6767
return $message . ": No errors found.";
6868
}
6969

70+
$this->printTofile($errors, $filePath);
71+
72+
$errorCount = count($errors);
73+
74+
return $message . ": Errors found across {$errorCount} file(s). Error details output to {$filePath}";
75+
}
76+
77+
/**
78+
* Prints out given warnings to file, and returns summary result string
79+
* @param array $warnings
80+
* @param string $filePath
81+
* @param string $message
82+
* @return string
83+
*/
84+
public function printWarningsToFile(array $warnings, string $filePath, string $message): string
85+
{
86+
if (empty($warnings)) {
87+
return $message . ": No warnings found.";
88+
}
89+
$this->printTofile($warnings, $filePath);
90+
$errorCount = count($warnings);
91+
92+
return $message . ": Warnings found across {$errorCount} file(s). Warning details output to {$filePath}";
93+
}
94+
95+
/**
96+
* Writes contents to filePath
97+
* @param array $contents
98+
* @param string $filePath
99+
* @return void
100+
*/
101+
private function printTofile(array $contents, string $filePath)
102+
{
70103
$dirname = dirname($filePath);
71104
if (!file_exists($dirname)) {
72105
mkdir($dirname, 0777, true);
73106
}
74107

75108
$fileResource = fopen($filePath, 'w');
76109

77-
foreach ($errors as $test => $error) {
110+
foreach ($contents as $test => $error) {
78111
fwrite($fileResource, $error[0] . PHP_EOL);
79112
}
80113

81114
fclose($fileResource);
82-
$errorCount = count($errors);
83-
$output = $message . ": Errors found across {$errorCount} file(s). Error details output to {$filePath}";
84-
85-
return $output;
86115
}
87116

88117
/**

0 commit comments

Comments
 (0)