Skip to content

Commit 67373ba

Browse files
committed
MQE-1173: [Dev experience] Error on test generation without reference on file
- Moved count out of matching method
1 parent 0062426 commit 67373ba

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -682,26 +682,7 @@ private function matchParameterReferences($reference, $parameters)
682682
{
683683
preg_match_all('/{{[\w.]+}}/', $reference, $varMatches);
684684
$varMatches[0] = array_unique($varMatches[0]);
685-
if (count($varMatches[0]) > count($parameters)) {
686-
if (is_array($parameters)) {
687-
$parametersGiven = implode(",", $parameters);
688-
} elseif ($parameters == null) {
689-
$parametersGiven = "NONE";
690-
} else {
691-
$parametersGiven = $parameters;
692-
}
693-
throw new TestReferenceException(
694-
"Parameter Resolution Failed: Not enough parameters given for reference " .
695-
$reference . ". Parameters Given: " . $parametersGiven,
696-
["reference" => $reference, "parametersGiven" => $parametersGiven]
697-
);
698-
} elseif (count($varMatches[0]) < count($parameters)) {
699-
throw new TestReferenceException(
700-
"Parameter Resolution Failed: Too many parameters given for reference " .
701-
$reference . ". Parameters Given: " . implode(", ", $parameters),
702-
["reference" => $reference, "parametersGiven" => $parameters]
703-
);
704-
}
685+
$this->checkParameterCount($varMatches[0], $parameters, $reference);
705686

706687
//Attempt to Resolve {{data}} references to actual output. Trim parameter for whitespace before processing it.
707688
//If regex matched it means that it's either a 'StringLiteral' or $key.data$/$$key.data$$ reference.
@@ -730,4 +711,43 @@ private function matchParameterReferences($reference, $parameters)
730711
}
731712
return $reference;
732713
}
714+
715+
/**
716+
* Checks count of parameters versus matches
717+
*
718+
* @param array $matches
719+
* @param array $parameters
720+
* @param string $reference
721+
* @return void
722+
* @throws \Exception
723+
*/
724+
private function checkParameterCount($matches, $parameters, $reference)
725+
{
726+
if (count($matches) > count($parameters)) {
727+
if (is_array($parameters)) {
728+
$parametersGiven = implode(",", $parameters);
729+
} elseif ($parameters == null) {
730+
$parametersGiven = "NONE";
731+
} else {
732+
$parametersGiven = $parameters;
733+
}
734+
throw new TestReferenceException(
735+
"Parameter Resolution Failed: Not enough parameters given for reference " .
736+
$reference . ". Parameters Given: " . $parametersGiven,
737+
["reference" => $reference, "parametersGiven" => $parametersGiven]
738+
);
739+
} elseif (count($matches) < count($parameters)) {
740+
throw new TestReferenceException(
741+
"Parameter Resolution Failed: Too many parameters given for reference " .
742+
$reference . ". Parameters Given: " . implode(", ", $parameters),
743+
["reference" => $reference, "parametersGiven" => $parameters]
744+
);
745+
} elseif (count($matches) == 0) {
746+
throw new TestReferenceException(
747+
"Parameter Resolution Failed: No parameter matches found for reference " .
748+
$reference,
749+
["reference" => $reference]
750+
);
751+
}
752+
}
733753
}

0 commit comments

Comments
 (0)