Skip to content

Commit 1af0fa0

Browse files
committed
MC-38349: Create automated test for SVC changes
- test updating workflow
1 parent cd231b3 commit 1af0fa0

File tree

8 files changed

+44
-35
lines changed

8 files changed

+44
-35
lines changed

src/Analyzer/Xsd/Analyzer.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function analyze($registryBefore, $registryAfter)
112112
}
113113

114114
//process removed nodes
115-
if($removedNodes) {
115+
if ($removedNodes) {
116116
$filePath = $registryBefore->mapping[XmlRegistry::NODES_KEY][$moduleName][$fileName];
117117
$this->reportRemovedNodes($filePath, $removedNodes);
118118
}
@@ -267,8 +267,11 @@ private function reportRemovedNodes(string $filePath, array $nodes): void
267267
* @param array $relativeFilePaths
268268
* @param Registry $registryBefore
269269
*/
270-
private function reportRemovedSchemaDeclarations(string $module, array $relativeFilePaths, Registry $registryBefore): void
271-
{
270+
private function reportRemovedSchemaDeclarations(
271+
string $module,
272+
array $relativeFilePaths,
273+
Registry $registryBefore
274+
): void {
272275
foreach ($relativeFilePaths as $relativeFilePath) {
273276
$fullPath = $registryBefore->mapping[XmlRegistry::NODES_KEY][$module][$relativeFilePath];
274277
$this->report->add(self::CONTEXT, new SchemaDeclarationRemoved($fullPath, $relativeFilePath));

src/Helper/PackageNameResolver.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ public function __construct(InputInterface $input)
3737
* @param string $filepath
3838
* @return string|null
3939
*/
40-
private function getComposerPackageLocation(string $filepath):?string {
40+
private function getComposerPackageLocation(string $filepath): ?string
41+
{
4142
$sourceBeforeDir = realpath($this->input->getArgument('source-before'));
4243
$sourceAfterDir = realpath($this->input->getArgument('source-after'));
4344
$level = 1;
4445
$composerDirPath = dirname($filepath, $level);
45-
while ($composerDirPath !== $sourceBeforeDir
46+
while (
47+
$composerDirPath !== $sourceBeforeDir
4648
&& $composerDirPath !== $sourceAfterDir
47-
&& $composerDirPath !== '.') {
48-
49+
&& $composerDirPath !== '.'
50+
) {
4951
$composerPath = $composerDirPath . '/composer.json';
5052
if (is_file($composerPath)) {
5153
return $composerPath;
@@ -61,7 +63,8 @@ private function getComposerPackageLocation(string $filepath):?string {
6163
* @param string $filepath
6264
* @return string|null
6365
*/
64-
public function getPackageName(string $filepath):?string {
66+
public function getPackageName(string $filepath): ?string
67+
{
6568
$composerFilePath = $this->getComposerPackageLocation($filepath);
6669
if (!$composerFilePath) {
6770
return null;
@@ -70,5 +73,4 @@ public function getPackageName(string $filepath):?string {
7073
$composerJson = json_decode($composerFile);
7174
return $composerJson->name;
7275
}
73-
7476
}

src/Registry/XmlRegistry.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function addXmlNode(string $context, $data): void
3737
* @param LayoutNodeInterface $layoutNode
3838
* @param string $moduleName
3939
*/
40-
public function addLayoutContainerNode(LayoutNodeInterface $layoutNode, string $moduleName) {
40+
public function addLayoutContainerNode(LayoutNodeInterface $layoutNode, string $moduleName)
41+
{
4142
$this->data[self::NODES_KEY][$moduleName][$layoutNode->getUniqueKey()] = $layoutNode;
4243
$this->mapping[self::NODES_KEY][$moduleName][$layoutNode->getUniqueKey()] = $this->getCurrentFile();
4344
}
@@ -49,7 +50,8 @@ public function addLayoutContainerNode(LayoutNodeInterface $layoutNode, string $
4950
* @param string $uniqueKey
5051
* @return mixed
5152
*/
52-
public function getLayoutFile(string $moduleName, string $uniqueKey) {
53+
public function getLayoutFile(string $moduleName, string $uniqueKey)
54+
{
5355
return $this->mapping[self::NODES_KEY][$moduleName][$uniqueKey];
5456
}
5557

src/Reporter/HtmlPackageLevelChangesRenderer.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ public function outputPackageChanges()
8282
$pkgChangesJson = $this->getPackageChanges();
8383
$this->output->writeln('<tr class="text"><td class="test-name">Package Level Changes</td>');
8484
//Skip writing table if no severe changes are detected
85-
if (!$pkgChangesJson) {
86-
$this->output->writeln('<td>No BIC changes found to packages</td></tr>');
87-
return;
88-
}
85+
if (!$pkgChangesJson) {
86+
$this->output->writeln('<td>No BIC changes found to packages</td></tr>');
87+
return;
88+
}
8989
$this->output->writeln('<td><button class="btn-danger collapsible">Details</button><div class="content">');
9090
$this->output->writeln(
9191
'<table class="table table-striped"><tr><th class="column10">Level</th>' .
@@ -94,7 +94,7 @@ public function outputPackageChanges()
9494

9595
foreach ($pkgChangesJson as $pkg) {
9696
$this->output->writeln(
97-
'<tr class="text-danger"><td>'. $pkg['level'] . '</td><td>' . $pkg['name'] . '</td></tr>'
97+
'<tr class="text-danger"><td>' . $pkg['level'] . '</td><td>' . $pkg['name'] . '</td></tr>'
9898
);
9999
}
100100
$this->output->writeln('</table>');
@@ -109,8 +109,9 @@ public function outputPackageChanges()
109109
/**
110110
* Outputs JS to copy JSON to clipboard
111111
*/
112-
private function printClipboardJS() {
113-
$this->output->writeln( <<<COPY_PKG_JSON_SCRIPT
112+
private function printClipboardJS()
113+
{
114+
$this->output->writeln(<<<COPY_PKG_JSON_SCRIPT
114115
<input type="hidden" id="copyBuffer" value="">
115116
<button class="btn-info btn-tooltip" id="copy_pkg_json_btn">Copy</button>
116117
<script>
@@ -149,7 +150,7 @@ private function printClipboardJS() {
149150
*
150151
* @return array
151152
*/
152-
private function getPackageChanges():array
153+
private function getPackageChanges(): array
153154
{
154155
$results = [];
155156
foreach (self::$contexts as $context) {
@@ -179,7 +180,8 @@ private function getPackageChanges():array
179180
* @param int $level
180181
* @param array $results
181182
*/
182-
private function saveLevelOfChange(string $pkgName, int $level, array &$results) {
183+
private function saveLevelOfChange(string $pkgName, int $level, array &$results)
184+
{
183185
if (!isset($results[$pkgName]) || $level > $results[$pkgName]) {
184186
$results[$pkgName] = $level;
185187
}
@@ -191,7 +193,8 @@ private function saveLevelOfChange(string $pkgName, int $level, array &$results)
191193
* @param array $pkgChanges
192194
* @return array
193195
*/
194-
private function transformOutputArray(array $pkgChanges) {
196+
private function transformOutputArray(array $pkgChanges)
197+
{
195198
$results = [];
196199
$minimumChangeLevel = $this->input->getArgument('allowed-change-level');
197200
foreach ($pkgChanges as $pkgName => $level) {
@@ -204,4 +207,4 @@ private function transformOutputArray(array $pkgChanges) {
204207
}
205208
return $results;
206209
}
207-
}
210+
}

src/Scanner/XsdScanner.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,4 @@ private function getRelativePath(string $file, string $module): string
155155

156156
return substr($file, $moduleSubPathPosition + strlen($moduleSubPath));
157157
}
158-
159-
private function getModulePath(string $file, string $module) {
160-
$relativePath = $this->getRelativePath($file, $module);
161-
return substr($file, 0, strlen($file) - strlen($relativePath));
162-
}
163158
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\SemanticVersionChecker\Test\Unit\Console\Command\CompareSourceCommandTest;
99

10-
use \DOMDocument;
10+
use DOMDocument;
1111
use DOMXPath;
1212
use Exception;
1313
use Magento\SemanticVersionChecker\Console\Command\CompareSourceCommand;
@@ -99,7 +99,8 @@ protected function doTestExecute(
9999
* @param array $expectedJson
100100
* @param DOMDocument $docDom
101101
*/
102-
private static function assertJsonContent(array $expectedJson, DOMDocument $docDom) {
102+
private static function assertJsonContent(array $expectedJson, DOMDocument $docDom)
103+
{
103104
if (!$expectedJson) {
104105
$xpathQuery = '/html/body/table/tbody/tr[last()]/td[2]';
105106
$pattern = '#No BIC changes found to packages#i';
@@ -183,7 +184,7 @@ protected function executeCommand(string $pathToSourceCodeBefore, string $pathTo
183184
*
184185
* @return DOMDocument
185186
*/
186-
private function getSvcReportDOM() : ?DOMDocument
187+
private function getSvcReportDOM(): ?DOMDocument
187188
{
188189
$source = file_get_contents($this->svcLogPath);
189190
if (!$source) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
2+
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
56
*/
7+
68
declare(strict_types=1);
9+
710
namespace Magento\SemanticVersionChecker\Test\Unit\Console\Command\CompareSourceCommandTest;
811

912
/**
@@ -28,11 +31,10 @@ class HtmlParseInfoContainer
2831
*/
2932
public function __construct(?string $pattern, ?string $xpath = null)
3033
{
31-
if( !($pattern || $xpath) ) {
34+
if (!($pattern || $xpath)) {
3235
throw new \InvalidArgumentException('$pattern and $xpath can not both be empty');
3336
}
3437
$this->xpath = $xpath;
3538
$this->pattern = $pattern;
3639
}
37-
38-
}
40+
}

tests/Unit/Console/Command/HtmlTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ public function changesDataProvider()
156156
*
157157
* @return array
158158
*/
159-
private static function getAllReportTypes():array {
160-
if(!self::$reportTypesList) {
159+
private static function getAllReportTypes(): array
160+
{
161+
if (!self::$reportTypesList) {
161162
self::$reportTypesList = (new ReflectionClass(ReportTypes::class))->getConstants();
162163
}
163164
return self::$reportTypesList;

0 commit comments

Comments
 (0)