@@ -18,6 +18,7 @@ class TestGenerator
1818{
1919
2020 const REQUIRED_ENTITY_REFERENCE = 'createDataKey ' ;
21+ const TEST_SCOPE = 'Test ' ;
2122 const GENERATED_DIR = '_generated ' ;
2223
2324 /**
@@ -151,7 +152,7 @@ public function createAllCestFiles($runConfig = null)
151152 private function assembleCestPhp ($ cestObject )
152153 {
153154 $ usePhp = $ this ->generateUseStatementsPhp ();
154- $ classAnnotationsPhp = $ this ->generateClassAnnotationsPhp ($ cestObject ->getAnnotations ());
155+ $ classAnnotationsPhp = $ this ->generateAnnotationsPhp ($ cestObject ->getAnnotations (), " Cest " );
155156 $ className = $ cestObject ->getName ();
156157 $ className = str_replace (' ' , '' , $ className );
157158 try {
@@ -234,17 +235,22 @@ private function generateUseStatementsPhp()
234235 }
235236
236237 /**
237- * Creates a PHP string for the Class Annotations block if the Cest file contains an <annotations> block, outside
238- * of the <test> blocks.
239- *
240- * @param array $classAnnotationsObject
238+ * Generates Annotations PHP for given object, using given scope to determine indentation and additional output.
239+ * @param array $annotationsObject
240+ * @param string $scope
241241 * @return string
242242 */
243- private function generateClassAnnotationsPhp ( $ classAnnotationsObject )
243+ private function generateAnnotationsPhp ( $ annotationsObject , $ scope )
244244 {
245- $ classAnnotationsPhp = "/** \n" ;
245+ if ($ scope == self ::TEST_SCOPE ) {
246+ $ indent = "\t" ;
247+ } else {
248+ $ indent = "" ;
249+ }
246250
247- foreach ($ classAnnotationsObject as $ annotationType => $ annotationName ) {
251+ $ annotationsPhp = "{$ indent }/** \n" ;
252+
253+ foreach ($ annotationsObject as $ annotationType => $ annotationName ) {
248254 if ($ annotationType == "features " ) {
249255 $ features = "" ;
250256
@@ -256,7 +262,7 @@ private function generateClassAnnotationsPhp($classAnnotationsObject)
256262 }
257263 }
258264
259- $ classAnnotationsPhp .= sprintf (" * @Features({%s}) \n" , $ features );
265+ $ annotationsPhp .= sprintf ("{ $ indent } * @Features({%s}) \n" , $ features );
260266 }
261267
262268 if ($ annotationType == "stories " ) {
@@ -270,45 +276,55 @@ private function generateClassAnnotationsPhp($classAnnotationsObject)
270276 }
271277 }
272278
273- $ classAnnotationsPhp .= sprintf (" * @Stories({%s}) \n" , $ stories );
279+ $ annotationsPhp .= sprintf ("{ $ indent } * @Stories({%s}) \n" , $ stories );
274280 }
275281
276282 if ($ annotationType == "title " ) {
277- $ classAnnotationsPhp .= sprintf (
278- " * @Title( \"%s \") \n" ,
279- ucwords ($ annotationType ),
280- $ annotationName [0 ]
281- );
283+ $ annotationsPhp .= sprintf ("{$ indent } * @Title( \"%s \") \n" , $ annotationName [0 ]);
282284 }
283285
284286 if ($ annotationType == "description " ) {
285- $ classAnnotationsPhp .= sprintf (" * @Description( \"%s \") \n" , $ annotationName [0 ]);
287+ $ annotationsPhp .= sprintf ("{ $ indent } * @Description( \"%s \") \n" , $ annotationName [0 ]);
286288 }
287289
288290 if ($ annotationType == "severity " ) {
289- $ classAnnotationsPhp .= sprintf (" * @Severity(level = SeverityLevel::%s) \n" , $ annotationName [0 ]);
291+ $ annotationsPhp .= sprintf ("{ $ indent } * @Severity(level = SeverityLevel::%s) \n" , $ annotationName [0 ]);
290292 }
291293
292294 if ($ annotationType == "testCaseId " ) {
293- $ classAnnotationsPhp .= sprintf (" * TestCaseId( \"%s \") \n" , $ annotationName [0 ]);
295+ $ annotationsPhp .= sprintf ("{$ indent } * @TestCaseId( \"%s \") \n" , $ annotationName [0 ]);
296+ }
297+
298+ if ($ annotationType == "useCaseId " ) {
299+ $ annotationsPhp .= sprintf ("{$ indent } * @UseCaseId( \"%s \") \n" , $ annotationName [0 ]);
294300 }
295301
296302 if ($ annotationType == "group " ) {
297303 foreach ($ annotationName as $ group ) {
298- $ classAnnotationsPhp .= sprintf (" * @group %s \n" , $ group );
304+ $ annotationsPhp .= sprintf ("{ $ indent } * @group %s \n" , $ group );
299305 }
300306 }
301307
302308 if ($ annotationType == "env " ) {
303309 foreach ($ annotationName as $ env ) {
304- $ classAnnotationsPhp .= sprintf (" * @env %s \n" , $ env );
310+ $ annotationsPhp .= sprintf ("{ $ indent } * @env %s \n" , $ env );
305311 }
306312 }
307313 }
308314
309- $ classAnnotationsPhp .= " */ \n" ;
315+ if ($ scope == self ::TEST_SCOPE ) {
316+ $ annotationsPhp .= sprintf (
317+ "{$ indent } * @Parameter(name = \"%s \", value= \"$%s \") \n" ,
318+ "AcceptanceTester " ,
319+ "I "
320+ );
321+ $ annotationsPhp .= sprintf ("{$ indent } * @param %s $%s \n" , "AcceptanceTester " , "I " );
322+ $ annotationsPhp .= "{$ indent } * @return void \n" ;
323+ }
324+
325+ $ annotationsPhp .= "{$ indent } */ \n" ;
310326
311- return $ classAnnotationsPhp ;
327+ return $ annotationsPhp ;
312328 }
313329
314330 /**
@@ -1119,97 +1135,12 @@ private function generateHooksPhp($hookObjects)
11191135 return $ hooks ;
11201136 }
11211137
1122- /**
1123- * Creates a PHP string for the Test Annotations block if the Test contains an <annotations> block.
1124- *
1125- * @param array $testAnnotationsObject
1126- * @return string
1127- */
1128- private function generateTestAnnotationsPhp ($ testAnnotationsObject )
1129- {
1130- $ testAnnotationsPhp = "\t/** \n" ;
1131-
1132- foreach ($ testAnnotationsObject as $ annotationType => $ annotationName ) {
1133- if ($ annotationType == "features " ) {
1134- $ features = "" ;
1135-
1136- foreach ($ annotationName as $ name ) {
1137- $ features .= sprintf ("\"%s \"" , $ name );
1138-
1139- if (next ($ annotationName )) {
1140- $ features .= ", " ;
1141- }
1142- }
1143-
1144- $ testAnnotationsPhp .= sprintf ("\t * @Features({%s}) \n" , $ features );
1145- }
1146-
1147- if ($ annotationType == "stories " ) {
1148- $ stories = "" ;
1149-
1150- foreach ($ annotationName as $ name ) {
1151- $ stories .= sprintf ("\"%s \"" , $ name );
1152-
1153- if (next ($ annotationName )) {
1154- $ stories .= ", " ;
1155- }
1156- }
1157-
1158- $ testAnnotationsPhp .= sprintf ("\t * @Stories({%s}) \n" , $ stories );
1159- }
1160-
1161- if ($ annotationType == "title " ) {
1162- $ testAnnotationsPhp .= sprintf ("\t * @Title( \"%s \") \n" , $ annotationName [0 ]);
1163- }
1164-
1165- if ($ annotationType == "description " ) {
1166- $ testAnnotationsPhp .= sprintf ("\t * @Description( \"%s \") \n" , $ annotationName [0 ]);
1167- }
1168-
1169- if ($ annotationType == "severity " ) {
1170- $ testAnnotationsPhp .= sprintf (
1171- "\t * @Severity(level = SeverityLevel::%s) \n" ,
1172- $ annotationName [0 ]
1173- );
1174- }
1175-
1176- if ($ annotationType == "testCaseId " ) {
1177- $ testAnnotationsPhp .= sprintf ("\t * @TestCaseId( \"%s \") \n" , $ annotationName [0 ]);
1178- }
1179- }
1180-
1181- $ testAnnotationsPhp .= sprintf (
1182- "\t * @Parameter(name = \"%s \", value= \"$%s \") \n" ,
1183- "AcceptanceTester " ,
1184- "I "
1185- );
1186-
1187- foreach ($ testAnnotationsObject as $ annotationType => $ annotationName ) {
1188- if ($ annotationType == "group " ) {
1189- foreach ($ annotationName as $ name ) {
1190- $ testAnnotationsPhp .= sprintf ("\t * @group %s \n" , $ name );
1191- }
1192- }
1193-
1194- if ($ annotationType == "env " ) {
1195- foreach ($ annotationName as $ env ) {
1196- $ testAnnotationsPhp .= sprintf ("\t * @env %s \n" , $ env );
1197- }
1198- }
1199- }
1200-
1201- $ testAnnotationsPhp .= sprintf ("\t * @param %s $%s \n" , "AcceptanceTester " , "I " );
1202- $ testAnnotationsPhp .= "\t * @return void \n" ;
1203- $ testAnnotationsPhp .= "\t */ \n" ;
1204-
1205- return $ testAnnotationsPhp ;
1206- }
1207-
12081138 /**
12091139 * Creates a PHP string based on a <test> block.
12101140 * Concatenates the Test Annotations PHP and Test PHP for a single Test.
12111141 * @param array $testsObject
12121142 * @return string
1143+ * @throws TestReferenceException
12131144 */
12141145 private function generateTestsPhp ($ testsObject )
12151146 {
@@ -1218,7 +1149,7 @@ private function generateTestsPhp($testsObject)
12181149 foreach ($ testsObject as $ test ) {
12191150 $ testName = $ test ->getName ();
12201151 $ testName = str_replace (' ' , '' , $ testName );
1221- $ testAnnotations = $ this ->generateTestAnnotationsPhp ($ test ->getAnnotations ());
1152+ $ testAnnotations = $ this ->generateAnnotationsPhp ($ test ->getAnnotations (), " Test " );
12221153 $ dependencies = 'AcceptanceTester $I ' ;
12231154 try {
12241155 $ steps = $ this ->generateStepsPhp ($ test ->getOrderedActions (), $ test ->getCustomData ());
0 commit comments