Skip to content

Commit 0b2cea4

Browse files
[ACQE-4318] Optimizing the code
1 parent 795d08b commit 0b2cea4

File tree

1 file changed

+58
-35
lines changed

1 file changed

+58
-35
lines changed

src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -147,47 +147,15 @@ public function generateSuite($suiteName)
147147
* @return void
148148
* @throws \Exception
149149
*/
150-
public function generateTestgroupmembership($testManifest)
150+
public function generateTestgroupmembership($testManifest): void
151151
{
152-
// Get suits and subsuites data array
153-
$suites = $testManifest->getSuiteConfig();
154-
155-
// Add subsuites array[2nd dimension] to main array[1st dimension] to access it directly later
156-
if (!empty($suites)) {
157-
foreach ($suites as $subSuites) {
158-
if (!empty($subSuites)) {
159-
foreach ($subSuites as $subSuiteName => $suiteTestNames) {
160-
if (!is_numeric($subSuiteName)) {
161-
$suites[$subSuiteName] = $suiteTestNames;
162-
} else {
163-
continue;
164-
}
165-
}
166-
}
167-
}
168-
}
152+
$suites = $this->getSuitesDetails($testManifest);
169153

170154
// Path to groups folder
171155
$baseDir = FilePathFormatter::format(TESTS_MODULE_PATH);
172156
$path = $baseDir .'_generated/groups';
173157

174-
// Read all group files
175-
if (is_dir($path)) {
176-
$groupFiles = glob("$path/group*.txt");
177-
if ($groupFiles === false) {
178-
throw new RuntimeException("glob(): error with '$path'");
179-
}
180-
sort($groupFiles, SORT_NATURAL);
181-
}
182-
183-
// Read each file in the reverse order and form an array with groupId as key
184-
$groupNumber = 0;
185-
$allGroupsContent = [];
186-
while (!empty($groupFiles)) {
187-
$group = array_pop($groupFiles);
188-
$allGroupsContent[$groupNumber] = file($group);
189-
$groupNumber++;
190-
}
158+
$allGroupsContent = $this->readAllGroupFiles($path);
191159

192160
// Output file path
193161
$memberShipFilePath = $baseDir.'_generated/testgroupmembership.txt';
@@ -218,6 +186,61 @@ public function generateTestgroupmembership($testManifest)
218186
}
219187
}
220188

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+
}
221244
/**
222245
* Function which takes a suite name and a set of test names. The function then generates all relevant supporting
223246
* 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)