Skip to content

Commit 97e862f

Browse files
authored
Merge pull request #3 from magento-pangolin/MQE-2247
MQE-2247: Implement additional <section> and <operation> entity use cases in SVC tool
2 parents ac4e8c0 + 6a121d6 commit 97e862f

File tree

31 files changed

+733
-13
lines changed

31 files changed

+733
-13
lines changed

src/Analyzer/Mftf/AbstractEntityAnalyzer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ public function findAddedElementsInArray(
190190
if (!isset($newChild['attributes'][$elementIdentifier])) {
191191
continue;
192192
}
193-
$beforeFieldKey = $newChild['attributes'][$elementIdentifier];
193+
$afterFieldKey = $newChild['attributes'][$elementIdentifier];
194194
$matchingElement = $this->findMatchingElement($newChild, $beforeArray, $elementIdentifier);
195195
if ($matchingElement === null) {
196-
$operation = new $operationClass($filenames, $fullOperationTarget . '/' . $beforeFieldKey);
196+
$operation = new $operationClass($filenames, $fullOperationTarget . '/' . $afterFieldKey);
197197
$report->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
198198
}
199199
}
@@ -252,11 +252,11 @@ public function findAddedEntitiesInModule(
252252
if (!isset($newChild['type']) || $newChild['type'] !== $entityType) {
253253
continue;
254254
}
255-
$beforeFieldKey = $newChild['attributes']['name'];
255+
$afterFieldKey = $newChild['attributes']['name'];
256256
$matchingElement = $this->findMatchingElement($newChild, $beforeArray, 'name');
257257
if ($matchingElement === null) {
258258
$filenames = implode(', ', $newChild['filePaths']);
259-
$operation = new $operationClass($filenames, $fullOperationTarget . '/' . $beforeFieldKey);
259+
$operation = new $operationClass($filenames, $fullOperationTarget . '/' . $afterFieldKey);
260260
$report->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
261261
}
262262
}

src/Analyzer/Mftf/MetadataAnalyzer.php

+29-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\SemanticVersionChecker\MftfReport;
1010
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataAdded;
11+
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataChanged;
12+
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataChildAdded;
1113
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataChildRemoved;
1214
use Magento\SemanticVersionChecker\Operation\Mftf\Metadata\MetadataRemoved;
1315
use Magento\SemanticVersionChecker\Scanner\MftfScanner;
@@ -54,10 +56,31 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
5456
continue;
5557
}
5658

