Skip to content

Commit 8959d04

Browse files
committed
MQE-2195: refactored mftf svc code and incorporated in magento-semver repo
- Added ation group ref change case - Added adding/removing/changing <remove> action case
1 parent f8512c5 commit 8959d04

File tree

51 files changed

+607
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+607
-127
lines changed

src/Analyzer/Mftf/AbstractEntityAnalyzer.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
abstract class AbstractEntityAnalyzer
1616
{
17+
const DEFAULT_OPERATION_KEY = '*';
18+
1719
/**
1820
* @var Report
1921
*/
@@ -76,13 +78,13 @@ public function findMatchingElementByKeyAndValue($beforeElement, $afterElements,
7678
}
7779

7880
/**
79-
* Matches and validates all attributes of two given xml elements, adding operations according to class passed in
81+
* Matches and validates all attributes of two given xml elements, adding operations given
8082
*
8183
* @param array $beforeAttributes
8284
* @param array $afterAttributes
8385
* @param Report $report
8486
* @param string $filenames
85-
* @param string $operationClass
87+
* @param array $operations
8688
* @param string $fullOperationTarget
8789
* @return void
8890
*/
@@ -91,12 +93,17 @@ public function matchAndValidateAttributes(
9193
$afterAttributes,
9294
$report,
9395
$filenames,
94-
$operationClass,
96+
$operations,
9597
$fullOperationTarget
9698
) {
9799
foreach ($beforeAttributes as $key => $beforeAttribute) {
98100
$matchingAttribute = $afterAttributes[$key] ?? null;
99101
if ($beforeAttribute !== $matchingAttribute) {
102+
if (isset($operations[$key])) {
103+
$operationClass = $operations[$key];
104+
} else {
105+
$operationClass = $operations[self::DEFAULT_OPERATION_KEY];
106+
}
100107
$operation = new $operationClass($filenames, "$fullOperationTarget/$key");
101108
$report->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
102109
}

src/Analyzer/Mftf/ActionGroupAnalyzer.php

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,41 @@
99
use Magento\SemanticVersionChecker\MftfReport;
1010
use Magento\SemanticVersionChecker\Operation\Mftf\ActionGroup\ActionGroupActionAdded;
1111
use Magento\SemanticVersionChecker\Operation\Mftf\ActionGroup\ActionGroupActionChanged;
12-
use Magento\SemanticVersionChecker\Operation\Mftf\ActionGroup\ActionGroupActionRemove;
12+
use Magento\SemanticVersionChecker\Operation\Mftf\ActionGroup\ActionGroupActionRemoved;
1313
use Magento\SemanticVersionChecker\Operation\Mftf\ActionGroup\ActionGroupActionTypeChanged;
1414
use Magento\SemanticVersionChecker\Operation\Mftf\ActionGroup\ActionGroupAdded;
1515
use Magento\SemanticVersionChecker\Operation\Mftf\ActionGroup\ActionGroupArgumentAdded;
1616
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;
1919
use Magento\SemanticVersionChecker\Scanner\MftfScanner;
2020
use PHPSemVerChecker\Registry\Registry;
2121
use PHPSemVerChecker\Report\Report;
22+
use Magento\SemanticVersionChecker\Operation\Mftf\ActionGroup\ActionGroupRemoveActionRemoved;
23+
use Magento\SemanticVersionChecker\Operation\Mftf\ActionGroup\ActionGroupRemoveActionAdded;
2224

2325
class ActionGroupAnalyzer extends AbstractEntityAnalyzer
2426
{
2527
const MFTF_ARGUMENTS_ELEMENT = "{}arguments";
2628
const MFTF_DATA_TYPE = 'actionGroup';
2729
const MFTF_DATA_DIRECTORY = '/Mftf/ActionGroup/';
2830

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+
2947
/**
3048
* MFTF actionGroup.xml analyzer
3149
*
@@ -56,7 +74,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
5674

5775
// Validate section still exists
5876
if (!isset($afterEntities[$module][$entityName])) {
59-
$operation = new ActionGroupRemove($filenames, $operationTarget);
77+
$operation = new ActionGroupRemoved($filenames, $operationTarget);
6078
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
6179
continue;
6280
}
@@ -85,25 +103,33 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
85103

86104
// Validate <actions>
87105
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 {
89111
continue;
90112
}
91-
$beforeFieldKey = $testAction['attributes']['stepKey'];
113+
114+
$beforeFieldKey = $testAction['attributes'][$elementIdentifier];
92115
$matchingElement = $this->findMatchingElement(
93116
$testAction,
94117
$afterActions,
95-
'stepKey'
118+
$elementIdentifier
96119
);
97120
if ($matchingElement === null) {
98-
$operation = new ActionGroupActionRemove($filenames, $operationTarget . '/' . $beforeFieldKey);
121+
$operation = new self::$operations[$elementIdentifier]['remove'](
122+
$filenames,
123+
$operationTarget . '/' . $beforeFieldKey
124+
);
99125
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
100126
} else {
101127
$this->matchAndValidateAttributes(
102128
$testAction['attributes'],
103129
$matchingElement['attributes'],
104130
$this->getReport(),
105131
$filenames,
106-
ActionGroupActionChanged::class,
132+
[AbstractEntityAnalyzer::DEFAULT_OPERATION_KEY => ActionGroupActionChanged::class],
107133
"$operationTarget/$beforeFieldKey"
108134
);
109135
$this->matchAndValidateElementType(
@@ -116,22 +142,24 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
116142
);
117143
}
118144
}
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+
}
128156

129157
// Validate <arguments>
130158
foreach ($beforeArguments as $argument) {
131159
$beforeFieldKey = $argument['attributes']['name'];
132160
$matchingElement = $this->findMatchingElement($argument, $afterArguments,'name');
133161
if ($matchingElement === null) {
134-
$operation = new ActionGroupArgumentRemove(
162+
$operation = new ActionGroupArgumentRemoved(
135163
$filenames,
136164
$operationTarget . '/Arguments/' . $beforeFieldKey
137165
);
@@ -142,7 +170,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
142170
$matchingElement['attributes'],
143171
$this->getReport(),
144172
$filenames,
145-
ActionGroupArgumentChanged::class,
173+
[AbstractEntityAnalyzer::DEFAULT_OPERATION_KEY => ActionGroupArgumentChanged::class],
146174
"$operationTarget/$beforeFieldKey"
147175
);
148176

src/Analyzer/Mftf/DataAnalyzer.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
use Magento\SemanticVersionChecker\MftfReport;
1010
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityAdded;
1111
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityArrayAdded;
12-
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityArrayRemove;
13-
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityArrayItemRemove;
12+
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityArrayRemoved;
13+
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityArrayItemRemoved;
1414
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityFieldAdded;
15-
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityFieldRemove;
16-
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityRemove;
15+
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityFieldRemoved;
16+
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityRemoved;
1717
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityReqEntityAdded;
18-
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityReqEntityRemove;
18+
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityReqEntityRemoved;
1919
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityVarAdded;
20-
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityVarRemove;
20+
use Magento\SemanticVersionChecker\Operation\Mftf\Data\DataEntityVarRemoved;
2121
use Magento\SemanticVersionChecker\Scanner\MftfScanner;
2222
use PHPSemVerChecker\Registry\Registry;
2323
use PHPSemVerChecker\Report\Report;
@@ -61,7 +61,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
6161

6262
// Validate data entity still exists
6363
if (!isset($afterEntities[$module][$entityName])) {
64-
$operation = new DataEntityRemove($filenames, $operationTarget);
64+
$operation = new DataEntityRemoved($filenames, $operationTarget);
6565
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
6666
continue;
6767
}
@@ -110,7 +110,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
110110
'key'
111111
);
112112
if ($matchingElement === null) {
113-
$operation = new DataEntityFieldRemove(
113+
$operation = new DataEntityFieldRemoved(
114114
$filenames,
115115
$operationTarget . '/' . $beforeFieldKey
116116
);
@@ -131,7 +131,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
131131
$beforeFieldKey = $beforeField['attributes']['key'];
132132
$matchingElement = $this->findMatchingElement($beforeField, $afterVarFields,'key');
133133
if ($matchingElement === null) {
134-
$operation = new DataEntityVarRemove(
134+
$operation = new DataEntityVarRemoved(
135135
$filenames,
136136
$operationTarget . '/' . $beforeFieldKey
137137
);
@@ -156,7 +156,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
156156
'type'
157157
);
158158
if ($matchingElement === null) {
159-
$operation = new DataEntityReqEntityRemove(
159+
$operation = new DataEntityReqEntityRemoved(
160160
$filenames,
161161
$operationTarget . '/' . $beforeFieldValue
162162
);
@@ -181,7 +181,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
181181
'key'
182182
);
183183
if ($matchingElement === null) {
184-
$operation = new DataEntityArrayRemove(
184+
$operation = new DataEntityArrayRemoved(
185185
$filenames,
186186
$operationTarget . '/' . $beforeFieldKey
187187
);
@@ -197,7 +197,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
197197
}
198198
}
199199
if (count($itemValues) !== 0) {
200-
$operation = new DataEntityArrayItemRemove(
200+
$operation = new DataEntityArrayItemRemoved(
201201
$filenames,
202202
$operationTarget . '/' . $beforeFieldKey . '/(' . implode(", ", $itemValues) . ")"
203203
);

src/Analyzer/Mftf/MetadataAnalyzer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
use Magento\SemanticVersionChecker\MftfReport;
1010
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataAdded;
11-
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataChildRemove;
12-
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataRemove;
11+
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataChildRemoved;
12+
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataRemoved;
1313
use Magento\SemanticVersionChecker\Scanner\MftfScanner;
1414
use PHPSemVerChecker\Registry\Registry;
1515
use PHPSemVerChecker\Report\Report;
@@ -49,7 +49,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
4949

5050
// Validate section still exists
5151
if (!isset($afterEntities[$module][$entityName])) {
52-
$operation = new MetadataRemove($filenames, $operationTarget);
52+
$operation = new MetadataRemoved($filenames, $operationTarget);
5353
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
5454
continue;
5555
}
@@ -99,7 +99,7 @@ public function recursiveCompare($beforeEntity, $afterEntity, $operationTarget,
9999
}
100100
}
101101
if ($afterFound === null) {
102-
$operation = new MetadataChildRemove($filenames, $operationTarget . '/' . $beforeFieldKey);
102+
$operation = new MetadataChildRemoved($filenames, $operationTarget . '/' . $beforeFieldKey);
103103
$report->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
104104
} else {
105105
$this->recursiveCompare(

src/Analyzer/Mftf/PageAnalyzer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
use Magento\SemanticVersionChecker\MftfReport;
1010
use Magento\SemanticVersionChecker\Operation\Mftf\Page\PageAdded;
11-
use Magento\SemanticVersionChecker\Operation\Mftf\Page\PageRemove;
11+
use Magento\SemanticVersionChecker\Operation\Mftf\Page\PageRemoved;
1212
use Magento\SemanticVersionChecker\Operation\Mftf\Page\PageSectionAdded;
13-
use Magento\SemanticVersionChecker\Operation\Mftf\Page\PageSectionRemove;
13+
use Magento\SemanticVersionChecker\Operation\Mftf\Page\PageSectionRemoved;
1414
use Magento\SemanticVersionChecker\Scanner\MftfScanner;
1515
use PHPSemVerChecker\Registry\Registry;
1616
use PHPSemVerChecker\Report\Report;
@@ -51,7 +51,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
5151

5252
// Validate page still exists
5353
if (!isset($afterEntities[$module][$entityName])) {
54-
$operation = new PageRemove($filenames, $operationTarget);
54+
$operation = new PageRemoved($filenames, $operationTarget);
5555
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
5656
continue;
5757
}
@@ -80,7 +80,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
8080
'name'
8181
);
8282
if ($matchingElement === null) {
83-
$operation = new PageSectionRemove($filenames, $operationTarget . '/' . $beforeFieldKey);
83+
$operation = new PageSectionRemoved($filenames, $operationTarget . '/' . $beforeFieldKey);
8484
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
8585
}
8686
}

src/Analyzer/Mftf/SectionAnalyzer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionAdded;
1111
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionElementAdded;
1212
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionElementChanged;
13-
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionElementRemove;
14-
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionRemove;
13+
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionElementRemoved;
14+
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionRemoved;
1515
use Magento\SemanticVersionChecker\Scanner\MftfScanner;
1616
use PHPSemVerChecker\Registry\Registry;
1717
use PHPSemVerChecker\Report\Report;
@@ -52,7 +52,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
5252

5353
// Validate section still exists
5454
if (!isset($afterEntities[$module][$entityName])) {
55-
$operation = new SectionRemove($filenames, $operationTarget);
55+
$operation = new SectionRemoved($filenames, $operationTarget);
5656
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
5757
continue;
5858
}
@@ -80,7 +80,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
8080
'name'
8181
);
8282
if ($matchingElement === null) {
83-
$operation = new SectionElementRemove(
83+
$operation = new SectionElementRemoved(
8484
$filenames,
8585
$operationTarget . '/' . $beforeFieldKey
8686
);
@@ -91,7 +91,7 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
9191
$matchingElement['attributes'],
9292
$this->getReport(),
9393
$filenames,
94-
SectionElementChanged::class,
94+
[AbstractEntityAnalyzer::DEFAULT_OPERATION_KEY => SectionElementChanged::class],
9595
"$operationTarget/$beforeFieldKey"
9696
);
9797
}

0 commit comments

Comments
 (0)