Skip to content

Commit 6fc5d26

Browse files
authored
Merge pull request #145 from magento-arcticfoxes/MQE-2575
MQE-2575: Allow MFTF Helpers to Return Data to MFTF Test
2 parents da431d6 + ccfcf4f commit 6fc5d26

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

dev/tests/functional/tests/MFTF/DevDocs/Helper/CustomHelper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,15 @@ public function goTo(
4646
print('$bla = ' . $bla . PHP_EOL);
4747
print('array $arraysomething = [' . implode(', ', $arraysomething) . ']' . PHP_EOL);
4848
}
49+
50+
/**
51+
* Returns value of provided param $text
52+
*
53+
* @param string $text
54+
* @return string
55+
*/
56+
public function getText(string $text): string
57+
{
58+
return $text;
59+
}
4960
}

dev/tests/functional/tests/MFTF/DevDocs/Test/DevDocsTest.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
<argument name="int">987</argument>
4343
</helper>
4444

45+
<helper class="\MFTF\DevDocs\Helper\CustomHelper" method="getText" stepKey="getText">
46+
<argument name="text">some text</argument>
47+
</helper>
48+
<assertEquals stepKey="assertHelperReturnValue" message="Method getText of CustomHelper should return value which may be used as variable in test">
49+
<expectedResult type="string">some text</expectedResult>
50+
<actualResult type="variable">getText</actualResult>
51+
</assertEquals>
52+
4553
<actionGroup ref="HelperActionGroup" stepKey="actionGroupWithCustomHelper">
4654
<argument name="test" value="{{HelperData.entityField}}" />
4755
<argument name="entityTest" value="HelperData" />

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,12 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
898898
$stepKey,
899899
$customActionAttributes['class'] . '::' . $customActionAttributes['method']
900900
);
901-
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $arguments);
901+
$testSteps .= $this->wrapFunctionCallWithReturnValue(
902+
$stepKey,
903+
$actor,
904+
$actionObject,
905+
$arguments
906+
);
902907
break;
903908
case "createData":
904909
$entity = $customActionAttributes['entity'];
@@ -2016,16 +2021,7 @@ private function addDollarSign($input)
20162021
*/
20172022
private function wrapFunctionCall($actor, $action, ...$args)
20182023
{
2019-
$isFirst = true;
2020-
$isActionHelper = $action->getType() === 'helper';
2021-
$actionType = $action->getType();
2022-
if ($isActionHelper) {
2023-
$actor = "this->helperContainer->get('" . $action->getCustomActionAttributes()['class'] . "')";
2024-
$args = $args[0];
2025-
$actionType = $action->getCustomActionAttributes()['method'];
2026-
}
2027-
2028-
$output = sprintf("\t\t$%s->%s(", $actor, $actionType);
2024+
$output = sprintf("\t\t$%s->%s(", $actor, $action->getType());
20292025
for ($i = 0; $i < count($args); $i++) {
20302026
if (null === $args[$i]) {
20312027
continue;
@@ -2046,17 +2042,22 @@ private function wrapFunctionCall($actor, $action, ...$args)
20462042
/**
20472043
* Wrap parameters into a function call with a return value.
20482044
*
2049-
* @param string $returnVariable
2050-
* @param string $actor
2051-
* @param string $action
2052-
* @param array ...$args
2045+
* @param string $returnVariable
2046+
* @param string $actor
2047+
* @param actionObject $action
2048+
* @param array ...$args
20532049
* @return string
20542050
* @throws \Exception
20552051
*/
20562052
private function wrapFunctionCallWithReturnValue($returnVariable, $actor, $action, ...$args)
20572053
{
2058-
$isFirst = true;
2059-
$output = sprintf("\t\t$%s = $%s->%s(", $returnVariable, $actor, $action->getType());
2054+
$actionType = $action->getType();
2055+
if ($actionType === 'helper') {
2056+
$actor = "this->helperContainer->get('" . $action->getCustomActionAttributes()['class'] . "')";
2057+
$args = $args[0];
2058+
$actionType = $action->getCustomActionAttributes()['method'];
2059+
}
2060+
$output = sprintf("\t\t$%s = $%s->%s(", $returnVariable, $actor, $actionType);
20602061
for ($i = 0; $i < count($args); $i++) {
20612062
if (null === $args[$i]) {
20622063
continue;

0 commit comments

Comments
 (0)