57-
// Build simple metadata tree for comparison
59+
// Validate metadata attribute changes
60+
$this->matchAndValidateAttributes(
61+
$beforeEntity['attributes'],
62+
$afterEntities[$module][$entityName]['attributes'],
63+
$this->getReport(),
64+
$filenames,
65+
[AbstractEntityAnalyzer::DEFAULT_OPERATION_KEY => MetadataChanged::class],
66+
$operationTarget
67+
);
68+
69+
// Validate child elements removed
5870
$this->recursiveCompare(
5971
$beforeEntity,
6072
$afterEntities[$module][$entityName],
73+
MetadataChildRemoved::class,
74+
$operationTarget,
75+
$filenames,
76+
$this->getReport()
77+
);
78+
79+
// Validate child elements added
80+
$this->recursiveCompare(
81+
$afterEntities[$module][$entityName],
82+
$beforeEntity,
83+
MetadataChildAdded::class,
6184
$operationTarget,
6285
$filenames,
6386
$this->getReport()
@@ -72,22 +95,23 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
7295
*
7396
* @param array $beforeEntity
7497
* @param array $afterEntity
98+
* @param string $operationClass
7599
* @param string $operationTarget
76100
* @param string $filenames
77101
* @param Report $report
78102
* @return void
79103
*/
80-
public function recursiveCompare($beforeEntity, $afterEntity, $operationTarget, $filenames, $report)
104+
public function recursiveCompare($beforeEntity, $afterEntity, $operationClass, $operationTarget, $filenames, $report)
81105
{
82106
$beforeChildren = $beforeEntity['value'] ?? [];
107+
$afterChildren = $afterEntity['value'] ?? [];
83108
if (!is_array($beforeChildren)) {
84109
return;
85110
}
86111
foreach ($beforeChildren as $beforeChild) {
87112
$beforeType = $beforeChild['name'];
88113
$beforeFieldKey = $beforeChild['attributes']['key'] ?? null;
89114
$afterFound = null;
90-
$afterChildren = $afterEntity['value'] ?? [];
91115
foreach ($afterChildren as $afterChild) {
92116
if ($afterChild['name'] !== $beforeType) {
93117
continue;
@@ -99,12 +123,13 @@ public function recursiveCompare($beforeEntity, $afterEntity, $operationTarget,
99123
}
100124
}
101125
if ($afterFound === null) {
102-
$operation = new MetadataChildRemoved($filenames, $operationTarget . '/' . $beforeFieldKey);
126+
$operation = new $operationClass($filenames, $operationTarget . '/' . $beforeFieldKey);
103127
$report->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
104128
} else {
105129
$this->recursiveCompare(
106130
$beforeChild,
107131
$afterFound,
132+
$operationClass,
108133
$operationTarget . '/' . $beforeFieldKey,
109134
$filenames,
110135
$report

src/Analyzer/Mftf/SectionAnalyzer.php

+31-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
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\SectionElementParameterizedChanged;
1314
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionElementRemoved;
15+
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionElementSelectorChanged;
16+
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionElementTypeChanged;
1417
use Magento\SemanticVersionChecker\Operation\Mftf\Section\SectionRemoved;
1518
use Magento\SemanticVersionChecker\Scanner\MftfScanner;
1619
use PHPSemVerChecker\Registry\Registry;
@@ -21,6 +24,19 @@ class SectionAnalyzer extends AbstractEntityAnalyzer
2124
const MFTF_ELEMENT_ELEMENT = "{}element";
2225
const MFTF_DATA_TYPE = 'section';
2326
const MFTF_DATA_DIRECTORY = '/Mftf/Section/';
27+
const MFTF_ELEMENT_PARAM = 'parameterized';
28+
29+
/**
30+
* operations array
31+
*
32+
* @var string[]
33+
*/
34+
private static $operations = [
35+
AbstractEntityAnalyzer::DEFAULT_OPERATION_KEY => SectionElementChanged::class,
36+
'selector' => SectionElementSelectorChanged::class,
37+
'type' => SectionElementTypeChanged::class,
38+
self::MFTF_ELEMENT_PARAM => SectionElementParameterizedChanged::class
39+
];
2440

2541
/**
2642
* MFTF section.xml analyzer
@@ -91,9 +107,23 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
91107
$matchingElement['attributes'],
92108
$this->getReport(),
93109
$filenames,
94-
[AbstractEntityAnalyzer::DEFAULT_OPERATION_KEY => SectionElementChanged::class],
110+
self::$operations,
95111
"$operationTarget/$beforeFieldKey"
96112
);
113+
114+
// validate parameterized added
115+
$beforeAttributes = $beforeField['attributes'];
116+
$afterAttributes = $matchingElement['attributes'];
117+
118+
if (isset($afterAttributes[self::MFTF_ELEMENT_PARAM])) {
119+
if (!isset($beforeAttributes[self::MFTF_ELEMENT_PARAM])) {
120+
$operation = new SectionElementParameterizedChanged(
121+
$filenames,
122+
"$operationTarget/$beforeFieldKey/". self::MFTF_ELEMENT_PARAM
123+
);
124+
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
125+
}
126+
}
97127
}
98128
}
99129
$this->findAddedElementsInArray(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Operation\Mftf\Metadata;
4+
5+
use Magento\SemanticVersionChecker\Operation\Mftf\MftfOperation;
6+
use PHPSemVerChecker\SemanticVersioning\Level;
7+
8+
/**
9+
* Metadata Entity was modified
10+
*/
11+
class MetadataChanged extends MftfOperation
12+
{
13+
/**
14+
* Error codes.
15+
*
16+
* @var array
17+
*/
18+
protected $code = 'M241';
19+
20+
/**
21+
* Operation Severity
22+
* @var int
23+
*/
24+
protected $level = Level::MINOR;
25+
26+
/**
27+
* Operation message.
28+
*
29+
* @var string
30+
*/
31+
protected $reason = '<operation> was changed';
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Operation\Mftf\Metadata;
4+
5+
use Magento\SemanticVersionChecker\Operation\Mftf\MftfOperation;
6+
use PHPSemVerChecker\SemanticVersioning\Level;
7+
8+
/**
9+
* Metadata Child was added in the Module
10+
*/
11+
class MetadataChildAdded extends MftfOperation
12+
{
13+
/**
14+
* Error codes.
15+
*
16+
* @var array
17+
*/
18+
protected $code = 'M242';
19+
20+
/**
21+
* Operation Severity
22+
* @var int
23+
*/
24+
protected $level = Level::MINOR;
25+
26+
/**
27+
* Operation message.
28+
*
29+
* @var string
30+
*/
31+
protected $reason = '<operation> child element was added';
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Operation\Mftf\Section;
4+
5+
use Magento\SemanticVersionChecker\Operation\Mftf\MftfOperation;
6+
use PHPSemVerChecker\SemanticVersioning\Level;
7+
8+
/**
9+
* Section <element> parameterized attribute was modified
10+
*/
11+
class SectionElementParameterizedChanged extends MftfOperation
12+
{
13+
/**
14+
* Error codes.
15+
*
16+
* @var array
17+
*/
18+
protected $code = 'M250';
19+
20+
/**
21+
* Operation Severity
22+
* @var int
23+
*/
24+
protected $level = Level::MAJOR;
25+
26+
/**
27+
* Operation message.
28+
*
29+
* @var string
30+
*/
31+
protected $reason = '<section> <element> parameterized was changed';
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Operation\Mftf\Section;
4+
5+
use Magento\SemanticVersionChecker\Operation\Mftf\MftfOperation;
6+
use PHPSemVerChecker\SemanticVersioning\Level;
7+
8+
/**
9+
* Section <element> selector was modified
10+
*/
11+
class SectionElementSelectorChanged extends MftfOperation
12+
{
13+
/**
14+
* Error codes.
15+
*
16+
* @var array
17+
*/
18+
protected $code = 'M219';
19+
20+
/**
21+
* Operation Severity
22+
* @var int
23+
*/
24+
protected $level = Level::PATCH;
25+
26+
/**
27+
* Operation message.
28+
*
29+
* @var string
30+
*/
31+
protected $reason = '<section> <element> selector was changed';
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Operation\Mftf\Section;
4+
5+
use Magento\SemanticVersionChecker\Operation\Mftf\MftfOperation;
6+
use PHPSemVerChecker\SemanticVersioning\Level;
7+
8+
/**
9+
* Section <element> type was modified
10+
*/
11+
class SectionElementTypeChanged extends MftfOperation
12+
{
13+
/**
14+
* Error codes.
15+
*
16+
* @var array
17+
*/
18+
protected $code = 'M218';
19+
20+
/**
21+
* Operation Severity
22+
* @var int
23+
*/
24+
protected $level = Level::PATCH;
25+
26+
/**
27+
* Operation message.
28+
*
29+
* @var string
30+
*/
31+
protected $reason = '<section> <element> type was changed';
32+
}

0 commit comments

Comments
 (0)