Skip to content

Commit c5751c6

Browse files
authored
Update TestGenerator.php
1 parent 2b19f3e commit c5751c6

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -250,33 +250,43 @@ public function createAllTestFiles($testManifest = null, $testsToIgnore = null)
250250
/**
251251
* Throw exception if duplicate arguments found
252252
*
253-
* @param string $fileContents
253+
* @param string $fileName
254254
* @return void
255255
* @throws TestFrameworkException
256256
*/
257-
public function throwExceptionIfDuplicateArgumentsFound(string $fileContents)
257+
public function throwExceptionIfDuplicateArgumentsFound(string $fileName): void
258258
{
259-
// Throw exception if duplicate arguments found in helper or actionGroup
259+
$fileContents = file_get_contents($fileName);
260260
$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);
273278
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+
}
280290
}
281291

282292
/**
@@ -291,7 +301,7 @@ public function throwExceptionIfDuplicateArgumentsFound(string $fileContents)
291301
public function assembleTestPhp($testObject)
292302
{
293303
if (!empty($testObject->getFilename()) && file_exists($testObject->getFilename())) {
294-
$this->throwExceptionIfDuplicateArgumentsFound(file_get_contents($testObject->getFilename()));
304+
$this->throwExceptionIfDuplicateArgumentsFound($testObject->getFilename());
295305
}
296306
$this->customHelpers = [];
297307
$usePhp = $this->generateUseStatementsPhp();

0 commit comments

Comments
 (0)