-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathActionGroupAnnotationExtractor.php
86 lines (76 loc) · 2.58 KB
/
ActionGroupAnnotationExtractor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Test\Util;
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
/**
* Class AnnotationExtractor
*/
class ActionGroupAnnotationExtractor extends AnnotationExtractor
{
const ACTION_GROUP_REQUIRED_ANNOTATIONS = [
"description"
];
const GENERATE_DOCS_COMMAND = 'generate:docs';
/**
* This method trims away irrelevant tags and returns annotations used in the array passed. The annotations
* can be found in both Tests and their child element tests.
*
* @param array $testAnnotations
* @param string $filename
* @return array
* @throws \Exception
*/
public function extractAnnotations($testAnnotations, $filename)
{
$annotationObjects = [];
$annotations = $this->stripDescriptorTags($testAnnotations, parent::NODE_NAME);
foreach ($annotations as $annotationKey => $annotationData) {
$annotationObjects[$annotationKey] = $annotationData[parent::ANNOTATION_VALUE];
}
// TODO: Remove this when all action groups have annotations
if ($this->isCommandDefined()) {
$this->validateMissingAnnotations($annotationObjects, $filename);
}
return $annotationObjects;
}
/**
* Validates given annotations against list of required annotations.
*
* @param array $annotationObjects
* @return void
* @throws \Exception
*/
private function validateMissingAnnotations($annotationObjects, $filename)
{
$missingAnnotations = [];
foreach (self::ACTION_GROUP_REQUIRED_ANNOTATIONS as $REQUIRED_ANNOTATION) {
if (!array_key_exists($REQUIRED_ANNOTATION, $annotationObjects)) {
$missingAnnotations[] = $REQUIRED_ANNOTATION;
}
}
if (!empty($missingAnnotations)) {
$message = "Action Group File {$filename} is missing required annotations.";
LoggingUtil::getInstance()->getLogger(ActionObject::class)->deprecation(
$message,
["actionGroup" => $filename, "missingAnnotations" => implode(", ", $missingAnnotations)],
true
);
}
}
/**
* Checks if command is defined as generate:docs
*
* @return boolean
*/
private function isCommandDefined()
{
if (defined('COMMAND') and COMMAND == self::GENERATE_DOCS_COMMAND) {
return true;
} else {
return false;
}
}
}