@@ -18,6 +18,7 @@ class TestGenerator
18
18
{
19
19
20
20
const REQUIRED_ENTITY_REFERENCE = 'createDataKey ' ;
21
+ const TEST_SCOPE = 'Test ' ;
21
22
const GENERATED_DIR = '_generated ' ;
22
23
23
24
/**
@@ -151,7 +152,7 @@ public function createAllCestFiles($runConfig = null)
151
152
private function assembleCestPhp ($ cestObject )
152
153
{
153
154
$ usePhp = $ this ->generateUseStatementsPhp ();
154
- $ classAnnotationsPhp = $ this ->generateClassAnnotationsPhp ($ cestObject ->getAnnotations ());
155
+ $ classAnnotationsPhp = $ this ->generateAnnotationsPhp ($ cestObject ->getAnnotations (), " Cest " );
155
156
$ className = $ cestObject ->getName ();
156
157
$ className = str_replace (' ' , '' , $ className );
157
158
try {
@@ -234,17 +235,22 @@ private function generateUseStatementsPhp()
234
235
}
235
236
236
237
/**
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
241
241
* @return string
242
242
*/
243
- private function generateClassAnnotationsPhp ( $ classAnnotationsObject )
243
+ private function generateAnnotationsPhp ( $ annotationsObject , $ scope )
244
244
{
245
- $ classAnnotationsPhp = "/** \n" ;
245
+ if ($ scope == self ::TEST_SCOPE ) {
246
+ $ indent = "\t" ;
247
+ } else {
248
+ $ indent = "" ;
249
+ }
246
250
247
- foreach ($ classAnnotationsObject as $ annotationType => $ annotationName ) {
251
+ $ annotationsPhp = "{$ indent }/** \n" ;
252
+
253
+ foreach ($ annotationsObject as $ annotationType => $ annotationName ) {
248
254
if ($ annotationType == "features " ) {
249
255
$ features = "" ;
250
256
@@ -256,7 +262,7 @@ private function generateClassAnnotationsPhp($classAnnotationsObject)
256
262
}
257
263
}
258
264
259
- $ classAnnotationsPhp .= sprintf (" * @Features({%s}) \n" , $ features );
265
+ $ annotationsPhp .= sprintf ("{ $ indent } * @Features({%s}) \n" , $ features );
260
266
}
261
267
262
268
if ($ annotationType == "stories " ) {
@@ -270,45 +276,55 @@ private function generateClassAnnotationsPhp($classAnnotationsObject)
270
276
}
271
277
}
272
278
273
- $ classAnnotationsPhp .= sprintf (" * @Stories({%s}) \n" , $ stories );
279
+ $ annotationsPhp .= sprintf ("{ $ indent } * @Stories({%s}) \n" , $ stories );
274
280
}
275
281
276
282
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 ]);
282
284
}
283
285
284
286
if ($ annotationType == "description " ) {
285
- $ classAnnotationsPhp .= sprintf (" * @Description( \"%s \") \n" , $ annotationName [0 ]);
287
+ $ annotationsPhp .= sprintf ("{ $ indent } * @Description( \"%s \") \n" , $ annotationName [0 ]);
286
288
}
287
289
288
290
if ($ annotationType == "severity " ) {
289
- $ classAnnotationsPhp .= sprintf (" * @Severity(level = SeverityLevel::%s) \n" , $ annotationName [0 ]);
291
+ $ annotationsPhp .= sprintf ("{ $ indent } * @Severity(level = SeverityLevel::%s) \n" , $ annotationName [0 ]);
290
292
}
291
293
292
294
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 ]);
294
300
}
295
301
296
302
if ($ annotationType == "group " ) {
297
303
foreach ($ annotationName as $ group ) {
298
- $ classAnnotationsPhp .= sprintf (" * @group %s \n" , $ group );
304
+ $ annotationsPhp .= sprintf ("{ $ indent } * @group %s \n" , $ group );
299
305
}
300
306
}
301
307
302
308
if ($ annotationType == "env " ) {
303
309
foreach ($ annotationName as $ env ) {
304
- $ classAnnotationsPhp .= sprintf (" * @env %s \n" , $ env );
310
+ $ annotationsPhp .= sprintf ("{ $ indent } * @env %s \n" , $ env );
305
311
}
306
312
}
307
313
}
308
314
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" ;
310
326
311
- return $ classAnnotationsPhp ;
327
+ return $ annotationsPhp ;
312
328
}
313
329
314
330
/**
@@ -1119,97 +1135,12 @@ private function generateHooksPhp($hookObjects)
1119
1135
return $ hooks ;
1120
1136
}
1121
1137
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
-
1208
1138
/**
1209
1139
* Creates a PHP string based on a <test> block.
1210
1140
* Concatenates the Test Annotations PHP and Test PHP for a single Test.
1211
1141
* @param array $testsObject
1212
1142
* @return string
1143
+ * @throws TestReferenceException
1213
1144
*/
1214
1145
private function generateTestsPhp ($ testsObject )
1215
1146
{
@@ -1218,7 +1149,7 @@ private function generateTestsPhp($testsObject)
1218
1149
foreach ($ testsObject as $ test ) {
1219
1150
$ testName = $ test ->getName ();
1220
1151
$ testName = str_replace (' ' , '' , $ testName );
1221
- $ testAnnotations = $ this ->generateTestAnnotationsPhp ($ test ->getAnnotations ());
1152
+ $ testAnnotations = $ this ->generateAnnotationsPhp ($ test ->getAnnotations (), " Test " );
1222
1153
$ dependencies = 'AcceptanceTester $I ' ;
1223
1154
try {
1224
1155
$ steps = $ this ->generateStepsPhp ($ test ->getOrderedActions (), $ test ->getCustomData ());
0 commit comments