@@ -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