Skip to content

Commit bc42a8d

Browse files
committed
MC-38349: Create automated test for SVC changes
- Fixed issues within tests - Removed nonapi checks - Changed mftf example to patch change
1 parent a1d547f commit bc42a8d

File tree

18 files changed

+101
-192
lines changed

18 files changed

+101
-192
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"wikimedia/less.php": "~1.8.0",
1717
"zendframework/zend-stdlib": "^3.2.1",
1818
"nikic/php-parser": "~4.4.0||~4.5.0||~4.6.0",
19-
"sabre/xml": "^2.1",
19+
"sabre/xml": "^2.1"
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "^6.5.0",

tests/Unit/Console/Command/CompareSourceCommandTest/AbstractHtmlTestCaseForHtml.php

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
use DOMXPath;
1212
use Exception;
1313
use Magento\SemanticVersionChecker\Console\Command\CompareSourceCommand;
14+
use Magento\SemanticVersionChecker\ReportTypes;
1415
use PHPSemVerChecker\SemanticVersioning\Level;
1516
use PHPUnit\Framework\TestCase;
17+
use ReflectionClass;
1618
use Symfony\Component\Console\Tester\CommandTester;
1719

1820
/**
@@ -53,26 +55,28 @@ protected function tearDown()
5355
*
5456
* @param string $pathToSourceCodeBefore
5557
* @param string $pathToSourceCodeAfter
56-
* @param $allowedChangeLevel
58+
* @param int $allowedChangeLevel
5759
* @param HtmlParseInfoContainer[] $expectedHtmlEntries
5860
* @param array $expectedPackageSection
5961
* @param string $expectedOutput
6062
* @param $expectedStatusCode
63+
* @param $reportTypes
6164
* @param bool $shouldSkipTest
6265
* @throws Exception
6366
*/
6467
protected function doTestExecute(
65-
$pathToSourceCodeBefore,
66-
$pathToSourceCodeAfter,
67-
$allowedChangeLevel,
68-
$expectedHtmlEntries,
69-
$expectedPackageSection,
70-
$expectedOutput,
71-
$expectedStatusCode,
72-
$shouldSkipTest
68+
string $pathToSourceCodeBefore,
69+
string $pathToSourceCodeAfter,
70+
int $allowedChangeLevel,
71+
array $expectedHtmlEntries,
72+
array $expectedPackageSection,
73+
string $expectedOutput,
74+
int $expectedStatusCode,
75+
array $reportTypes,
76+
bool $shouldSkipTest
7377
): void {
7478
try {
75-
$commandTester = $this->executeCommand($pathToSourceCodeBefore, $pathToSourceCodeAfter, $allowedChangeLevel);
79+
$commandTester = $this->executeCommand($pathToSourceCodeBefore, $pathToSourceCodeAfter, $allowedChangeLevel, $reportTypes);
7680
$svcDom = $this->getSvcReportDOM();
7781
self::assertJsonContent($expectedPackageSection, $svcDom);
7882
foreach ($expectedHtmlEntries as $expectedHtmlEntry) {
@@ -89,6 +93,12 @@ protected function doTestExecute(
8993
}
9094
}
9195

96+
/**
97+
* Validate json in html svc document
98+
*
99+
* @param array $expectedJson
100+
* @param DOMDocument $docDom
101+
*/
92102
private static function assertJsonContent(array $expectedJson, DOMDocument $docDom) {
93103
if (!$expectedJson) {
94104
$xpathQuery = '/html/body/table/tbody/tr[last()]/td[2]';
@@ -102,14 +112,18 @@ private static function assertJsonContent(array $expectedJson, DOMDocument $docD
102112
$encodedJson = json_decode($jsonText);
103113
//store expectedJson in same format
104114
$expectedJson = json_decode(json_encode($expectedJson));
105-
self::assertEquals(sort($expectedJson), sort($encodedJson));
115+
sort($expectedJson);
116+
sort($encodedJson);
117+
self::assertEquals($expectedJson, $encodedJson);
106118
}
107119
}
108120

109121
/**
110122
* Assert HTML document resolves xpath, resolves finding pattern, or resolves finding pattern within resolved xpath
111-
* @param HtmlParseInfoContainer $container
112-
* @param DOMXPath $docXpath
123+
*
124+
* @param $xpathQuery
125+
* @param $regex
126+
* @param DOMDocument $docDom
113127
*/
114128
public static function assertHtml($xpathQuery, $regex, DOMDocument $docDom)
115129
{
@@ -142,12 +156,13 @@ public static function assertHtml($xpathQuery, $regex, DOMDocument $docDom)
142156
* <li><kbd>--include-patterns</kbd>: The path to the file <kbd>./_files/application_includes.txt</kbd></li>
143157
* </ul>
144158
*
145-
* @param $pathToSourceCodeBefore
146-
* @param $pathToSourceCodeAfter
147-
* @param $allowedChangeLevel
159+
* @param string $pathToSourceCodeBefore
160+
* @param string $pathToSourceCodeAfter
161+
* @param int $allowedChangeLevel
162+
* @param array $reportTypes
148163
* @return CommandTester
149164
*/
150-
protected function executeCommand($pathToSourceCodeBefore, $pathToSourceCodeAfter, $allowedChangeLevel): CommandTester
165+
protected function executeCommand(string $pathToSourceCodeBefore, string $pathToSourceCodeAfter, int $allowedChangeLevel, array $reportTypes): CommandTester
151166
{
152167
$commandTester = new CommandTester($this->command);
153168
$commandTester->execute(
@@ -156,6 +171,7 @@ protected function executeCommand($pathToSourceCodeBefore, $pathToSourceCodeAfte
156171
'source-after' => $pathToSourceCodeAfter,
157172
'--log-output-location' => $this->svcLogPath,
158173
'--include-patterns' => __DIR__ . '/_files/application_includes.txt',
174+
'--report-type' => $reportTypes,
159175
'allowed-change-level' => $allowedChangeLevel,
160176
]
161177
);

tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/mftf/actionGroup-remove-action-key-changed/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/non-api-class/composer.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/non-api-class/new-class/TestClass.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/non-api-class/new-class/TestInterface.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/non-api-interface/composer.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/non-api-interface/new-method/TestInterface.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/non-api-trait/composer.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/non-api-trait/removed-method/TestTrait.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)