Skip to content

Commit 2e966be

Browse files
authored
MQE-497: Add useCaseId annotation
- added useCaseId to Test Schema. - di.xml changes - Refarctored TestGenerator to use a single Annotation Generation mechanism. - Updated Verification Tests, turns out there was a bug in existing code.
1 parent dceff25 commit 2e966be

File tree

6 files changed

+47
-113
lines changed

6 files changed

+47
-113
lines changed

dev/tests/verification/Resources/ActionGroupFunctionalCest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use Yandex\Allure\Adapter\Annotation\TestCaseId;
1717

1818
/**
1919
* @Severity(level = SeverityLevel::CRITICAL)
20-
* @Title("Title")
20+
* @Title("A Functional Cest")
2121
* @group functional
2222
* @Features({"Action Group Functional Cest"})
2323
* @Stories({"MQE-433"})

dev/tests/verification/Resources/BasicFunctionalCest.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use Yandex\Allure\Adapter\Annotation\TestCaseId;
1717

1818
/**
1919
* @Severity(level = SeverityLevel::CRITICAL)
20-
* @Title("Title")
20+
* @Title("A Functional Cest")
2121
* @group functional
2222
* @Features({"Basic Functional Cest"})
2323
* @Stories({"MQE-305"})
@@ -37,10 +37,10 @@ class BasicFunctionalCest
3737
/**
3838
* @Severity(level = SeverityLevel::SEVERE)
3939
* @Title("Basic Functional Test")
40+
* @group functionalTest
4041
* @Features({"Hardcoded Functional Test"})
4142
* @Stories({"MQE-425"})
4243
* @Parameter(name = "AcceptanceTester", value="$I")
43-
* @group functionalTest
4444
* @param AcceptanceTester $I
4545
* @return void
4646
*/

dev/tests/verification/Resources/MergeFunctionalCest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use Yandex\Allure\Adapter\Annotation\TestCaseId;
1717

1818
/**
1919
* @Severity(level = SeverityLevel::CRITICAL)
20-
* @Title("Title")
20+
* @Title("A Functional Cest")
2121
* @group mergeTest
2222
* @Features({"Merge Functional Cest"})
2323
* @Stories({"MQE-433"})

etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
<item name="/config/cest/annotations/description" xsi:type="string">/config/cest/annotations/description</item>
243243
<item name="/config/cest/annotations/severity" xsi:type="string">/config/cest/annotations/severity</item>
244244
<item name="/config/cest/annotations/testCaseId" xsi:type="string">/config/cest/annotations/testCaseId</item>
245+
<item name="/config/cest/annotations/useCaseId" xsi:type="string">/config/cest/annotations/useCaseId</item>
245246
<item name="/config/cest/annotations/group" xsi:type="string">/config/cest/annotations/group</item>
246247
<item name="/config/cest/annotations/return" xsi:type="string">/config/cest/annotations/return</item>
247248
<item name="/config/cest/test/annotations/features" xsi:type="string">/config/cest/test/annotations/features</item>
@@ -250,6 +251,7 @@
250251
<item name="/config/cest/test/annotations/description" xsi:type="string">/config/cest/test/annotations/description</item>
251252
<item name="/config/cest/test/annotations/severity" xsi:type="string">/config/cest/test/annotations/severity</item>
252253
<item name="/config/cest/test/annotations/testCaseId" xsi:type="string">/config/cest/test/annotations/testCaseId</item>
254+
<item name="/config/cest/test/annotations/useCaseId" xsi:type="string">/config/cest/test/annotations/useCaseId</item>
253255
<item name="/config/cest/test/annotations/group" xsi:type="string">/config/cest/test/annotations/group</item>
254256
<item name="/config/cest/test/annotations/env" xsi:type="string">/config/cest/test/annotations/env</item>
255257
<item name="/config/cest/test/annotations/return" xsi:type="string">/config/cest/test/annotations/return</item>

src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<xs:element type="annotationType" name="description" minOccurs="0" maxOccurs="unbounded"/>
5656
<xs:element type="annotationType" name="severity" minOccurs="0" maxOccurs="unbounded"/>
5757
<xs:element type="annotationType" name="testCaseId" minOccurs="0" maxOccurs="unbounded"/>
58+
<xs:element type="annotationType" name="useCaseId" minOccurs="0" maxOccurs="unbounded"/>
5859
<xs:element type="annotationType" name="group" minOccurs="0" maxOccurs="unbounded"/>
5960
<xs:element type="annotationType" name="return" minOccurs="0" maxOccurs="unbounded"/>
6061
</xs:choice>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 40 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)