Skip to content

Commit 74c47b2

Browse files
committed
AC-661: Create phpcs static check for XmlTest
1 parent 2f4c72e commit 74c47b2

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

Magento2/Sniffs/Legacy/WidgetXMLSniff.php

+2-20
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ public function process(File $phpcsFile, $stackPtr)
3838
return;
3939
}
4040

41-
try {
42-
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
43-
} catch (\Exception $e) {
44-
$this->invalidXML($phpcsFile, $stackPtr);
45-
return;
46-
}
41+
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
42+
4743
if ($xml === false) {
4844
$this->invalidXML($phpcsFile, $stackPtr);
4945
return;
@@ -102,20 +98,6 @@ protected function invalidXML(File $phpcsFile, int $stackPtr): void
10298
);
10399
}
104100

105-
/**
106-
* Check if the element passed is in the currently sniffed line
107-
*
108-
* @param SimpleXMLElement $element
109-
* @param int $stackPtr
110-
* @return bool
111-
*/
112-
private function elementIsCurrentlySniffedLine(SimpleXMLElement $element, int $stackPtr): bool
113-
{
114-
$node = dom_import_simplexml($element);
115-
116-
return $node->getLineNo() === $stackPtr + 1;
117-
}
118-
119101
/**
120102
* Format the incoming XML to avoid tags split into several lines.
121103
*

Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml

+22
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,27 @@
77
-->
88
<widgets>
99
<widget
10+
type="/Deprecated"
11+
>
12+
<label
13+
translate="true"
14+
>Catalog New Products List
15+
16+
</label>
17+
18+
19+
<description translate="true">List of Products that are set as New</description>
20+
21+
<supported_blocks>
22+
23+
24+
Deprecated
25+
26+
27+
<block>
28+
<block_name>Deprecated</block_name>
29+
</block>
30+
</supported_blocks>
31+
</widget>
1032
</widgets>
1133

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
<widgets>
9+
<widget
10+
>
11+
<label
12+
translate="true"
13+
/>
14+
<description
15+
translate="true"
16+
>
17+
List of Products that are set as New
18+
</description>
19+
20+
</widget>
21+
</widgets>
22+

Magento2/Tests/Legacy/WidgetXMLUnitTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public function getErrorList($testFile = '')
2323
}
2424
if ($testFile === 'WidgetXMLUnitTest.2.xml') {
2525
return [
26-
1 => 1
26+
9 => 1,
27+
17 => 1,
28+
24 => 1,
2729
];
2830
}
2931
return [];

0 commit comments

Comments
 (0)