Skip to content

Commit ac4e8c0

Browse files
authored
Merge pull request #2 from magento-pangolin/MQE-2245
MQE-2245: Implement additional <test> entity use cases in SVC tool
2 parents 8959d04 + 178b3c6 commit ac4e8c0

File tree

11 files changed

+303
-30
lines changed

11 files changed

+303
-30
lines changed

src/Analyzer/Mftf/AbstractEntityAnalyzer.php

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,36 @@ public function matchAndValidateElementType(
135135
}
136136
}
137137

138+
139+
/**
140+
* Matches and validates actions sequence in a test block
141+
*
142+
* @param array $beforeTestActions
143+
* @param array $afterTestActions
144+
* @param Report $report
145+
* @param string $filenames
146+
* @param string $operationClass
147+
* @param string $fullOperationTarget
148+
* @return void
149+
*/
150+
public function matchAndValidateActionsSequence(
151+
$beforeTestActions,
152+
$afterTestActions,
153+
$report,
154+
$filenames,
155+
$operationClass,
156+
$fullOperationTarget
157+
) {
158+
if ($beforeTestActions != $afterTestActions) {
159+
sort($beforeTestActions);
160+
sort($afterTestActions);
161+
if ($beforeTestActions == $afterTestActions) {
162+
$operation = new $operationClass($filenames, $fullOperationTarget);
163+
$report->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
164+
}
165+
}
166+
}
167+
138168
/**
139169
* Finds all added child elements in afterArray, compared to beforeArray
140170
*
@@ -155,19 +185,20 @@ public function findAddedElementsInArray(
155185
$operationClass,
156186
$fullOperationTarget
157187
) {
158-
foreach ($afterArray as $newChild) {
159-
if (!isset($newChild['attributes'][$elementIdentifier])) {
160-
continue;
161-
}
162-
$beforeFieldKey = $newChild['attributes'][$elementIdentifier];
163-
$matchingElement = $this->findMatchingElement($newChild, $beforeArray, $elementIdentifier);
164-
if ($matchingElement === null) {
165-
$operation = new $operationClass($filenames, $fullOperationTarget . '/' . $beforeFieldKey);
166-
$report->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
188+
if (is_array($afterArray) || is_object($afterArray)) {
189+
foreach ($afterArray as $newChild) {
190+
if (!isset($newChild['attributes'][$elementIdentifier])) {
191+
continue;
192+
}
193+
$beforeFieldKey = $newChild['attributes'][$elementIdentifier];
194+
$matchingElement = $this->findMatchingElement($newChild, $beforeArray, $elementIdentifier);
195+
if ($matchingElement === null) {
196+
$operation = new $operationClass($filenames, $fullOperationTarget . '/' . $beforeFieldKey);
197+
$report->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
198+
}
199+
}
167200
}
168-
}
169201
}
170-
171202
/**
172203
* Finds all added child elements in afterArray, compared to beforeArray, using both key and value for matching
173204
*

src/Analyzer/Mftf/ActionGroupAnalyzer.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,26 @@ public function analyze(Registry $registryBefore, Registry $registryAfter)
155155
}
156156

157157
// Validate <arguments>
158-
foreach ($beforeArguments as $argument) {
159-
$beforeFieldKey = $argument['attributes']['name'];
160-
$matchingElement = $this->findMatchingElement($argument, $afterArguments,'name');
161-
if ($matchingElement === null) {
162-
$operation = new ActionGroupArgumentRemoved(
163-
$filenames,
164-
$operationTarget . '/Arguments/' . $beforeFieldKey
165-
);
166-
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
167-
} else {
168-
$this->matchAndValidateAttributes(
169-
$argument['attributes'],
170-
$matchingElement['attributes'],
171-
$this->getReport(),
172-
$filenames,
173-
[AbstractEntityAnalyzer::DEFAULT_OPERATION_KEY => ActionGroupArgumentChanged::class],
174-
"$operationTarget/$beforeFieldKey"
175-
);
176-
158+
if (is_array($beforeArguments) || is_object($beforeArguments)) {
159+
foreach ($beforeArguments as $argument) {
160+
$beforeFieldKey = $argument['attributes']['name'];
161+
$matchingElement = $this->findMatchingElement($argument, $afterArguments, 'name');
162+
if ($matchingElement === null) {
163+
$operation = new ActionGroupArgumentRemoved(
164+
$filenames,
165+
$operationTarget . '/Arguments/' . $beforeFieldKey
166+
);
167+
$this->getReport()->add(MftfReport::MFTF_REPORT_CONTEXT, $operation);
168+
} else {
169+
$this->matchAndValidateAttributes(
170+
$argument['attributes'],
171+
$matchingElement['attributes'],
172+
$this->getReport(),
173+
$filenames,
174+
[AbstractEntityAnalyzer::DEFAULT_OPERATION_KEY => ActionGroupArgumentChanged::class],
175+
"$operationTarget/$beforeFieldKey"
176+
);
177+
}
177178
}
178179
}
179180

src/Analyzer/Mftf/TestAnalyzer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\SemanticVersionChecker\Operation\Mftf\Test\TestActionChanged;
1313
use Magento\SemanticVersionChecker\Operation\Mftf\Test\TestActionGroupRefChanged;
1414
use Magento\SemanticVersionChecker\Operation\Mftf\Test\TestActionRemoved;
15+
use Magento\SemanticVersionChecker\Operation\Mftf\Test\TestActionSequenceChanged;
1516
use Magento\SemanticVersionChecker\Operation\Mftf\Test\TestActionTypeChanged;
1617
use Magento\SemanticVersionChecker\Operation\Mftf\Test\TestAdded;
1718
use Magento\SemanticVersionChecker\Operation\Mftf\Test\TestAnnotationAdded;
@@ -191,6 +192,15 @@ public function validateActionsInBlock(
191192
$filenames,
192193
$operationTarget
193194
) {
195+
$this->matchAndValidateActionsSequence(
196+
$beforeTestActions,
197+
$afterTestActions,
198+
$report,
199+
$filenames,
200+
TestActionSequenceChanged::class,
201+
$operationTarget
202+
);
203+
194204
foreach ($beforeTestActions as $testAction) {
195205
if (isset($testAction['attributes']['stepKey'])) {
196206
$elementIdentifier = 'stepKey';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Operation\Mftf\Test;
4+
5+
use Magento\SemanticVersionChecker\Operation\Mftf\MftfOperation;
6+
use PHPSemVerChecker\SemanticVersioning\Level;
7+
8+
/**
9+
* Test action sequence was changed
10+
*/
11+
class TestActionSequenceChanged extends MftfOperation
12+
{
13+
/**
14+
* Error codes.
15+
*
16+
* @var array
17+
*/
18+
protected $code = 'M223';
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 = '<test> <action> sequence was changed';
32+
}

