Skip to content

Commit fdf77db

Browse files
authored
Merge pull request #353 from magento-gl/ACQE-5843
ACQE-5843 : Adding filters for test data
2 parents 0654ac6 + 82afa08 commit fdf77db

File tree

2 files changed

+55
-19
lines changed

2 files changed

+55
-19
lines changed

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
252252
// check test dependencies log command
253253
if (!empty($log)) {
254254
if ($log === "testEntityJson") {
255-
$this->getTestEntityJson($tests);
255+
$this->getTestEntityJson($filterList ??[], $tests);
256256
$testDependencyFileLocation = self::TEST_DEPENDENCY_FILE_LOCATION_EMBEDDED;
257257
if (isset($_ENV['MAGENTO_BP'])) {
258258
$testDependencyFileLocation = self::TEST_DEPENDENCY_FILE_LOCATION_STANDALONE;
@@ -395,21 +395,22 @@ private function parseConfigParallelOptions($time, $groups)
395395
* @throws TestFrameworkException
396396
* @throws XmlException|FastFailException
397397
*/
398-
private function getTestEntityJson(array $tests = [])
398+
private function getTestEntityJson(array $filterList, array $tests = [])
399399
{
400-
$testDependencies = $this->getTestDependencies($tests);
400+
$testDependencies = $this->getTestDependencies($filterList, $tests);
401401
$this->array2Json($testDependencies);
402402
}
403403

404404
/**
405405
* Function responsible for getting test dependencies in array
406+
* @param array $filterList
406407
* @param array $tests
407408
* @return array
408409
* @throws FastFailException
409410
* @throws TestFrameworkException
410411
* @throws XmlException
411412
*/
412-
public function getTestDependencies(array $tests = []): array
413+
public function getTestDependencies(array $filterList, array $tests = []): array
413414
{
414415
$this->scriptUtil = new ScriptUtil();
415416
$this->testDependencyUtil = new TestDependencyUtil();
@@ -442,7 +443,11 @@ public function getTestDependencies(array $tests = []): array
442443
}
443444

444445
list($testDependencies, $extendedTestMapping) = $this->findTestDependentModule($testXmlFiles);
445-
return $this->testDependencyUtil->mergeDependenciesForExtendingTests($testDependencies, $extendedTestMapping);
446+
return $this->testDependencyUtil->mergeDependenciesForExtendingTests(
447+
$testDependencies,
448+
$filterList,
449+
$extendedTestMapping
450+
);
446451
}
447452

448453
/**

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

+45-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\FunctionalTestingFramework\Util\Script;
77

8+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
9+
use Magento\FunctionalTestingFramework\Filter\FilterList;
10+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
11+
812
/**
913
* TestDependencyUtil class that contains helper functions for static and upgrade scripts
1014
*
@@ -144,11 +148,16 @@ public function getModuleName(string $filePath, array $moduleNameToPath): ?strin
144148
/**
145149
* Return array of merge test modules and file path with same test name.
146150
* @param array $testDependencies
151+
* @param array $filterList
147152
* @param array $extendedTestMapping
148153
* @return array
149154
*/
150-
public function mergeDependenciesForExtendingTests(array $testDependencies, array $extendedTestMapping = []): array
151-
{
155+
public function mergeDependenciesForExtendingTests(
156+
array $testDependencies,
157+
array $filterList,
158+
array $extendedTestMapping = []
159+
): array {
160+
$filteredTestNames = (count($filterList)>0)?$this->getFilteredTestNames():[];
152161
$temp_array = array_reverse(array_column($testDependencies, "test_name"), true);
153162
if (!empty($extendedTestMapping)) {
154163
foreach ($extendedTestMapping as $value) {
@@ -165,20 +174,42 @@ public function mergeDependenciesForExtendingTests(array $testDependencies, arra
165174
}
166175
$testDependencies = [];
167176
foreach ($temp_array as $testDependencyArray) {
168-
$testDependencies[] = [
169-
"file_path" => array_column($testDependencyArray, 'file_path'),
170-
"full_name" => $testDependencyArray[0]["full_name"],
171-
"test_name" => $testDependencyArray[0]["test_name"],
172-
"test_modules" =>array_values(
173-
array_unique(
174-
call_user_func_array(
175-
'array_merge',
176-
array_column($testDependencyArray, 'test_modules')
177+
if ((
178+
empty($filterList)) ||
179+
isset($filteredTestNames[$testDependencyArray[0]["test_name"]])
180+
) {
181+
$testDependencies[] = [
182+
"file_path" => array_column($testDependencyArray, 'file_path'),
183+
"full_name" => $testDependencyArray[0]["full_name"],
184+
"test_name" => $testDependencyArray[0]["test_name"],
185+
"test_modules" => array_values(
186+
array_unique(
187+
call_user_func_array(
188+
'array_merge',
189+
array_column($testDependencyArray, 'test_modules')
190+
)
177191
)
178-
)
179-
),
180-
];
192+
),
193+
];
194+
}
181195
}
182196
return $testDependencies;
183197
}
198+
199+
/**
200+
* Return array of merge test modules and file path with same test name.
201+
* @return array
202+
*/
203+
public function getFilteredTestNames()
204+
{
205+
$testObjects = TestObjectHandler::getInstance()->getAllObjects();
206+
$filters = MftfApplicationConfig::getConfig()->getFilterList()->getFilters();
207+
foreach ($filters as $filter) {
208+
$filter->filter($testObjects);
209+
}
210+
$testValues = array_map(function ($testObjects) {
211+
return $testObjects->getName();
212+
}, $testObjects);
213+
return $testValues;
214+
}
184215
}

0 commit comments

Comments
 (0)