@@ -250,33 +250,43 @@ public function createAllTestFiles($testManifest = null, $testsToIgnore = null)
250
250
/**
251
251
* Throw exception if duplicate arguments found
252
252
*
253
- * @param string $fileContents
253
+ * @param string $fileName
254
254
* @return void
255
255
* @throws TestFrameworkException
256
256
*/
257
- public function throwExceptionIfDuplicateArgumentsFound (string $ fileContents )
257
+ public function throwExceptionIfDuplicateArgumentsFound (string $ fileName ): void
258
258
{
259
- // Throw exception if duplicate arguments found in helper or actionGroup
259
+ $ fileContents = file_get_contents ( $ fileName );
260
260
$ fileToArr = explode ("\n" , $ fileContents );
261
- $ argArr = [];
262
- foreach ($ fileToArr as $ key => $ fileVal ) {
263
- if (!empty (strpos ($ fileVal , "<argument name " ))) {
264
- $ argArr [$ key ] = explode (" " , trim ($ fileVal ))[1 ];
265
- }
266
- }
267
- foreach ($ argArr as $ key => $ arrVal ) {
268
- if (!str_contains ('= ' , $ arrVal )) {
269
- continue ;
270
- }
271
- if (!empty ($ argArr [$ key + 1 ]) && $ argArr [$ key + 1 ] === $ arrVal ) {
272
- $ err [] = 'Duplicate argument name ' .$ arrVal .' not allowed in helper or actionGroup ' ;
261
+ $ argumentArray = [];
262
+ $ actionGroupStart = false ;
263
+ foreach ($ fileToArr as $ fileVal ) {
264
+ $ fileVal = trim ($ fileVal );
265
+ if (str_starts_with ($ fileVal , '<actionGroup ' ) && !str_ends_with ($ fileVal , '/> ' )) {
266
+ $ actionGroupStart = true ;
267
+ continue ;
268
+ }
269
+ if ($ fileVal === '</actionGroup> ' ) {
270
+ $ argumentNameArray = [];
271
+ foreach ($ argumentArray as $ argument ) {
272
+ $ subtringStart = strpos ($ argument , 'name= ' );
273
+ $ subtringStart += strlen ('name= ' );
274
+ $ size = strpos ($ argument , ' ' , $ subtringStart ) - $ subtringStart ;
275
+ $ argumentName = substr ($ argument , $ subtringStart , $ size );
276
+ if (in_array ($ argumentName , $ argumentNameArray )) {
277
+ $ err [] = sprintf ('Duplicate argument name: %s in test file: %s ' , $ argumentName , $ fileName );
273
278
throw new TestFrameworkException (implode (PHP_EOL , $ err ));
274
- }
275
- if (!empty ($ argArr [$ key + 2 ]) && $ argArr [$ key + 2 ] === $ arrVal ) {
276
- $ err [] = 'Duplicate argument name ' .$ arrVal .' not allowed in helper or actionGroup ' ;
277
- throw new TestFrameworkException (implode (PHP_EOL , $ err ));
278
- }
279
- }
279
+ }
280
+ $ argumentNameArray [] = $ argumentName ;
281
+ }
282
+ $ argumentArray = [];
283
+ $ actionGroupStart = false ;
284
+ continue ;
285
+ }
286
+ if ($ actionGroupStart ) {
287
+ $ argumentArray [] = $ fileVal ;
288
+ }
289
+ }
280
290
}
281
291
282
292
/**
@@ -291,7 +301,7 @@ public function throwExceptionIfDuplicateArgumentsFound(string $fileContents)
291
301
public function assembleTestPhp ($ testObject )
292
302
{
293
303
if (!empty ($ testObject ->getFilename ()) && file_exists ($ testObject ->getFilename ())) {
294
- $ this ->throwExceptionIfDuplicateArgumentsFound (file_get_contents ( $ testObject ->getFilename () ));
304
+ $ this ->throwExceptionIfDuplicateArgumentsFound ($ testObject ->getFilename ());
295
305
}
296
306
$ this ->customHelpers = [];
297
307
$ usePhp = $ this ->generateUseStatementsPhp ();
0 commit comments