Skip to content

Commit d2f2726

Browse files
authored
Merge pull request #303 from magento-gl/ACQE-4318
ACQE 4318 :: Enhance the details in the testgroupmembership.txt file
2 parents 0cd8a72 + c1bc9f3 commit d2f2726

File tree

3 files changed

+159
-2
lines changed

3 files changed

+159
-2
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,60 @@ protected function setUp(): void
4040
TestLoggingUtil::getInstance()->setMockLoggingUtil();
4141
}
4242

43+
/**
44+
* Tests generating a suite given a set of parsed test data.
45+
*
46+
* @return void
47+
* @throws Exception
48+
*/
49+
public function testGenerateTestgroupmembership(): void
50+
{
51+
$suiteDataArrayBuilder = new SuiteDataArrayBuilder();
52+
$mockSuiteData = $suiteDataArrayBuilder
53+
->withName('mockSuite')
54+
->includeGroups(['group1'])
55+
->build();
56+
$testDataArrayBuilder = new TestDataArrayBuilder();
57+
$mockSimpleTest1 = $testDataArrayBuilder
58+
->withName('simpleTest1')
59+
->withAnnotations(['group' => [['value' => 'group1']]])
60+
->withTestReference("NonExistantTest")
61+
->withTestActions()
62+
->build();
63+
$mockSimpleTest2 = $testDataArrayBuilder
64+
->withName('simpleTest2')
65+
->withAnnotations(['group' => [['value' => 'group1']]])
66+
->withTestActions()
67+
->build();
68+
$mockSimpleTest3 = $testDataArrayBuilder
69+
->withName('simpleTest3')
70+
->withAnnotations(['group' => [['value' => 'group1']]])
71+
->withTestActions()
72+
->build();
73+
$mockTestData = array_merge($mockSimpleTest1, $mockSimpleTest2, $mockSimpleTest3);
74+
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockSuiteData);
75+
76+
// Make manifest for split suites
77+
$suiteConfig = [
78+
'mockSuite' => [
79+
'mockSuite_0_G' => ['simpleTest1', 'simpleTest2'],
80+
'mockSuite_1_G' => ['simpleTest3'],
81+
],
82+
];
83+
$manifest = TestManifestFactory::makeManifest('default', $suiteConfig);
84+
85+
// parse and generate suite object with mocked data and manifest
86+
$mockSuiteGenerator = SuiteGenerator::getInstance();
87+
$mockSuiteGenerator->generateAllSuites($manifest);
88+
89+
// assert last split suite group generated
90+
TestLoggingUtil::getInstance()->validateMockLogStatement(
91+
'info',
92+
'suite generated',
93+
['suite' => 'mockSuite_1_G', 'relative_path' => '_generated' . DIRECTORY_SEPARATOR . 'mockSuite_1_G']
94+
);
95+
}
96+
4397
/**
4498
* Tests generating a single suite given a set of parsed test data.
4599
*

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
231231
$testManifest->createTestGroups($configNumber);
232232
}
233233

234-
SuiteGenerator::getInstance()->generateAllSuites($testManifest);
235-
236234
$testManifest->generate();
235+
236+
SuiteGenerator::getInstance()->generateAllSuites($testManifest);
237237
} catch (\Exception $e) {
238238
if (!empty(GenerationErrorHandler::getInstance()->getAllErrors())) {
239239
GenerationErrorHandler::getInstance()->printErrorSummary();

src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public static function getInstance(): SuiteGenerator
9595
*/
9696
public function generateAllSuites($testManifest)
9797
{
98+
$this->generateTestgroupmembership($testManifest);
9899
$suites = $testManifest->getSuiteConfig();
99100

100101
foreach ($suites as $suiteName => $suiteContent) {
@@ -139,6 +140,108 @@ public function generateSuite($suiteName)
139140
$this->generateSuiteFromTest($suiteName, []);
140141
}
141142

143+
/**
144+
* Function which generate Testgroupmembership file.
145+
*
146+
* @param object $testManifest
147+
* @return void
148+
* @throws \Exception
149+
*/
150+
public function generateTestgroupmembership($testManifest): void
151+
{
152+
$suites = $this->getSuitesDetails($testManifest);
153+
154+
// Path to groups folder
155+
$baseDir = FilePathFormatter::format(TESTS_MODULE_PATH);
156+
$path = $baseDir .'_generated/groups';
157+
158+
$allGroupsContent = $this->readAllGroupFiles($path);
159+
160+
// Output file path
161+
$memberShipFilePath = $baseDir.'_generated/testgroupmembership.txt';
162+
$testCaseNumber = 0;
163+
164+
if (!empty($allGroupsContent)) {
165+
foreach ($allGroupsContent as $groupId => $groupInfo) {
166+
foreach ($groupInfo as $testName) {
167+
// If file has -g then it is test suite
168+
if (str_contains($testName, '-g')) {
169+
$suitename = explode(" ", $testName);
170+
$suitename[1] = trim($suitename[1]);
171+
172+
if (!empty($suites[$suitename[1]])) {
173+
foreach ($suites[$suitename[1]] as $key => $test) {
174+
$suiteTest = sprintf('%s:%s:%s:%s', $groupId, $key, $suitename[1], $test);
175+
file_put_contents($memberShipFilePath, $suiteTest . PHP_EOL, FILE_APPEND);
176+
}
177+
}
178+
} else {
179+
$defaultSuiteTest = sprintf('%s:%s:%s', $groupId, $testCaseNumber, $testName);
180+
file_put_contents($memberShipFilePath, $defaultSuiteTest, FILE_APPEND);
181+
}
182+
$testCaseNumber++;
183+
}
184+
$testCaseNumber = 0;
185+
}
186+
}
187+
}
188+
189+
/**
190+
* Function to format suites details
191+
*
192+
* @param object $testManifest
193+
* @return array $suites
194+
*/
195+
private function getSuitesDetails($testManifest): array
196+
{
197+
// Get suits and subsuites data array
198+
$suites = $testManifest->getSuiteConfig();
199+
200+
// Add subsuites array[2nd dimension] to main array[1st dimension] to access it directly later
201+
if (!empty($suites)) {
202+
foreach ($suites as $subSuites) {
203+
if (!empty($subSuites)) {
204+
foreach ($subSuites as $subSuiteName => $suiteTestNames) {
205+
if (!is_numeric($subSuiteName)) {
206+
$suites[$subSuiteName] = $suiteTestNames;
207+
} else {
208+
continue;
209+
}
210+
}
211+
}
212+
}
213+
}
214+
return $suites;
215+
}
216+
217+
/**
218+
* Function to read all group* text files inside /groups folder
219+
*
220+
* @param object $path
221+
* @return array $allGroupsContent
222+
*/
223+
private function readAllGroupFiles($path): array
224+
{
225+
// Read all group files
226+
if (is_dir($path)) {
227+
$groupFiles = glob("$path/group*.txt");
228+
if ($groupFiles === false) {
229+
throw new RuntimeException("glob(): error with '$path'");
230+
}
231+
sort($groupFiles, SORT_NATURAL);
232+
}
233+
234+
// Read each file in the reverse order and form an array with groupId as key
235+
$groupNumber = 0;
236+
$allGroupsContent = [];
237+
while (!empty($groupFiles)) {
238+
$group = array_pop($groupFiles);
239+
$allGroupsContent[$groupNumber] = file($group);
240+
$groupNumber++;
241+
}
242+
return $allGroupsContent;
243+
}
244+
142245
/**
143246
* Function which takes a suite name and a set of test names. The function then generates all relevant supporting
144247
* files and classes for the suite. The function takes an optional argument for suites which are split by a parallel

0 commit comments

Comments
 (0)