9
9
use Magento \SemanticVersionChecker \MftfReport ;
10
10
use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupActionAdded ;
11
11
use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupActionChanged ;
12
- use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupActionRemove ;
12
+ use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupActionRemoved ;
13
13
use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupActionTypeChanged ;
14
14
use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupAdded ;
15
15
use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupArgumentAdded ;
16
16
use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupArgumentChanged ;
17
- use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupArgumentRemove ;
18
- use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupRemove ;
17
+ use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupArgumentRemoved ;
18
+ use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupRemoved ;
19
19
use Magento \SemanticVersionChecker \Scanner \MftfScanner ;
20
20
use PHPSemVerChecker \Registry \Registry ;
21
21
use PHPSemVerChecker \Report \Report ;
22
+ use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupRemoveActionRemoved ;
23
+ use Magento \SemanticVersionChecker \Operation \Mftf \ActionGroup \ActionGroupRemoveActionAdded ;
22
24
23
25
class ActionGroupAnalyzer extends AbstractEntityAnalyzer
24
26
{
25
27
const MFTF_ARGUMENTS_ELEMENT = "{}arguments " ;
26
28
const MFTF_DATA_TYPE = 'actionGroup ' ;
27
29
const MFTF_DATA_DIRECTORY = '/Mftf/ActionGroup/ ' ;
28
30
31
+ /**
32
+ * operations array
33
+ *
34
+ * @var string[][]
35
+ */
36
+ private static $ operations = [
37
+ 'stepKey ' => [
38
+ 'add ' => ActionGroupActionAdded::class,
39
+ 'remove ' => ActionGroupActionRemoved::class,
40
+ ],
41
+ 'keyForRemoval ' => [
42
+ 'add ' => ActionGroupRemoveActionAdded::class,
43
+ 'remove ' => ActionGroupRemoveActionRemoved::class,
44
+ ],
45
+ ];
46
+
29
47
/**
30
48
* MFTF actionGroup.xml analyzer
31
49
*
@@ -56,7 +74,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
56
74
57
75
// Validate section still exists
58
76
if (!isset ($ afterEntities [$ module ][$ entityName ])) {
59
- $ operation = new ActionGroupRemove ($ filenames , $ operationTarget );
77
+ $ operation = new ActionGroupRemoved ($ filenames , $ operationTarget );
60
78
$ this ->getReport ()->add (MftfReport::MFTF_REPORT_CONTEXT , $ operation );
61
79
continue ;
62
80
}
@@ -85,25 +103,33 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
85
103
86
104
// Validate <actions>
87
105
foreach ($ beforeActions as $ testAction ) {
88
- if (!isset ($ testAction ['attributes ' ]['stepKey ' ])) {
106
+ if (isset ($ testAction ['attributes ' ]['stepKey ' ])) {
107
+ $ elementIdentifier = 'stepKey ' ;
108
+ } elseif (isset ($ testAction ['attributes ' ]['keyForRemoval ' ])) {
109
+ $ elementIdentifier = 'keyForRemoval ' ;
110
+ } else {
89
111
continue ;
90
112
}
91
- $ beforeFieldKey = $ testAction ['attributes ' ]['stepKey ' ];
113
+
114
+ $ beforeFieldKey = $ testAction ['attributes ' ][$ elementIdentifier ];
92
115
$ matchingElement = $ this ->findMatchingElement (
93
116
$ testAction ,
94
117
$ afterActions ,
95
- ' stepKey '
118
+ $ elementIdentifier
96
119
);
97
120
if ($ matchingElement === null ) {
98
- $ operation = new ActionGroupActionRemove ($ filenames , $ operationTarget . '/ ' . $ beforeFieldKey );
121
+ $ operation = new self::$ operations [$ elementIdentifier ]['remove ' ](
122
+ $ filenames ,
123
+ $ operationTarget . '/ ' . $ beforeFieldKey
124
+ );
99
125
$ this ->getReport ()->add (MftfReport::MFTF_REPORT_CONTEXT , $ operation );
100
126
} else {
101
127
$ this ->matchAndValidateAttributes (
102
128
$ testAction ['attributes ' ],
103
129
$ matchingElement ['attributes ' ],
104
130
$ this ->getReport (),
105
131
$ filenames ,
106
- ActionGroupActionChanged::class,
132
+ [AbstractEntityAnalyzer:: DEFAULT_OPERATION_KEY => ActionGroupActionChanged::class] ,
107
133
"$ operationTarget/ $ beforeFieldKey "
108
134
);
109
135
$ this ->matchAndValidateElementType (
@@ -116,22 +142,24 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
116
142
);
117
143
}
118
144
}
119
- $ this ->findAddedElementsInArray (
120
- $ beforeActions ,
121
- $ afterActions ,
122
- 'stepKey ' ,
123
- $ this ->getReport (),
124
- $ filenames ,
125
- ActionGroupActionAdded::class,
126
- $ operationTarget
127
- );
145
+ foreach (self ::$ operations as $ identifier => $ operations ) {
146
+ $ this ->findAddedElementsInArray (
147
+ $ beforeActions ,
148
+ $ afterActions ,
149
+ $ identifier ,
150
+ $ this ->getReport (),
151
+ $ filenames ,
152
+ $ operations ['add ' ],
153
+ $ operationTarget
154
+ );
155
+ }
128
156
129
157
// Validate <arguments>
130
158
foreach ($ beforeArguments as $ argument ) {
131
159
$ beforeFieldKey = $ argument ['attributes ' ]['name ' ];
132
160
$ matchingElement = $ this ->findMatchingElement ($ argument , $ afterArguments ,'name ' );
133
161
if ($ matchingElement === null ) {
134
- $ operation = new ActionGroupArgumentRemove (
162
+ $ operation = new ActionGroupArgumentRemoved (
135
163
$ filenames ,
136
164
$ operationTarget . '/Arguments/ ' . $ beforeFieldKey
137
165
);
@@ -142,7 +170,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
142
170
$ matchingElement ['attributes ' ],
143
171
$ this ->getReport (),
144
172
$ filenames ,
145
- ActionGroupArgumentChanged::class,
173
+ [AbstractEntityAnalyzer:: DEFAULT_OPERATION_KEY => ActionGroupArgumentChanged::class] ,
146
174
"$ operationTarget/ $ beforeFieldKey "
147
175
);
148
176
0 commit comments