tests/Unit/Console/Command/CompareSourceCommandMftfTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,15 @@ public function changesDataProvider()
406406
],
407407
'Patch change is detected.'
408408
],
409+
'test-action-sequence-changed' => [
410+
$pathToFixtures . '/test-action-sequence-changed/source-code-before',
411+
$pathToFixtures . '/test-action-sequence-changed/source-code-after',
412+
[
413+
'Mftf (MAJOR)',
414+
'Test/SampleTest | <test> <action> sequence was changed | M223'
415+
],
416+
'Major change is detected.'
417+
],
409418
'test-action-type-changed' => [
410419
$pathToFixtures . '/test-action-type-changed/source-code-before',
411420
$pathToFixtures . '/test-action-type-changed/source-code-after',
@@ -451,6 +460,15 @@ public function changesDataProvider()
451460
],
452461
'Minor change is detected.'
453462
],
463+
'test-before-action-sequence-changed' => [
464+
$pathToFixtures . '/test-before-action-sequence-changed/source-code-before',
465+
$pathToFixtures . '/test-before-action-sequence-changed/source-code-after',
466+
[
467+
'Mftf (MAJOR)',
468+
'Test/SampleTest/before | <test> <action> sequence was changed | M223'
469+
],
470+
'Major change is detected.'
471+
],
454472
'test-after-action-removed' => [
455473
$pathToFixtures . '/test-after-action-removed/source-code-before',
456474
$pathToFixtures . '/test-after-action-removed/source-code-after',
@@ -469,6 +487,15 @@ public function changesDataProvider()
469487
],
470488
'Minor change is detected.'
471489
],
490+
'test-after-action-sequence-changed' => [
491+
$pathToFixtures . '/test-after-action-sequence-changed/source-code-before',
492+
$pathToFixtures . '/test-after-action-sequence-changed/source-code-after',
493+
[
494+
'Mftf (MAJOR)',
495+
'Test/SampleTest/after | <test> <action> sequence was changed | M223'
496+
],
497+
'Major change is detected.'
498+
],
472499
'test-annotation-changed' => [
473500
$pathToFixtures . '/test-annotation-changed/source-code-before',
474501
$pathToFixtures . '/test-annotation-changed/source-code-after',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<test name="SampleTest">
10+
<annotations>
11+
<features value="Tools"/>
12+
<stories value="Story Value"/>
13+
<title value="Story Title"/>
14+
<description value="Story Description"/>
15+
<severity value="CRITICAL"/>
16+
<group value="sampleGroup"/>
17+
</annotations>
18+
<before>
19+
<comment userInput="beforecomment1" stepKey="key1"/>
20+
</before>
21+
<after>
22+
<comment userInput="aftercomment1" stepKey="key1"/>
23+
</after>
24+
<comment userInput="comment2" stepKey="key2"/>
25+
<comment userInput="newComment" stepKey="key1"/>
26+
</test>
27+
</tests>
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<test name="SampleTest">
10+
<annotations>
11+
<features value="Tools"/>
12+
<stories value="Story Value"/>
13+
<title value="Story Title"/>
14+
<description value="Story Description"/>
15+
<severity value="CRITICAL"/>
16+
<group value="sampleGroup"/>
17+
</annotations>
18+
<before>
19+
<comment userInput="beforecomment1" stepKey="key1"/>
20+
</before>
21+
<after>
22+
<comment userInput="aftercomment1" stepKey="key1"/>
23+
</after>
24+
<comment userInput="newComment" stepKey="key1"/>
25+
<comment userInput="comment2" stepKey="key2"/>
26+
</test>
27+
</tests>
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<test name="SampleTest">
10+
<annotations>
11+
<features value="Tools"/>
12+
<stories value="Story Value"/>
13+
<title value="Story Title"/>
14+
<description value="Story Description"/>
15+
<severity value="CRITICAL"/>
16+
<group value="sampleGroup"/>
17+
</annotations>
18+
<before>
19+
<comment userInput="beforecomment1" stepKey="key1"/>
20+
</before>
21+
<after>
22+
<comment userInput="aftercomment2" stepKey="key2"/>
23+
<comment userInput="aftercomment1" stepKey="key1"/>
24+
</after>
25+
<comment userInput="newComment" stepKey="key1"/>
26+
<comment userInput="comment2" stepKey="key2"/>
27+
</test>
28+
</tests>
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<test name="SampleTest">
10+
<annotations>
11+
<features value="Tools"/>
12+
<stories value="Story Value"/>
13+
<title value="Story Title"/>
14+
<description value="Story Description"/>
15+
<severity value="CRITICAL"/>
16+
<group value="sampleGroup"/>
17+
</annotations>
18+
<before>
19+
<comment userInput="beforecomment1" stepKey="key1"/>
20+
</before>
21+
<after>
22+
<comment userInput="aftercomment1" stepKey="key1"/>
23+
<comment userInput="aftercomment2" stepKey="key2"/>
24+
</after>
25+
<comment userInput="newComment" stepKey="key1"/>
26+
<comment userInput="comment2" stepKey="key2"/>
27+
</test>
28+
</tests>
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<test name="SampleTest">
10+
<annotations>
11+
<features value="Tools"/>
12+
<stories value="Story Value"/>
13+
<title value="Story Title"/>
14+
<description value="Story Description"/>
15+
<severity value="CRITICAL"/>
16+
<group value="sampleGroup"/>
17+
</annotations>
18+
<before>
19+
<comment userInput="beforecomment2" stepKey="key2"/>
20+
<comment userInput="beforecomment1" stepKey="key1"/>
21+
</before>
22+
<after>
23+
<comment userInput="aftercomment1" stepKey="key1"/>
24+
</after>
25+
<comment userInput="newComment" stepKey="key1"/>
26+
<comment userInput="comment2" stepKey="key2"/>
27+
</test>
28+
</tests>
29+

0 commit comments

Comments
 (0)