@@ -702,7 +702,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
702
702
);
703
703
}
704
704
705
- if (isset ( $ storeCode) ) {
705
+ if ($ storeCode ) {
706
706
$ createEntityFunctionCall .= sprintf ("\"%s \"); \n" , $ storeCode );
707
707
} else {
708
708
$ createEntityFunctionCall .= "); \n" ;
@@ -743,13 +743,14 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
743
743
$ testSteps .= $ contextSetter ;
744
744
$ testSteps .= $ deleteEntityFunctionCall ;
745
745
} else {
746
+ $ url = $ this ->resolveEnvReferences ([$ url ])[0 ];
747
+ $ url = $ this ->resolveTestVariable ([$ url ], null )[0 ];
746
748
$ output = sprintf (
747
749
"\t\t$%s->deleteEntityByUrl(%s); \n" ,
748
750
$ actor ,
749
751
$ url
750
752
);
751
- $ output = $ this ->resolveEnvReferences ($ output , [$ url ]);
752
- $ testSteps .= $ this ->resolveTestVariable ($ output , [$ url ], null );
753
+ $ testSteps .= $ output ;
753
754
}
754
755
break ;
755
756
case "updateData " :
@@ -798,7 +799,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
798
799
);
799
800
}
800
801
801
- if (isset ( $ storeCode) ) {
802
+ if ($ storeCode ) {
802
803
$ updateEntityFunctionCall .= sprintf (", \"%s \"); \n" , $ storeCode );
803
804
} else {
804
805
$ updateEntityFunctionCall .= "); \n" ;
@@ -865,7 +866,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
865
866
$ getEntityFunctionCall .= 'null ' ;
866
867
}
867
868
868
- if (isset ( $ storeCode) ) {
869
+ if ($ storeCode ) {
869
870
$ getEntityFunctionCall .= sprintf (", \"%s \"); \n" , $ storeCode );
870
871
} else {
871
872
$ getEntityFunctionCall .= "); \n" ;
@@ -1222,9 +1223,10 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
1222
1223
break ;
1223
1224
case "field " :
1224
1225
$ fieldKey = $ actionObject ->getCustomActionAttributes ()['key ' ];
1226
+ $ input = $ this ->resolveTestVariable ([$ input ], $ actionObject ->getActionOrigin ())[0 ];
1225
1227
$ argRef = "\t\t\$" ;
1226
1228
$ argRef .= str_replace (ucfirst ($ fieldKey ), "" , $ stepKey ) . "Fields[' {$ fieldKey }'] = $ {input}; \n" ;
1227
- $ testSteps .= $ this -> resolveTestVariable ( $ argRef, [ $ input ], $ actionObject -> getActionOrigin ()) ;
1229
+ $ testSteps .= $ argRef ;
1228
1230
break ;
1229
1231
default :
1230
1232
$ testSteps .= $ this ->wrapFunctionCall ($ actor , $ actionObject , $ selector , $ input , $ parameter );
@@ -1253,19 +1255,16 @@ private function resolveLocatorFunctionInAttribute($attribute)
1253
1255
* Resolves replacement of $input$ and $$input$$ in given function, recursing and replacing individual arguments
1254
1256
* Also determines if each argument requires any quote replacement.
1255
1257
*
1256
- * @param string $inputString
1257
1258
* @param array $args
1258
1259
* @param array $actionOrigin
1259
- * @return string
1260
+ * @return array
1260
1261
* @throws \Exception
1261
1262
*/
1262
- private function resolveTestVariable ($ inputString , $ args , $ actionOrigin )
1263
+ private function resolveTestVariable ($ args , $ actionOrigin )
1263
1264
{
1264
- $ outputString = $ inputString ;
1265
-
1266
- //Loop through each argument, replace and then replace
1267
- foreach ($ args as $ arg ) {
1268
- if ($ arg == null ) {
1265
+ $ newArgs = [];
1266
+ foreach ($ args as $ key => $ arg ) {
1267
+ if ($ arg === null ) {
1269
1268
continue ;
1270
1269
}
1271
1270
$ outputArg = $ arg ;
@@ -1282,10 +1281,10 @@ private function resolveTestVariable($inputString, $args, $actionOrigin)
1282
1281
1283
1282
$ outputArg = $ this ->resolveStepKeyReferences ($ outputArg , $ actionOrigin );
1284
1283
1285
- $ outputString = str_replace ( $ arg , $ outputArg, $ outputString ) ;
1284
+ $ newArgs [ $ key ] = $ outputArg ;
1286
1285
}
1287
1286
1288
- return $ outputString ;
1287
+ return $ newArgs ;
1289
1288
}
1290
1289
1291
1290
/**
@@ -1665,20 +1664,17 @@ private function wrapFunctionCall($actor, $action, ...$args)
1665
1664
if (null === $ args [$ i ]) {
1666
1665
continue ;
1667
1666
}
1668
- if (!$ isFirst ) {
1669
- $ output .= ', ' ;
1670
- }
1671
1667
if ($ args [$ i ] === "" ) {
1672
1668
$ args [$ i ] = '" ' . $ args [$ i ] . '" ' ;
1673
1669
}
1674
- $ output .= $ args [$ i ];
1675
- $ isFirst = false ;
1676
1670
}
1677
- $ output .= "); \n" ;
1678
-
1679
- $ output = $ this ->resolveEnvReferences ($ output , $ args );
1680
-
1681
- return $ this ->resolveTestVariable ($ output , $ args , $ action ->getActionOrigin ());
1671
+ if (!is_array ($ args )) {
1672
+ $ args = [$ args ];
1673
+ }
1674
+ $ args = $ this ->resolveEnvReferences ($ args );
1675
+ $ args = $ this ->resolveTestVariable ($ args , $ action ->getActionOrigin ());
1676
+ $ output .= implode (", " , array_filter ($ args , function ($ value ) { return $ value !== null ; })) . "); \n" ;
1677
+ return $ output ;
1682
1678
}
1683
1679
1684
1680
/**
@@ -1699,36 +1695,32 @@ private function wrapFunctionCallWithReturnValue($returnVariable, $actor, $actio
1699
1695
if (null === $ args [$ i ]) {
1700
1696
continue ;
1701
1697
}
1702
- if (!$ isFirst ) {
1703
- $ output .= ', ' ;
1704
- }
1705
1698
if ($ args [$ i ] === "" ) {
1706
1699
$ args [$ i ] = '" ' . $ args [$ i ] . '" ' ;
1707
1700
}
1708
- $ output .= $ args [$ i ];
1709
- $ isFirst = false ;
1710
1701
}
1711
- $ output .= "); \n" ;
1712
-
1713
- $ output = $ this ->resolveEnvReferences ($ output , $ args );
1714
-
1715
- return $ this ->resolveTestVariable ($ output , $ args , $ action ->getActionOrigin ());
1702
+ if (!is_array ($ args )) {
1703
+ $ args = [$ args ];
1704
+ }
1705
+ $ args = $ this ->resolveEnvReferences ($ args );
1706
+ $ args = $ this ->resolveTestVariable ($ args , $ action ->getActionOrigin ());
1707
+ $ output .= implode (", " , array_filter ($ args , function ($ value ) { return $ value !== null ; })) . "); \n" ;
1708
+ return $ output ;
1716
1709
}
1717
1710
// @codingStandardsIgnoreEnd
1718
1711
1719
1712
/**
1720
1713
* Resolves {{_ENV.variable}} into getenv("variable") for test-runtime ENV referencing.
1721
- * @param string $inputString
1722
1714
* @param array $args
1723
- * @return string
1715
+ * @return array
1724
1716
*/
1725
- private function resolveEnvReferences ($ inputString , $ args )
1717
+ private function resolveEnvReferences ($ args )
1726
1718
{
1727
1719
$ envRegex = "/{{_ENV\.([\w]+)}}/ " ;
1728
1720
1729
- $ outputString = $ inputString ;
1721
+ $ newArgs = [] ;
1730
1722
1731
- foreach ($ args as $ arg ) {
1723
+ foreach ($ args as $ key => $ arg ) {
1732
1724
preg_match_all ($ envRegex , $ arg , $ matches );
1733
1725
if (!empty ($ matches [0 ])) {
1734
1726
$ fullMatch = $ matches [0 ][0 ];
@@ -1737,11 +1729,14 @@ private function resolveEnvReferences($inputString, $args)
1737
1729
$ replacement = "getenv( \"{$ envVariable }\") " ;
1738
1730
1739
1731
$ outputArg = $ this ->processQuoteBreaks ($ fullMatch , $ arg , $ replacement );
1740
- $ outputString = str_replace ($ arg , $ outputArg , $ outputString );
1732
+ $ newArgs [$ key ] = $ outputArg ;
1733
+ continue ;
1741
1734
}
1735
+ $ newArgs [$ key ] = $ arg ;
1742
1736
}
1743
1737
1744
- return $ outputString ;
1738
+ // override passed in args for use later.
1739
+ return $ newArgs ;
1745
1740
}
1746
1741
1747
1742
/**
0 commit comments