@@ -247,48 +247,68 @@ public function createAllTestFiles($testManifest = null, $testsToIgnore = null)
247247 $ this ->createCestFile ($ testPhpFile [1 ], $ testPhpFile [0 ]);
248248 }
249249 }
250+
250251 /**
251252 * Throw exception if duplicate arguments found
252253 *
253254 * @param string $fileContents
254- * @param string $fileName
255+ * @param TestObject $testObject
255256 * @return void
256257 * @throws TestFrameworkException
257258 */
258- public function throwExceptionIfDuplicateArgumentsFound (string $ fileContents , string $ fileName = '' ): void
259+ public function throwExceptionIfDuplicateArgumentsFound (string $ fileContents , TestObject $ testObject ): void
259260 {
260- $ fileToArr = explode ("\n" , $ fileContents );
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 ;
261+ $ parsedSteps = $ testObject ->getUnresolvedSteps ();
262+ foreach ($ parsedSteps as $ parsedStep ) {
263+ if (
264+ $ parsedStep ->getType () !== 'actionGroup ' &&
265+ $ parsedStep ->getType () !== 'helper '
266+ ) {
267267 continue ;
268268 }
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 (
278- 'Duplicate argument for actiongroup with name: %s in test file: %s ' ,
279- $ argumentName ,
280- $ fileName
281- );
282- throw new TestFrameworkException (implode (PHP_EOL , $ err ));
283- }
284- $ argumentNameArray [] = $ argumentName ;
285- }
286- $ argumentArray = [];
287- $ actionGroupStart = false ;
269+ $ attributesActions = $ parsedStep ->getCustomActionAttributes ();
270+ if (!key_exists ('arguments ' , $ attributesActions )) {
288271 continue ;
289272 }
290- if ($ actionGroupStart ) {
291- $ argumentArray [] = $ fileVal ;
273+ $ arguments = $ attributesActions ['arguments ' ];
274+ $ stepKey = $ parsedStep ->getStepKey ();
275+
276+ $ fileToArr = explode ("\n" , $ fileContents );
277+ $ actionGroupStart = false ;
278+ $ argumentArray = [];
279+ foreach ($ fileToArr as $ fileVal ) {
280+ $ fileVal = trim ($ fileVal );
281+ if (
282+ (str_contains ($ fileVal , '<actionGroup ' ) || str_contains ($ fileVal , '<helper ' )) &&
283+ str_contains ($ fileVal , $ stepKey )
284+ ) {
285+ $ actionGroupStart = true ;
286+ continue ;
287+ }
288+ if (str_contains ($ fileVal , '</actionGroup ' ) || str_contains ($ fileVal , '</helper ' )) {
289+ foreach ($ arguments as $ argumentName => $ argumentValue ) {
290+ $ argumentCounter = 0 ;
291+ foreach ($ argumentArray as $ rawArgument ) {
292+ if (str_contains ($ rawArgument , '<argument ' ) && str_contains ($ rawArgument , $ argumentName )){
293+ $ argumentCounter ++;
294+ }
295+ if ($ argumentCounter > 1 ) {
296+ $ err [] = sprintf (
297+ 'Duplicate argument(%s) for stepKey: %s in test file: %s ' ,
298+ $ argumentName ,
299+ $ stepKey ,
300+ $ testObject ->getFileName ()
301+ );
302+ throw new TestFrameworkException (implode (PHP_EOL , $ err ));
303+ }
304+ }
305+ $ actionGroupStart = false ;
306+ $ argumentArray = [];
307+ }
308+ }
309+ if ($ actionGroupStart ) {
310+ $ argumentArray [] = $ fileVal ;
311+ }
292312 }
293313 }
294314 }
0 commit comments