diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index c65dab6b..24024d9d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ master ] + branches: [ master, develop ] pull_request: - branches: [ master ] + branches: [ master, develop ] jobs: build: diff --git a/composer.json b/composer.json index 7bf33f9d..ccecfeac 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "magento/magento-semver", "description": "Magento Semantic Version Checker", - "version": "9.0.0", + "version": "10.0.0", "license": [ "OSL-3.0", "AFL-3.0" @@ -20,6 +20,7 @@ }, "require-dev": { "phpunit/phpunit": "^6.5.0", + "ext-dom": "*", "squizlabs/php_codesniffer": "^3.5" }, "autoload": { diff --git a/composer.lock b/composer.lock index 606b656e..db759c0c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "83b926ad9471c996f7224a1ffef6d148", + "content-hash": "f1653344271daf4dc2411465b9cc6744", "packages": [ { "name": "hassankhan/config", @@ -2655,6 +2655,8 @@ "php": "~7.2.29||~7.3.0||~7.4.0", "ext-json": "*" }, - "platform-dev": [], + "platform-dev": { + "ext-dom": "*" + }, "plugin-api-version": "1.1.0" } diff --git a/src/Analyzer/DBSchema/DbSchemaColumnAnalyzer.php b/src/Analyzer/DBSchema/DbSchemaColumnAnalyzer.php index 613d894b..d0b8af95 100644 --- a/src/Analyzer/DBSchema/DbSchemaColumnAnalyzer.php +++ b/src/Analyzer/DBSchema/DbSchemaColumnAnalyzer.php @@ -58,19 +58,21 @@ public function analyze($registryBefore, $registryAfter) foreach ($registryTablesBefore as $moduleName => $moduleTables) { foreach ($moduleTables as $tableName => $tableData) { + $fileBefore = $registryBefore->mapping['table'][$moduleName]; $columns = $tableData['column'] ?? []; foreach ($columns as $column) { if ( isset($registryTablesAfter[$moduleName][$tableName]) && !isset($registryTablesAfter[$moduleName][$tableName]['column'][$column]) ) { - $operation = new ColumnRemove($moduleName, $tableName . '/' . $column); + $operation = new ColumnRemove($fileBefore, $tableName . '/' . $column); $this->getReport()->add($this->context, $operation); } } } } foreach ($registryTablesAfter as $moduleName => $moduleTables) { + $fileAfter = $registryAfter->mapping['table'][$moduleName]; foreach ($moduleTables as $tableName => $tableData) { $columns = $tableData['column'] ?? []; foreach ($columns as $column) { @@ -78,7 +80,7 @@ public function analyze($registryBefore, $registryAfter) isset($registryTablesBefore[$moduleName][$tableName]) && !isset($registryTablesBefore[$moduleName][$tableName]['column'][$column]) ) { - $operation = new ColumnAdd($moduleName, $tableName . '/' . $column); + $operation = new ColumnAdd($fileAfter, $tableName . '/' . $column); $this->getReport()->add($this->context, $operation); } } diff --git a/src/Analyzer/DBSchema/DbSchemaForeignKeyAnalyzer.php b/src/Analyzer/DBSchema/DbSchemaForeignKeyAnalyzer.php index ad37915d..7a362aef 100644 --- a/src/Analyzer/DBSchema/DbSchemaForeignKeyAnalyzer.php +++ b/src/Analyzer/DBSchema/DbSchemaForeignKeyAnalyzer.php @@ -56,6 +56,7 @@ public function analyze($registryBefore, $registryAfter) $registryTablesAfter = $registryAfter->data['table'] ?? []; foreach ($registryTablesBefore as $moduleName => $moduleTables) { + $fileBefore = $registryBefore->mapping['table'][$moduleName]; foreach ($moduleTables as $tableName => $tableData) { $keys = $tableData['foreign'] ?? []; foreach ($keys as $name => $key) { @@ -63,13 +64,13 @@ public function analyze($registryBefore, $registryAfter) continue; } if ($key !== null && !isset($registryTablesAfter[$moduleName][$tableName]['foreign'][$name])) { - $operation = new ForeignKeyDrop($moduleName, $tableName . '/' . $name); + $operation = new ForeignKeyDrop($fileBefore, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); continue; } foreach ($key as $item => $value) { if ($value !== $registryTablesAfter[$moduleName][$tableName]['foreign'][$name][$item]) { - $operation = new ForeignKeyChange($moduleName, $tableName . '/' . $name . '/' . $item); + $operation = new ForeignKeyChange($fileBefore, $tableName . '/' . $name . '/' . $item); $this->getReport()->add($this->context, $operation); } } @@ -78,6 +79,7 @@ public function analyze($registryBefore, $registryAfter) } foreach ($registryTablesAfter as $moduleName => $moduleTables) { + $fileAfter = $registryAfter->mapping['table'][$moduleName]; foreach ($moduleTables as $tableName => $tableData) { $keys = $tableData['foreign'] ?? []; foreach ($keys as $name => $key) { @@ -85,7 +87,7 @@ public function analyze($registryBefore, $registryAfter) continue; } if ($key !== null && !isset($registryTablesBefore[$moduleName][$tableName]['foreign'][$name])) { - $operation = new ForeignKeyAdd($moduleName, $tableName . '/' . $name); + $operation = new ForeignKeyAdd($fileAfter, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); } } diff --git a/src/Analyzer/DBSchema/DbSchemaPrimaryKeyAnalyzer.php b/src/Analyzer/DBSchema/DbSchemaPrimaryKeyAnalyzer.php index 42812ffe..83ffb85b 100644 --- a/src/Analyzer/DBSchema/DbSchemaPrimaryKeyAnalyzer.php +++ b/src/Analyzer/DBSchema/DbSchemaPrimaryKeyAnalyzer.php @@ -55,6 +55,7 @@ public function analyze($registryBefore, $registryAfter) $registryTablesAfter = $registryAfter->data['table'] ?? []; foreach ($registryTablesBefore as $moduleName => $moduleTables) { + $fileBefore = $registryBefore->mapping['table'][$moduleName]; foreach ($moduleTables as $tableName => $tableData) { $keys = $tableData['primary'] ?? []; foreach ($keys as $name => $key) { @@ -62,7 +63,7 @@ public function analyze($registryBefore, $registryAfter) continue; } if ($key !== null && !isset($registryTablesAfter[$moduleName][$tableName]['primary'][$name])) { - $operation = new PrimaryKeyDrop($moduleName, $tableName . '/' . $name); + $operation = new PrimaryKeyDrop($fileBefore, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); continue; } @@ -76,7 +77,7 @@ public function analyze($registryBefore, $registryAfter) } } if (!$matchedColumnFlag) { - $operation = new PrimaryKeyChange($moduleName, $tableName . '/' . $name); + $operation = new PrimaryKeyChange($fileBefore, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); break; } @@ -86,6 +87,7 @@ public function analyze($registryBefore, $registryAfter) } foreach ($registryTablesAfter as $moduleName => $moduleTables) { + $fileAfter = $registryAfter->mapping['table'][$moduleName]; foreach ($moduleTables as $tableName => $tableData) { $keys = $tableData['primary'] ?? []; foreach ($keys as $name => $key) { @@ -93,7 +95,7 @@ public function analyze($registryBefore, $registryAfter) continue; } if ($key !== null && !isset($registryTablesBefore[$moduleName][$tableName]['primary'][$name])) { - $operation = new PrimaryKeyAdd($moduleName, $tableName . '/' . $name); + $operation = new PrimaryKeyAdd($fileAfter, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); continue; } @@ -108,7 +110,7 @@ public function analyze($registryBefore, $registryAfter) } } if (!$matchedColumnFlag) { - $operation = new PrimaryKeyChange($moduleName, $tableName . '/' . $name); + $operation = new PrimaryKeyChange($fileAfter, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); break; } diff --git a/src/Analyzer/DBSchema/DbSchemaTableAnalyzer.php b/src/Analyzer/DBSchema/DbSchemaTableAnalyzer.php index 662abec2..aa16d4ad 100644 --- a/src/Analyzer/DBSchema/DbSchemaTableAnalyzer.php +++ b/src/Analyzer/DBSchema/DbSchemaTableAnalyzer.php @@ -55,15 +55,16 @@ public function analyze($registryBefore, $registryAfter) $registryTablesAfter = $registryAfter->data['table'] ?? []; foreach ($registryTablesBefore as $moduleName => $moduleTables) { + $fileBefore = $registryBefore->mapping['table'][$moduleName]; foreach ($moduleTables as $tableName => $tableData) { if (!isset($registryTablesAfter[$moduleName][$tableName])) { - $operation = new TableDropped($moduleName, $tableName); + $operation = new TableDropped($fileBefore, $tableName); $this->getReport()->add($this->context, $operation); continue; } if ($tableData['resource'] !== $registryTablesAfter[$moduleName][$tableName]['resource']) { $operation = new TableChangeResource( - $moduleName, + $fileBefore, $tableName, $tableData['resource'], $registryTablesAfter[$moduleName][$tableName]['resource'] @@ -73,12 +74,13 @@ public function analyze($registryBefore, $registryAfter) } } foreach ($registryTablesAfter as $moduleName => $moduleTables) { + $fileAfter = $registryAfter->mapping['table'][$moduleName]; foreach ($moduleTables as $tableName => $tableData) { if ( !isset($registryTablesBefore[$moduleName][$tableName]) && !$this->isModificationTableDeclaration($registryTablesAfter, $moduleName, $tableName) ) { - $operation = new TableAdded($moduleName, $tableName); + $operation = new TableAdded($fileAfter, $tableName); $this->getReport()->add($this->context, $operation); } } diff --git a/src/Analyzer/DBSchema/DbSchemaUniqueKeyAnalyzer.php b/src/Analyzer/DBSchema/DbSchemaUniqueKeyAnalyzer.php index f8fa1812..dc7c88b4 100644 --- a/src/Analyzer/DBSchema/DbSchemaUniqueKeyAnalyzer.php +++ b/src/Analyzer/DBSchema/DbSchemaUniqueKeyAnalyzer.php @@ -56,6 +56,7 @@ public function analyze($registryBefore, $registryAfter) $registryTablesAfter = $registryAfter->data['table'] ?? []; foreach ($registryTablesBefore as $moduleName => $moduleTables) { + $fileBefore = $registryBefore->mapping['table'][$moduleName]; foreach ($moduleTables as $tableName => $tableData) { $keys = $tableData['unique'] ?? []; foreach ($keys as $name => $key) { @@ -63,7 +64,7 @@ public function analyze($registryBefore, $registryAfter) continue; } if ($key !== null && !isset($registryTablesAfter[$moduleName][$tableName]['unique'][$name])) { - $operation = new UniqueKeyDrop($moduleName, $tableName . '/' . $name); + $operation = new UniqueKeyDrop($fileBefore, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); continue; } @@ -77,7 +78,7 @@ public function analyze($registryBefore, $registryAfter) } } if (!$matchedColumnFlag) { - $operation = new UniqueKeyChange($moduleName, $tableName . '/' . $name); + $operation = new UniqueKeyChange($fileBefore, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); break; } @@ -87,6 +88,7 @@ public function analyze($registryBefore, $registryAfter) } foreach ($registryTablesAfter as $moduleName => $moduleTables) { + $fileAfter = $registryAfter->mapping['table'][$moduleName]; foreach ($moduleTables as $tableName => $tableData) { $keys = $tableData['unique'] ?? []; foreach ($keys as $name => $key) { @@ -94,7 +96,7 @@ public function analyze($registryBefore, $registryAfter) continue; } if ($key !== null && !isset($registryTablesBefore[$moduleName][$tableName]['unique'][$name])) { - $operation = new UniqueKeyAdd($moduleName, $tableName . '/' . $name); + $operation = new UniqueKeyAdd($fileAfter, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); continue; } @@ -109,7 +111,7 @@ public function analyze($registryBefore, $registryAfter) } } if (!$matchedColumnFlag) { - $operation = new UniqueKeyChange($moduleName, $tableName . '/' . $name); + $operation = new UniqueKeyChange($fileAfter, $tableName . '/' . $name); $this->getReport()->add($this->context, $operation); break; } diff --git a/src/Analyzer/DBSchema/DbSchemaWhitelistAnalyzer.php b/src/Analyzer/DBSchema/DbSchemaWhitelistAnalyzer.php index 0b10c288..1b1fa623 100644 --- a/src/Analyzer/DBSchema/DbSchemaWhitelistAnalyzer.php +++ b/src/Analyzer/DBSchema/DbSchemaWhitelistAnalyzer.php @@ -11,11 +11,12 @@ use Magento\SemanticVersionChecker\Analyzer\AnalyzerInterface; use Magento\SemanticVersionChecker\Operation\InvalidWhitelist; +use Magento\SemanticVersionChecker\Operation\WhiteListWasRemoved; use PHPSemVerChecker\Registry\Registry; use PHPSemVerChecker\Report\Report; /** - * Implements an analyzer fdr the database schema whitelist files. + * Implements an analyzer for the database schema whitelist files. * @noinspection PhpUnused */ class DbSchemaWhitelistAnalyzer implements AnalyzerInterface @@ -54,17 +55,23 @@ public function analyze($registryBefore, $registryAfter) $dbWhiteListContent = $registryAfter->data['whitelist_json'] ?? []; foreach ($registryTablesAfter as $moduleName => $tablesData) { + $whiteListFileAfter = $registryAfter->mapping['whitelist_json'][$moduleName] ?? ''; + if (!file_exists($whiteListFileAfter)) { + $tableFileAfter = $registryAfter->mapping['table'][$moduleName]; + $whiteListFileAfter = dirname($tableFileAfter) . '/db_schema_whitelist.json'; + $operation = new WhiteListWasRemoved($whiteListFileAfter, $moduleName); + $this->report->add('database', $operation); + continue; + } if (count($tablesData)) { foreach (array_keys($tablesData) as $table) { if (!isset($dbWhiteListContent[$moduleName][$table])) { - $operation = new InvalidWhitelist($moduleName, $table); + $operation = new InvalidWhitelist($whiteListFileAfter, $table); $this->report->add('database', $operation); } } } } - - return $this->report; } } diff --git a/src/Analyzer/DBSchema/DbSchemaWhitelistReductionOrRemovalAnalyzer.php b/src/Analyzer/DBSchema/DbSchemaWhitelistReductionOrRemovalAnalyzer.php index 3dcdd78b..97a5e596 100644 --- a/src/Analyzer/DBSchema/DbSchemaWhitelistReductionOrRemovalAnalyzer.php +++ b/src/Analyzer/DBSchema/DbSchemaWhitelistReductionOrRemovalAnalyzer.php @@ -49,8 +49,9 @@ public function analyze($registryBefore, $registryAfter) /** @var array $tablesData */ foreach ($whiteListBefore as $moduleName => $beforeModuleTablesData) { + $fileBefore = $registryBefore->mapping['whitelist_json'][$moduleName]; if (!isset($whiteListAfter[$moduleName])) { - $operation = new WhiteListWasRemoved($moduleName); + $operation = new WhiteListWasRemoved($fileBefore, $moduleName); $this->report->add('database', $operation); continue; } @@ -58,14 +59,14 @@ public function analyze($registryBefore, $registryAfter) /** @var array $beforeTableData */ foreach ($beforeModuleTablesData as $tableName => $beforeTableData) { if (!$this->isArrayExistsAndHasSameSize($afterModuleTablesData, $beforeTableData, $tableName)) { - $this->addReport($moduleName, $tableName); + $this->addReport($fileBefore, $tableName); continue; } $afterTableData = $afterModuleTablesData[$tableName]; /** @var array $beforeTablePartData */ foreach ($beforeTableData as $tablePartName => $beforeTablePartData) { if (!$this->isArrayExistsAndHasSameSize($afterTableData, $beforeTablePartData, $tablePartName)) { - $this->addReport($moduleName, $tableName . '/' . $tablePartName); + $this->addReport($fileBefore, $tableName . '/' . $tablePartName); continue; } $afterTablePartData = $afterTableData[$tablePartName]; @@ -73,7 +74,7 @@ public function analyze($registryBefore, $registryAfter) foreach ($beforeTablePartData as $name => $beforeStatus) { //checks if array exists in new whitelist.json and if it has different amount of items inside if (!isset($afterTablePartData[$name])) { - $this->addReport($moduleName, $tableName . '/' . $tablePartName . '/' . $name); + $this->addReport($fileBefore, $tableName . '/' . $tablePartName . '/' . $name); } } } @@ -102,14 +103,14 @@ public function isArrayExistsAndHasSameSize(array $after, array $beforeArray, st } /** - * @param string $moduleName + * @param string $location * @param string $target * * @return void */ - public function addReport(string $moduleName, string $target): void + public function addReport(string $location, string $target): void { - $operation = new WhiteListReduced($moduleName, $target); + $operation = new WhiteListReduced($location, $target); $this->report->add('database', $operation); } } diff --git a/src/Analyzer/DbSchemaWhitelistAnalyzer.php b/src/Analyzer/DbSchemaWhitelistAnalyzer.php deleted file mode 100644 index 6017f5a4..00000000 --- a/src/Analyzer/DbSchemaWhitelistAnalyzer.php +++ /dev/null @@ -1,81 +0,0 @@ -data['table'] ?? []; - $registryTablesBefore = $registryBefore->data['table'] ?? []; - - foreach ($registryTablesAfter as $moduleName => $tablesData) { - if (count($tablesData)) { - //Take file like an example - //We will replace module_name in file_path in order to get - //correct module - $dbFile = $registryAfter->getCurrentFile(); - $dbWhiteListFile = preg_replace( - '/(.*Magento\/)\w+(\/.*)/', - '$1' . explode("_", $moduleName)[1] . '$2', - $dbFile - ); - $dbWhiteListFile = str_replace( - 'db_schema.xml', - 'db_schema_whitelist.json', - $dbWhiteListFile - ); - if (!file_exists($dbWhiteListFile)) { - $operation = new WhiteListWasRemoved($moduleName); - $report->add('database', $operation); - continue; - } else { - $dbWhiteListContent = json_decode( - file_get_contents($dbWhiteListFile), - true - ); - } - - $tables = array_replace($tablesData, $registryTablesBefore[$moduleName] ?? []); - foreach (array_keys($tables) as $table) { - if (!isset($dbWhiteListContent[$table])) { - $operation = new InvalidWhitelist($dbWhiteListFile, $table); - $report->add('database', $operation); - } - } - } - } - - - return $report; - } -} diff --git a/src/Analyzer/DiXml/VirtualTypeAnalyzer.php b/src/Analyzer/DiXml/VirtualTypeAnalyzer.php index 1db35f2f..5dd021c4 100644 --- a/src/Analyzer/DiXml/VirtualTypeAnalyzer.php +++ b/src/Analyzer/DiXml/VirtualTypeAnalyzer.php @@ -56,17 +56,18 @@ public function analyze($registryBefore, $registryAfter) foreach ($nodesBefore as $moduleName => $moduleNodes) { /* @var VirtualType $nodeBefore */ + $fileBefore = $registryBefore->mapping[XmlRegistry::NODES_KEY][$moduleName]; foreach ($moduleNodes as $name => $nodeBefore) { // search nodesAfter the by name $nodeAfter = $nodesAfter[$moduleName][$name] ?? false; if ($nodeAfter !== false && $nodeBefore !== $nodeAfter) { /* @var VirtualType $nodeAfter */ - $this->triggerNodeChange($nodeBefore, $nodeAfter); + $this->triggerNodeChange($nodeBefore, $nodeAfter, $fileBefore); continue; } - $operation = new VirtualTypeRemoved($moduleName, $name); + $operation = new VirtualTypeRemoved($fileBefore, $name); $this->report->add('di', $operation); } } @@ -103,8 +104,9 @@ private function getVirtualTypeNode(XmlRegistry $xmlRegistry): array * * @param VirtualType $nodeBefore * @param VirtualType $nodeAfter + * @param string $beforeFilePath */ - private function triggerNodeChange(VirtualType $nodeBefore, VirtualType $nodeAfter): void + private function triggerNodeChange(VirtualType $nodeBefore, VirtualType $nodeAfter, string $beforeFilePath): void { $bcFieldBefore = [ 'type' => $nodeBefore->getType(), @@ -124,7 +126,7 @@ private function triggerNodeChange(VirtualType $nodeBefore, VirtualType $nodeAft foreach ($bcFieldBefore as $fieldName => $valueBefore) { $valueAfter = $bcFieldAfter[$fieldName]; if ($valueBefore !== $valueAfter) { - $operation = new VirtualTypeChanged($nodeBefore->getName(), $fieldName); + $operation = new VirtualTypeChanged($beforeFilePath, $fieldName); $this->report->add('di', $operation); } } diff --git a/src/Analyzer/Layout/Analyzer.php b/src/Analyzer/Layout/Analyzer.php index 7a65a3c1..e5e4c8ef 100644 --- a/src/Analyzer/Layout/Analyzer.php +++ b/src/Analyzer/Layout/Analyzer.php @@ -46,8 +46,8 @@ public function __construct(Report $report) /** * Compared registryBefore and registryAfter find changes for layout block types * - * @param XmlRegistry|Registry $registryBefore - * @param XmlRegistry|Registry $registryAfter + * @param XmlRegistry $registryBefore + * @param XmlRegistry $registryAfter * @return Report */ public function analyze($registryBefore, $registryAfter) @@ -60,23 +60,18 @@ public function analyze($registryBefore, $registryAfter) foreach (array_keys($nodesBefore) as $moduleName) { $moduleNodesBefore = $nodesBefore[$moduleName] ?? []; - $moduleNodesAfter = []; - - /** - * @var LayoutNodeInterface $node - */ - foreach ($nodesAfter[$moduleName] ?? [] as $node) { - $moduleNodesAfter[$moduleName][$node->getUniqueKey()] = $node; - } + $moduleNodesAfter = $nodesAfter[$moduleName] ?? []; /** * @var string $nodeName * @var LayoutNodeInterface $node */ foreach ($moduleNodesBefore as $nodeName => $node) { - $nodeAfter = $moduleNodesAfter[$moduleName][$node->getUniqueKey()] ?? false; + $uniqueKey = $node->getUniqueKey(); + $nodeAfter = $moduleNodesAfter[$uniqueKey] ?? false; if ($nodeAfter === false) { - $this->triggerNodeRemoved($moduleName, $node); + $beforeFilePath = $registryBefore->getLayoutFile($moduleName, $uniqueKey); + $this->triggerNodeRemoved($node, $beforeFilePath); } } } @@ -85,23 +80,23 @@ public function analyze($registryBefore, $registryAfter) } /** - * @param string $moduleName * @param $node + * @param string $beforeFilePath */ - private function triggerNodeRemoved(string $moduleName, $node): void + private function triggerNodeRemoved($node, string $beforeFilePath): void { if ($node instanceof Block) { - $this->report->add('layout', new BlockRemoved($moduleName, $node->getName())); + $this->report->add('layout', new BlockRemoved($beforeFilePath, $node->getName())); return; } if ($node instanceof Container) { - $this->report->add('layout', new ContainerRemoved($moduleName, $node->getName())); + $this->report->add('layout', new ContainerRemoved($beforeFilePath, $node->getName())); return; } if ($node instanceof Update) { - $this->report->add('layout', new UpdateRemoved($moduleName, $node->getHandle())); + $this->report->add('layout', new UpdateRemoved($beforeFilePath, $node->getHandle())); return; } } diff --git a/src/Analyzer/Less/Analyzer.php b/src/Analyzer/Less/Analyzer.php index 8272bde0..1ef3fe02 100644 --- a/src/Analyzer/Less/Analyzer.php +++ b/src/Analyzer/Less/Analyzer.php @@ -15,6 +15,7 @@ use Magento\SemanticVersionChecker\Operation\Less\VariableRemoved; use Magento\SemanticVersionChecker\Operation\Less\MixinRemoved; use Magento\SemanticVersionChecker\Registry\LessRegistry; +use Magento\SemanticVersionChecker\Registry\XmlRegistry; use PHPSemVerChecker\Registry\Registry; use PHPSemVerChecker\Report\Report; use Less_Tree; @@ -74,6 +75,7 @@ public function analyze($registryBefore, $registryAfter) foreach ($commonModules as $moduleName) { $moduleLessFilesBefore = $nodesBefore[$moduleName]; $moduleLessFilesAfter = $nodesAfter[$moduleName]; + $commonLessFiles = array_intersect_key($moduleLessFilesBefore, $moduleLessFilesAfter); foreach (array_keys($commonLessFiles) as $lessFileName) { @@ -86,10 +88,12 @@ public function analyze($registryBefore, $registryAfter) if (count($removedNodeNames)) { //report removals $removedNodes = array_intersect_key($lessNodesBefore, array_flip($removedNodeNames)); - $this->reportRemovedNodes($lessFileName, $removedNodes); + $fileBefore = $registryBefore->mapping[LessRegistry::NODES_KEY][$moduleName][$lessFileName]; + $this->reportRemovedNodes($fileBefore, $removedNodes); } elseif (!count($addedNodeNames) && !count($removedNodeNames)) { //report changes inside nodes - $this->reportUpdatedNodes($lessFileName, $lessNodesBefore, $lessNodesAfter); + $fileAfter = $registryAfter->mapping[LessRegistry::NODES_KEY][$moduleName][$lessFileName]; + $this->reportUpdatedNodes($fileAfter, $lessNodesBefore, $lessNodesAfter); } } } diff --git a/src/Analyzer/SystemXml/Analyzer.php b/src/Analyzer/SystemXml/Analyzer.php index 4841e0bf..5fe050a3 100644 --- a/src/Analyzer/SystemXml/Analyzer.php +++ b/src/Analyzer/SystemXml/Analyzer.php @@ -77,10 +77,10 @@ public function analyze($registryBefore, $registryAfter) $removedModules = array_diff($modulesBefore, $modulesAfter); //process added files - $this->reportAddedFiles($addedModules); + $this->reportAddedFiles($addedModules, $registryAfter); //process removed files - $this->reportRemovedFiles($removedModules); + $this->reportRemovedFiles($removedModules, $registryBefore); //process common files foreach ($commonModules as $moduleName) { @@ -88,11 +88,15 @@ public function analyze($registryBefore, $registryAfter) $moduleNodesAfter = $nodesAfter[$moduleName]; $addedNodes = array_diff_key($moduleNodesAfter, $moduleNodesBefore); $removedNodes = array_diff_key($moduleNodesBefore, $moduleNodesAfter); - - $this->reportAddedNodes($moduleName, $addedNodes); - $this->reportRemovedNodes($moduleName, $removedNodes); + if ($removedNodes) { + $beforeFile = $registryBefore->mapping[XmlRegistry::NODES_KEY][$moduleName]; + $this->reportRemovedNodes($beforeFile, $removedNodes); + } + if ($addedNodes) { + $afterFile = $registryAfter->mapping[XmlRegistry::NODES_KEY][$moduleName]; + $this->reportAddedNodes($afterFile, $addedNodes); + } } - return $this->report; } @@ -125,11 +129,13 @@ private function getNodes(XmlRegistry $registry): array * Creates reports for $modules considering that system.xml has been added to them. * * @param string[] $modules + * @param XmlRegistry $registryAfter */ - private function reportAddedFiles(array $modules) + private function reportAddedFiles(array $modules, XmlRegistry $registryAfter) { foreach ($modules as $module) { - $this->report->add('system', new FileAdded($module, 'system.xml')); + $afterFile = $registryAfter->mapping[XmlRegistry::NODES_KEY][$module]; + $this->report->add('system', new FileAdded($afterFile, 'system.xml')); } } @@ -162,11 +168,13 @@ private function reportAddedNodes(string $file, array $nodes) * Creates reports for $modules considering that system.xml has been removed from them. * * @param array $modules + * @param XmlRegistry $registryBefore */ - private function reportRemovedFiles(array $modules) + private function reportRemovedFiles(array $modules, XmlRegistry $registryBefore) { foreach ($modules as $module) { - $this->report->add('system', new FileRemoved($module, 'system.xml')); + $beforeFile = $registryBefore->mapping[XmlRegistry::NODES_KEY][$module]; + $this->report->add('system', new FileRemoved($beforeFile, 'system.xml')); } } diff --git a/src/Analyzer/Xsd/Analyzer.php b/src/Analyzer/Xsd/Analyzer.php index 5e6530f8..1d39855a 100644 --- a/src/Analyzer/Xsd/Analyzer.php +++ b/src/Analyzer/Xsd/Analyzer.php @@ -73,10 +73,10 @@ public function analyze($registryBefore, $registryAfter) $commonModules = array_intersect(array_keys($nodesBefore), array_keys($nodesAfter)); //process added modules - $this->reportAddedModules($addedModules); + $this->reportAddedModules($addedModules, $registryAfter); //process removed modules - $this->reportRemovedModules($removedModules); + $this->reportRemovedModules($removedModules, $registryBefore); //process common modules foreach ($commonModules as $moduleName) { @@ -91,10 +91,10 @@ public function analyze($registryBefore, $registryAfter) $commonFiles = array_intersect($filesBefore, $filesAfter); //process added files - $this->reportAddedSchemaDeclarations($moduleName, $addedFiles); + $this->reportAddedSchemaDeclarations($moduleName, $addedFiles, $registryAfter); //process removed files - $this->reportRemovedSchemaDeclarations($moduleName, $removedFiles); + $this->reportRemovedSchemaDeclarations($moduleName, $removedFiles, $registryBefore); //process common files foreach ($commonFiles as $fileName) { @@ -106,10 +106,16 @@ public function analyze($registryBefore, $registryAfter) $removedNodes = array_diff_key($nodesBefore, $nodesAfter); //process added nodes - $this->reportAddedNodes($moduleName, $addedNodes); + if ($addedNodes) { + $filePath = $registryAfter->mapping[XmlRegistry::NODES_KEY][$moduleName][$fileName]; + $this->reportAddedNodes($filePath, $addedNodes); + } //process removed nodes - $this->reportRemovedNodes($moduleName, $removedNodes); + if ($removedNodes) { + $filePath = $registryBefore->mapping[XmlRegistry::NODES_KEY][$moduleName][$fileName]; + $this->reportRemovedNodes($filePath, $removedNodes); + } } } @@ -159,12 +165,13 @@ private function getNodes(XmlRegistry $registry): array * Creates reports for $modules that have been added. * * @param array $modules + * @param Registry $beforeRegistry */ - private function reportAddedModules(array $modules): void + private function reportAddedModules(array $modules, Registry $beforeRegistry): void { foreach ($modules as $moduleName => $files) { - $fileNames = array_keys($files); - $this->reportAddedSchemaDeclarations($moduleName, $fileNames); + $relativeFilePaths = array_keys($files); + $this->reportAddedSchemaDeclarations($moduleName, $relativeFilePaths, $beforeRegistry); } } @@ -202,12 +209,14 @@ private function reportAddedNodes(string $module, array $nodes): void * Creates reports for $files in $module that have been added. * * @param string $module - * @param string[] $files + * @param string[] $relativeFilePaths + * @param Registry $registry */ - private function reportAddedSchemaDeclarations(string $module, array $files): void + private function reportAddedSchemaDeclarations(string $module, array $relativeFilePaths, Registry $registry): void { - foreach ($files as $file) { - $this->report->add(self::CONTEXT, new SchemaDeclarationAdded($module, $file)); + foreach ($relativeFilePaths as $relativeFilePath) { + $fullFilePath = $registry->mapping[XmlRegistry::NODES_KEY][$module][$relativeFilePath]; + $this->report->add(self::CONTEXT, new SchemaDeclarationAdded($fullFilePath, $relativeFilePath)); } } @@ -215,32 +224,33 @@ private function reportAddedSchemaDeclarations(string $module, array $files): vo * Creates reports for $modules that have been removed. * * @param array $modules + * @param Registry $registryBefore */ - private function reportRemovedModules(array $modules): void + private function reportRemovedModules(array $modules, Registry $registryBefore): void { foreach ($modules as $moduleName => $files) { - $fileNames = array_keys($files); - $this->reportRemovedSchemaDeclarations($moduleName, $fileNames); + $relativeFilePaths = array_keys($files); + $this->reportRemovedSchemaDeclarations($moduleName, $relativeFilePaths, $registryBefore); } } /** * Creates reports for $nodes that have been removed from $file in $module. * - * @param string $module + * @param string $filePath * @param NodeInterface[] $nodes */ - private function reportRemovedNodes(string $module, array $nodes): void + private function reportRemovedNodes(string $filePath, array $nodes): void { foreach ($nodes as $node) { switch (true) { case $node instanceof AttributeNode: - $data = new AttributeRemoved($module, $node->getName()); + $data = new AttributeRemoved($filePath, $node->getName()); $this->report->add(self::CONTEXT, $data); break; case $node instanceof ElementNode: - $data = new NodeRemoved($module, $node->getName()); + $data = new NodeRemoved($filePath, $node->getName()); $this->report->add(self::CONTEXT, $data); break; @@ -254,12 +264,17 @@ private function reportRemovedNodes(string $module, array $nodes): void * Creates reports for $files that have been removed in $module * * @param string $module - * @param array $files + * @param array $relativeFilePaths + * @param Registry $registryBefore */ - private function reportRemovedSchemaDeclarations(string $module, array $files): void - { - foreach ($files as $file) { - $this->report->add(self::CONTEXT, new SchemaDeclarationRemoved($module, $file)); + private function reportRemovedSchemaDeclarations( + string $module, + array $relativeFilePaths, + Registry $registryBefore + ): void { + foreach ($relativeFilePaths as $relativeFilePath) { + $fullPath = $registryBefore->mapping[XmlRegistry::NODES_KEY][$module][$relativeFilePath]; + $this->report->add(self::CONTEXT, new SchemaDeclarationRemoved($fullPath, $relativeFilePath)); } } } diff --git a/src/Console/Command/CompareSourceCommand.php b/src/Console/Command/CompareSourceCommand.php index 1c373019..04959f1d 100644 --- a/src/Console/Command/CompareSourceCommand.php +++ b/src/Console/Command/CompareSourceCommand.php @@ -13,6 +13,7 @@ use Magento\SemanticVersionChecker\FileChangeDetector; use Magento\SemanticVersionChecker\ReportBuilder; use Magento\SemanticVersionChecker\Reporter\HtmlDbSchemaReporter; +use Magento\SemanticVersionChecker\Reporter\HtmlPackageLevelChangesRenderer; use Magento\SemanticVersionChecker\ReportTypes; use Magento\SemanticVersionChecker\SemanticVersionChecker; use PHPSemVerChecker\SemanticVersioning\Level; @@ -96,7 +97,6 @@ protected function configure() /** * @param InputInterface $input * @param OutputInterface $cliOutput - * @return void */ protected function execute(InputInterface $input, OutputInterface $cliOutput) { @@ -180,6 +180,8 @@ protected function execute(InputInterface $input, OutputInterface $cliOutput) 'Changed filesNo changed files found.' ); } + $pkgLevelChangeRenderer = new HtmlPackageLevelChangesRenderer($versionReport, $input, $logOutputStream); + $pkgLevelChangeRenderer->outputPackageChanges(); $logOutputStream->writeln($this->getHtmlFooter()); } else { @@ -218,8 +220,9 @@ protected function execute(InputInterface $input, OutputInterface $cliOutput) "It exceeds the allowed change level, which is $allowedChangeLevel " . '(' . $versionIncWord . ').' ); - exit(-1); + return -1; } + return 0; } private function validateAllowedLevel($input) @@ -342,6 +345,19 @@ private function getHtmlHeader() th.column30 { width: 30%; } +.btn-tooltip:hover:after { + content: "Click to Copy JSON"; + position: absolute; + background-color: gray; + color: white; +} + .btn-tooltip-copied:hover:after { + content: "Copied!"; + position: absolute; + background-color: gray; + color: white; + } + diff --git a/src/Helper/PackageNameResolver.php b/src/Helper/PackageNameResolver.php new file mode 100644 index 00000000..f5931331 --- /dev/null +++ b/src/Helper/PackageNameResolver.php @@ -0,0 +1,76 @@ +input = $input; + } + + /** + * Gets the matching composer.json given a filepath. Will return null if composer.json is not found + * + * @param string $filepath + * @return string|null + */ + private function getComposerPackageLocation(string $filepath): ?string + { + $sourceBeforeDir = realpath($this->input->getArgument('source-before')); + $sourceAfterDir = realpath($this->input->getArgument('source-after')); + $level = 1; + $composerDirPath = dirname($filepath, $level); + while ( + $composerDirPath !== $sourceBeforeDir + && $composerDirPath !== $sourceAfterDir + && $composerDirPath !== '.' + ) { + $composerPath = $composerDirPath . '/composer.json'; + if (is_file($composerPath)) { + return $composerPath; + } + $composerDirPath = dirname($filepath, ++$level); + } + return null; + } + + /** + * Get the real name of package that contains the input file + * + * @param string $filepath + * @return string|null + */ + public function getPackageName(string $filepath): ?string + { + $composerFilePath = $this->getComposerPackageLocation($filepath); + if (!$composerFilePath) { + return null; + } + $composerFile = file_get_contents($composerFilePath); + $composerJson = json_decode($composerFile); + return $composerJson->name; + } +} diff --git a/src/Operation/InvalidWhitelist.php b/src/Operation/InvalidWhitelist.php index b0410d51..d48fcc1b 100644 --- a/src/Operation/InvalidWhitelist.php +++ b/src/Operation/InvalidWhitelist.php @@ -43,15 +43,15 @@ class InvalidWhitelist extends Operation * * @var string */ - protected $fileBefore; + protected $location; /** - * @param string $fileBefore + * @param string $location * @param string $target */ - public function __construct($fileBefore, $target) + public function __construct($location, $target) { - $this->fileBefore = $fileBefore; + $this->location = $location; $this->target = $target; } @@ -62,7 +62,7 @@ public function __construct($fileBefore, $target) */ public function getLocation() { - return $this->fileBefore; + return $this->location; } public function getReason() diff --git a/src/Operation/WhiteListWasRemoved.php b/src/Operation/WhiteListWasRemoved.php index 1670d951..b8635caf 100644 --- a/src/Operation/WhiteListWasRemoved.php +++ b/src/Operation/WhiteListWasRemoved.php @@ -42,12 +42,18 @@ class WhiteListWasRemoved extends Operation * @var string */ protected $target; + /** + * @var string + */ + private $location; /** + * @param string $location * @param string $target */ - public function __construct($target) + public function __construct($location, $target) { + $this->location = $location; $this->target = $target; } @@ -58,7 +64,7 @@ public function __construct($target) */ public function getLocation(): string { - return $this->target; + return $this->location; } /** diff --git a/src/Registry/XmlRegistry.php b/src/Registry/XmlRegistry.php index ef9bb9e3..eda97dbb 100644 --- a/src/Registry/XmlRegistry.php +++ b/src/Registry/XmlRegistry.php @@ -9,6 +9,8 @@ namespace Magento\SemanticVersionChecker\Registry; +use Magento\SemanticVersionChecker\Node\Layout\Container; +use Magento\SemanticVersionChecker\Node\Layout\LayoutNodeInterface; use PHPSemVerChecker\Registry\Registry; class XmlRegistry extends Registry @@ -29,6 +31,30 @@ public function addXmlNode(string $context, $data): void $this->data[self::NODES_KEY][$context][] = $data; } + /** + * Add layout container node to mapping and data + * + * @param LayoutNodeInterface $layoutNode + * @param string $moduleName + */ + public function addLayoutContainerNode(LayoutNodeInterface $layoutNode, string $moduleName) + { + $this->data[self::NODES_KEY][$moduleName][$layoutNode->getUniqueKey()] = $layoutNode; + $this->mapping[self::NODES_KEY][$moduleName][$layoutNode->getUniqueKey()] = $this->getCurrentFile(); + } + + /** + * Get the corresponding file given the module name and layoutNode key + * + * @param string $moduleName + * @param string $uniqueKey + * @return mixed + */ + public function getLayoutFile(string $moduleName, string $uniqueKey) + { + return $this->mapping[self::NODES_KEY][$moduleName][$uniqueKey]; + } + /** * Return all nodes that were found in the xml. * @return array diff --git a/src/Reporter/HtmlPackageLevelChangesRenderer.php b/src/Reporter/HtmlPackageLevelChangesRenderer.php new file mode 100644 index 00000000..617bebc1 --- /dev/null +++ b/src/Reporter/HtmlPackageLevelChangesRenderer.php @@ -0,0 +1,210 @@ +report = $report; + $this->input = $input; + $this->output = $output; + $this->packageNameResolver = new PackageNameResolver($input); + } + + /** + * Output Package Level Changes table. + */ + public function outputPackageChanges() + { + $pkgChangesJson = $this->getPackageChanges(); + $this->output->writeln('Package Level Changes'); + //Skip writing table if no severe changes are detected + if (!$pkgChangesJson) { + $this->output->writeln('No BIC changes found to packages'); + return; + } + $this->output->writeln('
'); + $this->output->writeln( + '' . + '' + ); + + foreach ($pkgChangesJson as $pkg) { + $this->output->writeln( + '' + ); + } + $this->output->writeln('
LevelPackage Name
' . $pkg['level'] . '' . $pkg['name'] . '
'); + $this->printClipboardJS(); + $pkgChangesJsonString = json_encode($pkgChangesJson, JSON_PRETTY_PRINT); + $this->output->writeln('
');
+        $this->output->writeln($pkgChangesJsonString);
+
+        $this->output->writeln('
'); + } + + /** + * Outputs JS to copy JSON to clipboard + */ + private function printClipboardJS() + { + $this->output->writeln(<< + + +COPY_PKG_JSON_SCRIPT + ); + } + + /** + * Get array of changed packages and their severity + * + * @return array + */ + private function getPackageChanges(): array + { + $results = []; + foreach (self::$contexts as $context) { + foreach (Level::asList('desc') as $level) { + $reportForLevel = $this->report[$context][$level] ?? []; + /** @var \PHPSemVerChecker\Operation\Operation $operation */ + foreach ($reportForLevel as $operation) { + $pkgName = $this->packageNameResolver->getPackageName($operation->getLocation()); + if ($pkgName === null) { + $error = "Unable to resolve package name for composer.json for change to file: " + . $operation->getLocation(); + $this->output->writeln('
' . $error  . '
'); + continue; + } + $this->saveLevelOfChange($pkgName, $level, $results); + } + } + } + $results = $this->transformOutputArray($results); + return $results; + } + + /** + * Insert package into results array. Skip inserting if change is less severe than currently stored packageChange + * + * @param string $pkgName + * @param int $level + * @param array $results + */ + private function saveLevelOfChange(string $pkgName, int $level, array &$results) + { + if (!isset($results[$pkgName]) || $level > $results[$pkgName]) { + $results[$pkgName] = $level; + } + } + + /** + * Transforms array of pkgChanges into expected output format + * + * @param array $pkgChanges + * @return array + */ + private function transformOutputArray(array $pkgChanges) + { + $results = []; + $minimumChangeLevel = $this->input->getArgument('allowed-change-level'); + foreach ($pkgChanges as $pkgName => $level) { + if ($level > $minimumChangeLevel) { + $results[] = [ + 'name' => $pkgName, + 'level' => Level::toString($level) + ]; + } + } + return $results; + } +} diff --git a/src/Scanner/DbSchemaScanner.php b/src/Scanner/DbSchemaScanner.php index 8f40bb72..2cfa00c5 100644 --- a/src/Scanner/DbSchemaScanner.php +++ b/src/Scanner/DbSchemaScanner.php @@ -106,6 +106,7 @@ public function scanJson(string $filePath): void { $tables = json_decode(file_get_contents($filePath), true); $moduleName = $this->getModuleNameByPath->resolveByEtcDirFilePath($this->registry->getCurrentFile()); + $this->getRegistry()->mapping['whitelist_json'][$moduleName] = $filePath; foreach ($tables as $tableName => $tableData) { $this->getRegistry()->data['whitelist_json'][$moduleName][$tableName] = $tableData; } @@ -155,7 +156,9 @@ private function isJson(string $file): bool private function processTable(array $data) { $name = $data['@attributes']['name']; - $moduleName = $this->getModuleNameByPath->resolveByEtcDirFilePath($this->registry->getCurrentFile()); + $file = $this->getRegistry()->getCurrentFile(); + $moduleName = $this->getModuleNameByPath->resolveByEtcDirFilePath($file); + $this->getRegistry()->mapping['table'][$moduleName] = $file; $resource = isset($data['@attributes']['resource']) ? $data['@attributes']['resource'] : 'default'; $this->getRegistry()->data['table'][$moduleName][$name]['resource'] = $resource; diff --git a/src/Scanner/DiConfigScanner.php b/src/Scanner/DiConfigScanner.php index c347e6a1..ed178326 100644 --- a/src/Scanner/DiConfigScanner.php +++ b/src/Scanner/DiConfigScanner.php @@ -55,6 +55,8 @@ public function scan(string $file): void private function registerVirtualTypeNodes(DOMNodeList $virtualTypeNodes, string $fileName): void { $moduleName = $this->getModuleNameByPath->resolveByEtcDirFilePath($fileName); + $this->getRegistry()->mapping[XmlRegistry::NODES_KEY][$moduleName] = $fileName; + $scope = $this->getScopeFromFile($fileName); /** @var DOMNode $node */ foreach ($virtualTypeNodes as $node) { diff --git a/src/Scanner/EtSchemaScanner.php b/src/Scanner/EtSchemaScanner.php index 2dcdaa3c..4ee601ce 100644 --- a/src/Scanner/EtSchemaScanner.php +++ b/src/Scanner/EtSchemaScanner.php @@ -61,6 +61,7 @@ public function scan(string $file): void $moduleName = $this->getModuleNameByPath->resolveByEtcDirFilePath($file); $data = $this->converter->convert($doc); $this->getRegistry()->data[EtSchemaAnalyzer::CONTEXT][$moduleName] = $data; + $this->getRegistry()->mapping[EtSchemaAnalyzer::CONTEXT][$moduleName] = $file; } /** diff --git a/src/Scanner/LayoutConfigScanner.php b/src/Scanner/LayoutConfigScanner.php index a724d247..4798486a 100644 --- a/src/Scanner/LayoutConfigScanner.php +++ b/src/Scanner/LayoutConfigScanner.php @@ -51,9 +51,11 @@ public function __construct(XmlRegistry $registry, ModuleNamespaceResolver $getM */ public function scan(string $file): void { + $this->registry->setCurrentFile($file); $doc = new DOMDocument(); $doc->loadXML(file_get_contents($file)); $moduleName = $this->getModuleNameByPath->resolveByViewDirFilePath($file); + $this->registerContainerNodes($doc->getElementsByTagName('container'), $moduleName); $this->registerBlockNodes($doc->getElementsByTagName('block'), $moduleName); $this->registerUpdateNodes($doc->getElementsByTagName('update'), $moduleName); @@ -77,7 +79,8 @@ private function registerContainerNodes(DOMNodeList $getElementsByTagName, strin foreach ($getElementsByTagName as $node) { $name = $node->getAttribute('name') ?? ''; $label = $node->getAttribute('label') ?? ''; - $this->registry->addXmlNode($moduleName, new Container($name, $label)); + $layoutNode = new Container($name, $label); + $this->registry->addLayoutContainerNode($layoutNode, $moduleName); } } @@ -96,8 +99,8 @@ private function registerBlockNodes(DOMNodeList $getElementsByTagName, string $m if ($node->getAttribute('cacheable') === 'false') { $cacheable = false; } - - $this->registry->addXmlNode($moduleName, new Block($name, $class, $template, $cacheable)); + $layoutNode = new Block($name, $class, $template, $cacheable); + $this->registry->addLayoutContainerNode($layoutNode, $moduleName); } } @@ -110,7 +113,8 @@ private function registerUpdateNodes(DOMNodeList $getElementsByTagName, string $ /** @var DOMNode $node */ foreach ($getElementsByTagName as $node) { $handle = $node->getAttribute('handle') ?? ''; - $this->registry->addXmlNode($moduleName, new Update($handle)); + $layoutNode = new Update($handle); + $this->registry->addLayoutContainerNode($layoutNode, $moduleName); } } } diff --git a/src/Scanner/LessScanner.php b/src/Scanner/LessScanner.php index deaddcd0..2b5e52e6 100644 --- a/src/Scanner/LessScanner.php +++ b/src/Scanner/LessScanner.php @@ -75,6 +75,7 @@ private function registerNode(Less_Tree $node) $relativeFilePath = $this->getRelativePath($file, $moduleName); $this->registry->data[LessRegistry::NODES_KEY][$moduleName][$relativeFilePath][] = $node; + $this->registry->mapping[LessRegistry::NODES_KEY][$moduleName][$relativeFilePath] = $file; } /** diff --git a/src/Scanner/MftfScanner.php b/src/Scanner/MftfScanner.php index 72f11c01..b883eb8b 100644 --- a/src/Scanner/MftfScanner.php +++ b/src/Scanner/MftfScanner.php @@ -87,8 +87,7 @@ private function registerEntityNode(array $entityNode): void $name = $entityNode['attributes']['name']; $file = $this->registry->getCurrentFile(); $moduleName = $this->moduleNamespaceResolver->resolveByTestMftfPath($file); - $relativeFilePath = $this->getRelativePath($file, $moduleName); - $entityNode['filePaths'][] = $relativeFilePath; + $entityNode['filePaths'][] = $file; // trim {}test => test $entityNode['type'] = str_replace(['{', '}'], '', $entityNode['name']); diff --git a/src/Scanner/SystemXmlScanner.php b/src/Scanner/SystemXmlScanner.php index a65aed8c..1685825f 100644 --- a/src/Scanner/SystemXmlScanner.php +++ b/src/Scanner/SystemXmlScanner.php @@ -59,6 +59,7 @@ public function scan(string $file): void { $doc = new DOMDocument(); $moduleName = $this->moduleNameResolver->resolveByEtcDirFilePath($file); + $this->getRegistry()->mapping[XmlRegistry::NODES_KEY][$moduleName] = $file; $doc->load($file); $this->xPath = new DOMXPath($doc); diff --git a/src/Scanner/XsdScanner.php b/src/Scanner/XsdScanner.php index 0a19fcb9..b6e0369c 100644 --- a/src/Scanner/XsdScanner.php +++ b/src/Scanner/XsdScanner.php @@ -138,6 +138,7 @@ private function registerNode(NodeInterface $node) $relativeFilePath = $this->getRelativePath($file, $moduleName); $this->registry->data[XmlRegistry::NODES_KEY][$moduleName][$relativeFilePath][] = $node; + $this->registry->mapping[XmlRegistry::NODES_KEY][$moduleName][$relativeFilePath] = $file; } /** diff --git a/tests/Unit/Console/Command/CompareSourceCommandDatabaseSchemasTest.php b/tests/Unit/Console/Command/CompareSourceCommandDatabaseSchemasTest.php index 3633a212..8e2dddec 100644 --- a/tests/Unit/Console/Command/CompareSourceCommandDatabaseSchemasTest.php +++ b/tests/Unit/Console/Command/CompareSourceCommandDatabaseSchemasTest.php @@ -64,8 +64,11 @@ public function changesDataProvider() $pathToFixtures . '/drop-foreign-key/source-code-before', $pathToFixtures . '/drop-foreign-key/source-code-after', [ - '/Database \(MAJOR\)/', - '/unit_test_table\/FL_ALLOWED_SEVERITIES\s*\|\s*Foreign key was removed\s*\|\s*M108/' + '#Database \(MAJOR\)#', + '#[\w/]+' . '/drop-foreign-key/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#', + '#unit_test_table/FL_ALLOWED_SEVERITIES\s*\|\s*Foreign key was removed\s*\|\s*M108#', + '#[\w/]+' . '/drop-foreign-key/source-code-before/Magento/DbSchema/etc/db_schema_whitelist\.json:0 \| unit_test_table/constraint#', + '#unit_test_table/constraint\s*\|\s*Module db schema whitelist reduced \(unit_test_table/constraint\)#' ], 'Major change is detected.' ], @@ -73,8 +76,9 @@ public function changesDataProvider() $pathToFixtures . '/change-foreign-key/source-code-before', $pathToFixtures . '/change-foreign-key/source-code-after', [ - '/Database \(MAJOR\)/', - '/unit_test_table\/FL_ALLOWED_SEVERITIES\/referenceTable\s*\|\s*Foreign key was changed\s*\|\s*M205/' + '#Database \(MAJOR\)#', + '#[\w/]+' . 'change-foreign-key/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#', + '#unit_test_table/FL_ALLOWED_SEVERITIES/referenceTable\s*\|\s*Foreign key was changed\s*\|\s*M205#' ], 'Major change is detected.' ], @@ -82,8 +86,9 @@ public function changesDataProvider() $pathToFixtures . '/add-foreign-key/source-code-before', $pathToFixtures . '/add-foreign-key/source-code-after', [ - '/Database \(MAJOR\)/', - '/unit_test_table\/FL_ALLOWED_SEVERITIES\s*\|\s*Foreign key was added\s*\|\s*M204/' + '#Database \(MAJOR\)#', + '#[\w/]+' . 'add-foreign-key/source-code-after/Magento/DbSchema/etc/db_schema\.xml:0#', + '#unit_test_table/FL_ALLOWED_SEVERITIES\s*\|\s*Foreign key was added\s*\|\s*M204#' ], 'Major change is detected.' ], @@ -91,8 +96,11 @@ public function changesDataProvider() $pathToFixtures . '/drop-primary-key/source-code-before', $pathToFixtures . '/drop-primary-key/source-code-after', [ - '/Database \(MAJOR\)/', - '/unit_test_table\/PRIMARY\s*\|\s*Primary key was removed\s*\|\s*M207/' + '#Database \(MAJOR\)#', + '#[\w/]+' . 'drop-primary-key/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#', + '#[\w/]+' . 'drop-primary-key/source-code-before/Magento/DbSchema/etc/db_schema_whitelist.json:0#', + '#unit_test_table\s*\|\s*Module db schema whitelist reduced \(unit_test_table\)\.\s*\|\s*M110#', + '#unit_test_table/PRIMARY\s*\|\s*Primary key was removed\s*\|\s*M207#' ], 'Major change is detected.' ], @@ -101,6 +109,8 @@ public function changesDataProvider() $pathToFixtures . '/change-primary-key/source-code-after', [ '/Database \(MAJOR\)/', + '#[\w/]+' . 'change-primary-key/source-code-after/Magento/DbSchema/etc/db_schema\.xml:0#', + '#[\w/]+' . 'change-primary-key/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#', '/unit_test_table\/PRIMARY\s*\|\s*Primary key was changed\s*\|\s*M206/' ], 'Major change is detected.' @@ -110,6 +120,7 @@ public function changesDataProvider() $pathToFixtures . '/add-primary-key/source-code-after', [ '/Database \(MAJOR\)/', + '#[\w/]+' . 'add-primary-key/source-code-after/Magento/DbSchema/etc/db_schema\.xml:0#', '/unit_test_table\/PRIMARY\s*\|\s*Primary key was added\s*\|\s*M205/' ], 'Major change is detected.' @@ -119,7 +130,10 @@ public function changesDataProvider() $pathToFixtures . '/drop-unique-key/source-code-after', [ '/Database \(MAJOR\)/', - '/unit_test_table\/UNIQUE_KEY\s*\|\s*Unique key was removed\s*\|\s*M209/' + '/unit_test_table\/UNIQUE_KEY\s*\|\s*Unique key was removed\s*\|\s*M209/', + '#unit_test_table/constraint\s*\|\s*Module db schema whitelist reduced \(unit_test_table/constraint\)\.\s*\|\s*M110#', + '#[\w/]+' . 'drop-unique-key/source-code-before/Magento/DbSchema/etc/db_schema.xml:0#', + '#[\w/]+' . 'drop-unique-key/source-code-before/Magento/DbSchema/etc/db_schema_whitelist.json:0#' ], 'Major change is detected.' ], @@ -128,7 +142,9 @@ public function changesDataProvider() $pathToFixtures . '/change-unique-key/source-code-after', [ '/Database \(MAJOR\)/', - '/unit_test_table\/UNIQUE_KEY\s*\|\s*Unique key was changed\s*\|\s*M210/' + '/unit_test_table\/UNIQUE_KEY\s*\|\s*Unique key was changed\s*\|\s*M210/', + '#[\w/]+' . 'change-unique-key/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#', + '#[\w/]+' . 'change-unique-key/source-code-after/Magento/DbSchema/etc/db_schema\.xml:0#' ], 'Major change is detected.' ], @@ -137,7 +153,8 @@ public function changesDataProvider() $pathToFixtures . '/add-unique-key/source-code-after', [ '/Database \(MAJOR\)/', - '/unit_test_table\/UNIQUE_KEY\s*\|\s*Unique key was added\s*\|\s*M208/' + '/unit_test_table\/UNIQUE_KEY\s*\|\s*Unique key was added\s*\|\s*M208/', + '#[\w/]+' . 'add-unique-key/source-code-after/Magento/DbSchema/etc/db_schema\.xml:0#' ], 'Major change is detected.' ], @@ -147,7 +164,9 @@ public function changesDataProvider() [ '/Database \(MAJOR\)/', '/unit_test_table\/time_occurred\s*\|\s*Column was removed\s*\|\s*M107/', - '/Module db schema whitelist reduced \(unit\_test\_table\/column\).\s*\|\s*M110/' + '/Module db schema whitelist reduced \(unit\_test\_table\/column\).\s*\|\s*M110/', + '#[\w/]+' . 'column-removed/source-code-before/Magento/DbSchema/etc/db_schema_whitelist\.json:0#', + '#[\w/]+' . 'column-removed/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#' ], 'Major change is detected.' ], @@ -156,6 +175,7 @@ public function changesDataProvider() $pathToFixtures . '/column-added/source-code-after', [ '/Database \(MINOR\)/', + '#[\w/]+' . 'column-added/source-code-after/Magento/DbSchema/etc/db_schema\.xml:0#', '/unit_test_table\/time_occurred\s*\|\s*Column was added\s*\|\s*M203/' ], 'Minor change is detected.' @@ -166,7 +186,9 @@ public function changesDataProvider() [ '/Database \(MAJOR\)/', '/other_unit_test_table\s*\|\s*Table was dropped\s*\|\s*M104/', - '/Module db schema whitelist reduced \(other\_unit\_test\_table\).\s*\|\s*M110/' + '/Module db schema whitelist reduced \(other\_unit\_test\_table\).\s*\|\s*M110/', + '#[\w/]+' . '/table-dropped/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#', + '#[\w/]+' . '/table-dropped/source-code-before/Magento/DbSchema/etc/db_schema_whitelist\.json:0#' ], 'Major change is detected.' ], @@ -175,7 +197,12 @@ public function changesDataProvider() $pathToFixtures . '/table-added/source-code-after', [ '/Database \(MINOR\)/', - '/other_unit_test_table\s*\|\s*Table was added\s*\|\s*M202/' + '/other_unit_test_table\s*\|\s*Table was added\s*\|\s*M202/', + '#other_table\s*\|\s*Table was added\s*\|\s*M202#', + '#other_table\s*\|\s*Whitelist do not have table other_table declared in db_schema\.xml\s*\|\s*M109#', + '#[\w/]+' . '/table-added/source-code-after/Magento/DbSchema/etc/db_schema\.xml:0#', + '#[\w/]+' . '/table-added/source-code-after/Magento/DbSchema/etc/db_schema_whitelist\.json:0#', + ], 'Minor change is detected.' ], @@ -185,6 +212,9 @@ public function changesDataProvider() [ '/Database \(MAJOR\)/', '/unit_test_table\s*\|\s*Table was dropped\s*\|\s*M104/', + '#[\w/]+' . 'table-changed/source-code-after/Magento/DbSchema/etc/db_schema\.xml:0#', + '#[\w/]+' . 'table-changed/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#', + '#[\w/]+' . 'table-changed/source-code-before/Magento/DbSchema/etc/db_schema_whitelist\.json:0#', '/unit_test_table\s*\|\s*Module db schema whitelist reduced \(unit\_test\_table\).\s*\|\s*M110/', '/new_unit_test_table\s*\|\s*Table was added\s*\|\s*M202/' ], @@ -195,6 +225,7 @@ public function changesDataProvider() $pathToFixtures . '/table-resource-changed/source-code-after', [ '/Database \(MAJOR\)/', + '#[\w/]+' . '/table-resource-changed/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#', '/unit_test_table\s*\|\s*Table chard was changed from default to sales\s*\|\s*M105/' ], 'Major change is detected.' @@ -204,10 +235,12 @@ public function changesDataProvider() $pathToFixtures . '/whitelist-was-reduced/source-code-after', [ '/Database \(MAJOR\)/', - '/Magento_DbSchema:0\s*\|\s*unit_test_table\s*\|\s*Module db schema whitelist reduced \(unit\_test\_table\).\s*\|\s*M110/', - '/Magento_DbSchema:0\s*\|\s*unit_test_table3\s*\|\s*Module db schema whitelist reduced \(unit\_test\_table3\).\s*\|\s*M110/', - '/Magento_DbSchemaSecond:0\s*\|\s*unit_test_table2\s*\|\s*Module db schema whitelist reduced \(unit\_test\_table2\).\s*\|\s*M110/', - '/Magento_DbSchemaSecond:0\s*\|\s*unit_test_table3\s*\|\s*Module db schema whitelist reduced \(unit\_test\_table3\).\s*\|\s*M110/' + '/Magento\/DbSchema\/etc\/db_schema_whitelist.json:0\s*\|\s*unit_test_table\s*\|\s*Module db schema whitelist reduced \(unit\_test\_table\).\s*\|\s*M110/', + '/Magento\/DbSchemaSecond\/etc\/db_schema_whitelist\.json:0\s*\|\s*unit_test_table3\s*\|\s*Module db schema whitelist reduced \(unit\_test\_table3\).\s*\|\s*M110/', + '/Magento\/DbSchemaSecond\/etc\/db_schema_whitelist\.json:0\s*\|\s*unit_test_table2\s*\|\s*Module db schema whitelist reduced \(unit\_test\_table2\).\s*\|\s*M110/', + '/Magento\/DbSchema\/etc\/db_schema_whitelist.json:0\s*\|\s*unit_test_table3\s*\|\s*Module db schema whitelist reduced \(unit\_test\_table3\).\s*\|\s*M110/', + '#[\w/]+' . '/whitelist-was-reduced/source-code-before/Magento/DbSchemaSecond/etc/db_schema\.xml:0#', + '#[\w/]+' . '/whitelist-was-reduced/source-code-before/Magento/DbSchema/etc/db_schema\.xml:0#' ], 'Major change is detected.' ], @@ -216,7 +249,7 @@ public function changesDataProvider() $pathToFixtures . '/whitelist-was-removed/source-code-after', [ '/Database \(MAJOR\)/', - '/Magento_DbSchema\s*\|\s*Db Whitelist from module Magento_DbSchema was removed\s*\|\s*M109/' + '/Magento\/DbSchema\/etc\/db_schema_whitelist\.json:0\s*\|\s*Magento_DbSchema\s*|\s*Db Whitelist from module Magento_DbSchema was removed\s*\|\s*M109/' ], 'Major change is detected.' ] diff --git a/tests/Unit/Console/Command/CompareSourceCommandDiXmlTest.php b/tests/Unit/Console/Command/CompareSourceCommandDiXmlTest.php index 0d7b2cbb..759785d2 100644 --- a/tests/Unit/Console/Command/CompareSourceCommandDiXmlTest.php +++ b/tests/Unit/Console/Command/CompareSourceCommandDiXmlTest.php @@ -7,12 +7,12 @@ namespace Magento\SemanticVersionChecker\Test\Unit\Console\Command; -use Magento\SemanticVersionChecker\Test\Unit\Console\Command\CompareSourceCommandTest\AbstractTestCase; +use Magento\SemanticVersionChecker\Test\Unit\Console\Command\CompareSourceCommandTest\AbstractTestCaseWithRegExp; /** * Test semantic version checker CLI command dealing with di.xml */ -class CompareSourceCommandDiXmlTest extends AbstractTestCase +class CompareSourceCommandDiXmlTest extends AbstractTestCaseWithRegExp { /** * Test semantic version checker CLI command for changes of the database schema. @@ -21,7 +21,7 @@ class CompareSourceCommandDiXmlTest extends AbstractTestCase * @param string $pathToSourceCodeAfter * @param string[] $expectedLogEntries * @param string $expectedOutput - * @param string[] $unexpectedLogEntries + * @param bool $shouldSkipTest * @return void * @throws \Exception * @dataProvider changesDataProvider @@ -31,14 +31,14 @@ public function testExecute( $pathToSourceCodeAfter, $expectedLogEntries, $expectedOutput, - $unexpectedLogEntries = [] + $shouldSkipTest = false ) { $this->doTestExecute( $pathToSourceCodeBefore, $pathToSourceCodeAfter, $expectedLogEntries, $expectedOutput, - $unexpectedLogEntries + $shouldSkipTest ); } @@ -51,7 +51,7 @@ public function changesDataProvider() $pathToFixtures . '/no-change/source-code-before', $pathToFixtures . '/no-change/source-code-after', [ - + '#Suggested semantic versioning change: NONE#', ], '' ], @@ -59,7 +59,7 @@ public function changesDataProvider() $pathToFixtures . '/moved-to-global/source-code-before', $pathToFixtures . '/moved-to-global/source-code-after', [ - 'Suggested semantic versioning change: NONE', + '#Suggested semantic versioning change: NONE#', ], 'Patch change is detected.', ], @@ -67,7 +67,9 @@ public function changesDataProvider() $pathToFixtures . '/moved-to-specific/source-code-before', $pathToFixtures . '/moved-to-specific/source-code-after', [ - 'Suggested semantic versioning change: MAJOR', + '#Suggested semantic versioning change: MAJOR#', + '#MAJOR\s*\|\s' . '[\w/]+' . '/moved-to-specific/source-code-before/Magento/TestModule/etc/di\.xml:0#', + '#scope\s*\|\s*Virtual Type was changed\s*\|\s*M201#' ], 'Major change is detected.', ], @@ -75,7 +77,9 @@ public function changesDataProvider() $pathToFixtures . '/remove-type/source-code-before', $pathToFixtures . '/remove-type/source-code-after', [ - 'Suggested semantic versioning change: MAJOR', + '#Suggested semantic versioning change: MAJOR#', + '#MAJOR\s*\|\s' . '[\w/]+' . 'remove-type/source-code-before/Magento/TestModule/etc/di\.xml:0#', + '#customCacheInstance2\s*\|\s*Virtual Type was removed\s*\|\s*M200\s*#' ], 'Major change is detected.', ], @@ -83,15 +87,19 @@ public function changesDataProvider() $pathToFixtures . '/change-type/source-code-before', $pathToFixtures . '/change-type/source-code-after', [ - 'Suggested semantic versioning change: MAJOR', + '#Suggested semantic versioning change: MAJOR#', + '#MAJOR\s*\|\s' . '[\w/]+' . '/change-type/source-code-before/Magento/TestModule/etc/di\.xml:0#', + '#type\s*\|\s*Virtual Type was changed\s*\|\s*M201#' ], 'Major change is detected.', ], 'change-name' => [ - $pathToFixtures . '/change-type/source-code-before', - $pathToFixtures . '/change-type/source-code-after', + $pathToFixtures . '/change-name/source-code-before', + $pathToFixtures . '/change-name/source-code-after', [ - 'Suggested semantic versioning change: MAJOR', + '#Suggested semantic versioning change: MAJOR#', + '#MAJOR\s*\|\s*' . '[\w/]+' . '/change-name/source-code-before/Magento/TestModule/etc/di\.xml:0#', + '#cacheInstance\s*\|\s*Virtual Type was removed\s*\|\s*M200#' ], 'Major change is detected.', ], diff --git a/tests/Unit/Console/Command/CompareSourceCommandLayoutTest.php b/tests/Unit/Console/Command/CompareSourceCommandLayoutTest.php index 6bb0b966..814b4a51 100644 --- a/tests/Unit/Console/Command/CompareSourceCommandLayoutTest.php +++ b/tests/Unit/Console/Command/CompareSourceCommandLayoutTest.php @@ -7,12 +7,12 @@ namespace Magento\SemanticVersionChecker\Test\Unit\Console\Command; -use Magento\SemanticVersionChecker\Test\Unit\Console\Command\CompareSourceCommandTest\AbstractTestCase; +use Magento\SemanticVersionChecker\Test\Unit\Console\Command\CompareSourceCommandTest\AbstractTestCaseWithRegExp; /** * Test semantic version checker CLI command dealing with layout xml. */ -class CompareSourceCommandLayoutTest extends AbstractTestCase +class CompareSourceCommandLayoutTest extends AbstractTestCaseWithRegExp { /** * Test semantic version checker CLI command for changes of the database schema. @@ -21,7 +21,7 @@ class CompareSourceCommandLayoutTest extends AbstractTestCase * @param string $pathToSourceCodeAfter * @param string[] $expectedLogEntries * @param string $expectedOutput - * @param string[] $unexpectedLogEntries + * @param bool $shouldSkipTest * @return void * @throws \Exception * @dataProvider changesDataProvider @@ -31,27 +31,30 @@ public function testExecute( $pathToSourceCodeAfter, $expectedLogEntries, $expectedOutput, - $unexpectedLogEntries = [] + $shouldSkipTest = false ) { $this->doTestExecute( $pathToSourceCodeBefore, $pathToSourceCodeAfter, $expectedLogEntries, $expectedOutput, - $unexpectedLogEntries + $shouldSkipTest ); } public function changesDataProvider() { $pathToFixtures = __DIR__ . '/CompareSourceCommandTest/_files/layout_xml'; + getcwd(); return [ 'block_remove' => [ $pathToFixtures . '/block_remove/source-code-before', $pathToFixtures . '/block_remove/source-code-after', [ - 'Suggested semantic versioning change: MAJOR', + '#Suggested semantic versioning change: MAJOR#', + '#MAJOR\s*\|\s' . '[\w/]+' . '/block_remove/source-code-before/Magento/Customer/view/adminhtml/layout/customer_index_viewwishlist\.xml:0#', + '#admin\.customer\.view\.wishlist\s*\|\s*Block was removed\s*\|\s*M220#' ], 'Major change is detected.', ], @@ -59,7 +62,9 @@ public function changesDataProvider() $pathToFixtures . '/container_remove/source-code-before', $pathToFixtures . '/container_remove/source-code-after', [ - 'Suggested semantic versioning change: MAJOR', + '#Suggested semantic versioning change: MAJOR#', + '#MAJOR\s*\|\s*' . '[\w/]+' . '/container_remove/source-code-before/Magento/Customer/view/adminhtml/layout/customer_index_viewwishlist\.xml:0#', + '#root\s*\|\s*Container was removed\s*\|\s*M221#' ], 'Major change is detected.', ], @@ -67,7 +72,9 @@ public function changesDataProvider() $pathToFixtures . '/update_remove/source-code-before', $pathToFixtures . '/update_remove/source-code-after', [ - 'Suggested semantic versioning change: MAJOR', + '#Suggested semantic versioning change: MAJOR#', + '#MAJOR\s*\|\s*' . '[\w/]+' . '/update_remove/source-code-before/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_configurable\.xml:0#', + '#catalog_product_superconfig_config\s*\|\s*An Update was removed\s*\|\s*M222#' ], 'Major change is detected.', ], diff --git a/tests/Unit/Console/Command/CompareSourceCommandMftfTest.php b/tests/Unit/Console/Command/CompareSourceCommandMftfTest.php index ebb1b3c4..5728d283 100644 --- a/tests/Unit/Console/Command/CompareSourceCommandMftfTest.php +++ b/tests/Unit/Console/Command/CompareSourceCommandMftfTest.php @@ -89,6 +89,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-removed/source-code-after', [ 'Mftf (MAJOR)', + 'actionGroup-removed/source-code-before/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup1 | was removed | M200' ], 'Major change is detected.' @@ -98,6 +99,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-added/source-code-after', [ 'Mftf (MINOR)', + 'actionGroup-added/source-code-after/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup2 | was added | M225' ], 'Minor change is detected.' @@ -107,6 +109,7 @@ public function changesDataProvider() $pathToFixtures . '/new-module-actionGroup-added/source-code-after', [ 'Mftf (MINOR)', + 'new-module-actionGroup-added/source-code-after/Magento/TestModuleTwo/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup2 | was added | M225' ], 'Minor change is detected.' @@ -116,6 +119,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-argument-changed/source-code-after', [ 'Mftf (MAJOR)', + 'actionGroup-argument-changed/source-code-before/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup1/arg1/type | was changed | M203' ], 'Major change is detected.' @@ -125,6 +129,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-argument-removed/source-code-after', [ 'Mftf (MAJOR)', + 'actionGroup-argument-removed/source-code-before/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup1/Arguments/arg1 | was removed | M201' ], 'Major change is detected.' @@ -134,6 +139,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-argument-added/source-code-after', [ 'Mftf (MAJOR)', + 'actionGroup-argument-added/source-code-before/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup1/arg2 | was added | M227' ], 'Major change is detected.' @@ -143,6 +149,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-action-changed/source-code-after', [ 'Mftf (PATCH)', + 'actionGroup-action-changed/source-code-before/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup1/action1/userInput | was changed | M204' ], 'Patch change is detected.' @@ -152,6 +159,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-action-type-changed/source-code-after', [ 'Mftf (PATCH)', + 'actionGroup-action-type-changed/source-code-before/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup1/action1 | type was changed | M223' ], 'Patch change is detected.' @@ -161,6 +169,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-action-removed/source-code-after', [ 'Mftf (MAJOR)', + 'actionGroup-action-removed/source-code-before/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup1/action2 | was removed | M202' ], 'Major change is detected.' @@ -170,6 +179,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-action-added/source-code-after', [ 'Mftf (MINOR)', + 'actionGroup-action-added/source-code-before/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup1/action3 | was added | M226' ], 'Minor change is detected.' @@ -179,6 +189,7 @@ public function changesDataProvider() $pathToFixtures . '/data-removed/source-code-after', [ 'Mftf (MAJOR)', + 'data-removed/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Data/DataEntity1 | Entity was removed | M205' ], 'Major change is detected.' @@ -188,6 +199,7 @@ public function changesDataProvider() $pathToFixtures . '/data-added/source-code-after', [ 'Mftf (MINOR)', + 'data-added/source-code-after/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Data/DataEntity2 | was added | M228' ], 'Minor change is detected.' @@ -197,6 +209,7 @@ public function changesDataProvider() $pathToFixtures . '/new-module-data-added/source-code-after', [ 'Mftf (MINOR)', + 'new-module-data-added/source-code-after/Magento/TestModuleTwo/Test/Mftf/Data/data.xml:0', 'Data/DataEntity2 | was added | M228' ], 'Minor change is detected.' @@ -206,6 +219,7 @@ public function changesDataProvider() $pathToFixtures . '/data-array-removed/source-code-after', [ 'Mftf (MAJOR)', + 'data-array-removed/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Data/DataEntity1/arraykey | Entity element was removed | M206' ], 'Major change is detected.' @@ -215,6 +229,7 @@ public function changesDataProvider() $pathToFixtures . '/data-array-added/source-code-after', [ 'Mftf (MINOR)', + 'data-array-added/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Data/DataEntity1/arraykeynew | was added | M229' ], 'Minor change is detected.' @@ -224,6 +239,7 @@ public function changesDataProvider() $pathToFixtures . '/data-array-item-removed/source-code-after', [ 'Mftf (MINOR)', + 'data-array-item-removed/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Data/DataEntity1/arraykey/(tre) | Entity element was removed | M207' ], 'Minor change is detected.' @@ -233,6 +249,7 @@ public function changesDataProvider() $pathToFixtures . '/data-field-removed/source-code-after', [ 'Mftf (MAJOR)', + 'data-field-removed/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Data/DataEntity1/datakey | Entity element was removed | M208' ], 'Major change is detected.' @@ -242,6 +259,7 @@ public function changesDataProvider() $pathToFixtures . '/data-field-added/source-code-after', [ 'Mftf (MINOR)', + 'data-field-added/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Data/DataEntity1/datakeynew | Entity element was added | M230' ], 'Minor change is detected.' @@ -251,6 +269,7 @@ public function changesDataProvider() $pathToFixtures . '/data-reqentity-removed/source-code-after', [ 'Mftf (MAJOR)', + 'data-reqentity-removed/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Data/DataEntity1/reqentity | Entity element was removed | M209' ], 'Major change is detected.' @@ -259,6 +278,7 @@ public function changesDataProvider() $pathToFixtures . '/data-reqentity-added/source-code-before', $pathToFixtures . '/data-reqentity-added/source-code-after', [ + 'data-reqentity-added/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Mftf (PATCH)', 'Data/DataEntity1/reqnew | element was added | M231' ], @@ -268,6 +288,7 @@ public function changesDataProvider() $pathToFixtures . '/data-var-removed/source-code-before', $pathToFixtures . '/data-var-removed/source-code-after', [ + 'data-var-removed/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Mftf (MAJOR)', 'Data/DataEntity1/var1 | Entity element was removed | M210' ], @@ -278,6 +299,7 @@ public function changesDataProvider() $pathToFixtures . '/data-var-added/source-code-after', [ 'Mftf (MINOR)', + 'data-var-added/source-code-before/Magento/TestModule/Test/Mftf/Data/data.xml:0', 'Data/DataEntity1/var2 | element was added | M232' ], 'Minor change is detected.' @@ -286,6 +308,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-removed/source-code-before', $pathToFixtures . '/metadata-removed/source-code-after', [ + 'metadata-removed/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Mftf (MAJOR)', 'Metadata/createEntity | was removed | M211' ], @@ -296,6 +319,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-added/source-code-after', [ 'Mftf (MINOR)', + 'metadata-added/source-code-after/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Metadata/createEntity2 | was added | M240' ], 'Minor change is detected.' @@ -305,6 +329,7 @@ public function changesDataProvider() $pathToFixtures . '/new-module-metadata-added/source-code-after', [ 'Mftf (MINOR)', + 'new-module-metadata-added/source-code-after/Magento/TestModuleTwo/Test/Mftf/Metadata/meta.xml:0', 'Metadata/createEntity2 | was added | M240' ], 'Minor change is detected.' @@ -314,6 +339,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-datatype-changed/source-code-after', [ 'Mftf (MINOR)', + 'metadata-datatype-changed/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Metadata/createEntity/dataType | was changed | M241' ], 'Minor change is detected.' @@ -322,6 +348,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-type-changed/source-code-before', $pathToFixtures . '/metadata-type-changed/source-code-after', [ + 'metadata-type-changed/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Mftf (MINOR)', 'Metadata/createEntity/type | was changed | M241' ], @@ -331,6 +358,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-auth-changed/source-code-before', $pathToFixtures . '/metadata-auth-changed/source-code-after', [ + 'metadata-auth-changed/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Mftf (MINOR)', 'Metadata/createEntity/auth | was changed | M241' ], @@ -340,6 +368,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-url-changed/source-code-before', $pathToFixtures . '/metadata-url-changed/source-code-after', [ + 'metadata-url-changed/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Mftf (MINOR)', 'Metadata/createEntity/url | was changed | M241' ], @@ -350,6 +379,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-method-changed/source-code-after', [ 'Mftf (MINOR)', + 'metadata-method-changed/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Metadata/createEntity/method | was changed | M241' ], 'Minor change is detected.' @@ -358,6 +388,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-top-level-child-removed/source-code-before', $pathToFixtures . '/metadata-top-level-child-removed/source-code-after', [ + 'metadata-top-level-child-removed/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Mftf (MAJOR)', 'Metadata/createEntity/toplevelField | child element was removed | M212' ], @@ -368,6 +399,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-top-level-child-added/source-code-after', [ 'Mftf (MINOR)', + 'metadata-top-level-child-added/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Metadata/createEntity/toplevelField | child element was added | M242' ], 'Minor change is detected.' @@ -377,6 +409,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-bottom-level-child-removed/source-code-after', [ 'Mftf (MAJOR)', + 'metadata-bottom-level-child-removed/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Metadata/createEntity/toplevelObj/childField | child element was removed | M212' ], 'Major change is detected.' @@ -386,6 +419,7 @@ public function changesDataProvider() $pathToFixtures . '/metadata-bottom-level-child-added/source-code-after', [ 'Mftf (MINOR)', + 'metadata-bottom-level-child-added/source-code-before/Magento/TestModule/Test/Mftf/Metadata/meta.xml:0', 'Metadata/createEntity/toplevelObj/childField | child element was added | M242' ], 'Minor change is detected.' @@ -395,6 +429,7 @@ public function changesDataProvider() $pathToFixtures . '/page-removed/source-code-after', [ 'Mftf (MAJOR)', + 'page-removed/source-code-before/Magento/TestModule/Test/Mftf/Page/page.xml:0', 'Page/SamplePage | was removed | M213' ], 'Major change is detected.' @@ -403,6 +438,7 @@ public function changesDataProvider() $pathToFixtures . '/page-added/source-code-before', $pathToFixtures . '/page-added/source-code-after', [ + 'page-added/source-code-after/Magento/TestModule/Test/Mftf/Page/page.xml:0', 'Mftf (MINOR)', 'Page/SamplePageNew | was added | M233' ], @@ -412,6 +448,7 @@ public function changesDataProvider() $pathToFixtures . '/new-module-page-added/source-code-before', $pathToFixtures . '/new-module-page-added/source-code-after', [ + 'new-module-page-added/source-code-after/Magento/TestModuleTwo/Test/Mftf/Page/page.xml:0', 'Mftf (MINOR)', 'Page/SamplePageNew | was added | M233' ], @@ -422,6 +459,7 @@ public function changesDataProvider() $pathToFixtures . '/page-section-removed/source-code-after', [ 'Mftf (MAJOR)', + 'page-section-removed/source-code-before/Magento/TestModule/Test/Mftf/Page/page.xml:0', 'Page/SamplePage/Section2 |
was removed | M214' ], 'Major change is detected.' @@ -431,6 +469,7 @@ public function changesDataProvider() $pathToFixtures . '/page-section-added/source-code-after', [ 'Mftf (MINOR)', + 'page-section-added/source-code-before/Magento/TestModule/Test/Mftf/Page/page.xml:0', 'Page/SamplePage/SectionNew |
was added | M234' ], 'Minor change is detected.' @@ -439,6 +478,7 @@ public function changesDataProvider() $pathToFixtures . '/section-removed/source-code-before', $pathToFixtures . '/section-removed/source-code-after', [ + 'section-removed/source-code-before/Magento/TestModule/Test/Mftf/Section/section.xml:0', 'Mftf (MAJOR)', 'Section/SampleSection |
was removed | M215' ], @@ -449,6 +489,7 @@ public function changesDataProvider() $pathToFixtures . '/section-added/source-code-after', [ 'Mftf (MINOR)', + 'section-added/source-code-after/Magento/TestModule/Test/Mftf/Section/section.xml:0', 'Section/NewSection |
was added | M235' ], 'Minor change is detected.' @@ -458,6 +499,7 @@ public function changesDataProvider() $pathToFixtures . '/new-module-section-added/source-code-after', [ 'Mftf (MINOR)', + 'new-module-section-added/source-code-after/Magento/TestModuleTwo/Test/Mftf/Section/section.xml:0', 'Section/NewSection |
was added | M235' ], 'Minor change is detected.' @@ -467,6 +509,7 @@ public function changesDataProvider() $pathToFixtures . '/section-element-removed/source-code-after', [ 'Mftf (MAJOR)', + 'section-element-removed/source-code-before/Magento/TestModule/Test/Mftf/Section/section.xml:0', 'Section/SampleSection/element2 |
was removed | M216' ], 'Major change is detected.' @@ -476,6 +519,7 @@ public function changesDataProvider() $pathToFixtures . '/section-element-selector-changed/source-code-after', [ 'Mftf (PATCH)', + 'section-element-selector-changed/source-code-before/Magento/TestModule/Test/Mftf/Section/section.xml:0', 'Section/SampleSection/element1/selector |
selector was changed | M219' ], 'Patch change is detected.' @@ -485,6 +529,7 @@ public function changesDataProvider() $pathToFixtures . '/section-element-type-changed/source-code-after', [ 'Mftf (PATCH)', + 'section-element-type-changed/source-code-before/Magento/TestModule/Test/Mftf/Section/section.xml:0', 'Section/SampleSection/element1/type |
type was changed | M218' ], 'Patch change is detected.' @@ -493,6 +538,7 @@ public function changesDataProvider() $pathToFixtures . '/section-element-parameterized-added/source-code-before', $pathToFixtures . '/section-element-parameterized-added/source-code-after', [ + 'section-element-parameterized-added/source-code-before/Magento/TestModule/Test/Mftf/Section/section.xml:0', 'Mftf (MAJOR)', 'Section/SampleSection/element1/parameterized |
parameterized was changed | M250' ], @@ -503,6 +549,7 @@ public function changesDataProvider() $pathToFixtures . '/section-element-parameterized-removed/source-code-after', [ 'Mftf (MAJOR)', + 'section-element-parameterized-removed/source-code-before/Magento/TestModule/Test/Mftf/Section/section.xml:0', 'Section/SampleSection/element1/parameterized |
parameterized was changed | M250' ], 'Major change is detected.' @@ -512,6 +559,7 @@ public function changesDataProvider() $pathToFixtures . '/section-element-added/source-code-after', [ 'Mftf (MINOR)', + 'section-element-added/source-code-before/Magento/TestModule/Test/Mftf/Section/section.xml:0', 'Section/SampleSection/newElement |
was added | M236' ], 'Minor change is detected.' @@ -521,6 +569,7 @@ public function changesDataProvider() $pathToFixtures . '/test-removed/source-code-after', [ 'Mftf (MAJOR)', + 'test-removed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest | was removed | M218' ], 'Major change is detected.' @@ -530,6 +579,7 @@ public function changesDataProvider() $pathToFixtures . '/test-added/source-code-after', [ 'Mftf (MINOR)', + 'test-added/source-code-after/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/NewTest | was added | M237' ], 'Minor change is detected.' @@ -539,6 +589,7 @@ public function changesDataProvider() $pathToFixtures . '/new-module-test-added/source-code-after', [ 'Mftf (MINOR)', + 'new-module-test-added/source-code-after/Magento/TestModuleTwo/Test/Mftf/Test/test.xml:0', 'Test/NewTest | was added | M237' ], 'Minor change is detected.' @@ -548,6 +599,7 @@ public function changesDataProvider() $pathToFixtures . '/test-action-changed/source-code-after', [ 'Mftf (PATCH)', + 'test-action-changed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/key1/userInput | was changed | M222' ], 'Patch change is detected.' @@ -557,6 +609,7 @@ public function changesDataProvider() $pathToFixtures . '/test-action-sequence-changed/source-code-after', [ 'Mftf (MAJOR)', + 'test-action-sequence-changed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest | sequence was changed | M223' ], 'Major change is detected.' @@ -566,6 +619,7 @@ public function changesDataProvider() $pathToFixtures . '/test-action-type-changed/source-code-after', [ 'Mftf (PATCH)', + 'test-action-type-changed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/action1 | type was changed | M224' ], 'Patch change is detected.' @@ -575,6 +629,7 @@ public function changesDataProvider() $pathToFixtures . '/test-action-removed/source-code-after', [ 'Mftf (MAJOR)', + 'test-action-removed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/key2 | was removed | M219' ], 'Major change is detected.' @@ -584,6 +639,7 @@ public function changesDataProvider() $pathToFixtures . '/test-action-added/source-code-after', [ 'Mftf (MINOR)', + 'test-action-added/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/newAction | was added | M238' ], 'Minor change is detected.' @@ -593,6 +649,7 @@ public function changesDataProvider() $pathToFixtures . '/test-before-action-removed/source-code-after', [ 'Mftf (MAJOR)', + 'test-before-action-removed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/before/key1 | was removed | M219' ], 'Major change is detected.' @@ -602,6 +659,7 @@ public function changesDataProvider() $pathToFixtures . '/test-before-action-added/source-code-after', [ 'Mftf (MINOR)', + 'test-before-action-added/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/before/newAction | was added | M238' ], 'Minor change is detected.' @@ -611,6 +669,7 @@ public function changesDataProvider() $pathToFixtures . '/test-before-action-sequence-changed/source-code-after', [ 'Mftf (MAJOR)', + 'test-before-action-sequence-changed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/before | sequence was changed | M223' ], 'Major change is detected.' @@ -619,6 +678,7 @@ public function changesDataProvider() $pathToFixtures . '/test-after-action-removed/source-code-before', $pathToFixtures . '/test-after-action-removed/source-code-after', [ + 'test-after-action-removed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Mftf (MAJOR)', 'Test/SampleTest/after/key1 | was removed | M219' ], @@ -629,6 +689,7 @@ public function changesDataProvider() $pathToFixtures . '/test-after-action-added/source-code-after', [ 'Mftf (MINOR)', + 'test-after-action-added/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/after/newAction | was added | M238' ], 'Minor change is detected.' @@ -638,6 +699,7 @@ public function changesDataProvider() $pathToFixtures . '/test-after-action-sequence-changed/source-code-after', [ 'Mftf (MAJOR)', + 'test-after-action-sequence-changed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/after | sequence was changed | M223' ], 'Major change is detected.' @@ -647,6 +709,7 @@ public function changesDataProvider() $pathToFixtures . '/test-annotation-changed/source-code-after', [ 'Mftf (PATCH)', + 'test-annotation-changed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/annotations/{}description | was removed or changed | M221' ], 'Patch change is detected.' @@ -656,6 +719,7 @@ public function changesDataProvider() $pathToFixtures . '/test-group-removed/source-code-after', [ 'Mftf (MAJOR)', + 'test-group-removed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/annotations/{}group(sampleGroup) | was removed | M220' ], 'Major change is detected.' @@ -665,6 +729,7 @@ public function changesDataProvider() $pathToFixtures . '/test-remove-action-added/source-code-after', [ 'Mftf (MAJOR)', + 'test-remove-action-added/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/newRemoveAction | was added | M401' ], 'Major change is detected.' @@ -674,6 +739,7 @@ public function changesDataProvider() $pathToFixtures . '/test-remove-action-removed/source-code-after', [ 'Mftf (MAJOR)', + 'test-remove-action-removed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/key2 | was removed | M402' ], 'Major change is detected.' @@ -683,6 +749,7 @@ public function changesDataProvider() $pathToFixtures . '/test-action-group-ref-changed/source-code-after', [ 'Mftf (MINOR)', + 'test-action-group-ref-changed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/key2/ref | ref was changed | M241' ], 'Minor change is detected.' @@ -692,6 +759,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-added/source-code-after', [ 'Mftf (MINOR)', + 'suite-added/source-code-after/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/Sample2Suite | was added | M407' ], 'Minor change is detected.' @@ -701,6 +769,7 @@ public function changesDataProvider() $pathToFixtures . '/new-module-suite-added/source-code-after', [ 'Mftf (MINOR)', + 'new-module-suite-added/source-code-after/Magento/TestModuleTwo/Test/Mftf/Suite/suite.xml:0', 'Suite/Sample2Suite | was added | M407' ], 'Minor change is detected.' @@ -710,6 +779,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-removed/source-code-after', [ 'Mftf (MAJOR)', + 'suite-removed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/Sample2Suite | was removed | M408' ], 'Major change is detected.' @@ -719,6 +789,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-after-action-added/source-code-after', [ 'Mftf (MINOR)', + 'suite-after-action-added/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/after/y | was added | M415' ], 'Minor change is detected.' @@ -728,6 +799,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-after-action-changed/source-code-after', [ 'Mftf (PATCH)', + 'suite-after-action-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/after/x/url | was changed | M416' ], 'Patch change is detected.' @@ -737,6 +809,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-after-action-removed/source-code-after', [ 'Mftf (MAJOR)', + 'suite-after-action-removed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/after/y | was removed | M412' ], 'Major change is detected.' @@ -746,6 +819,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-after-action-group-ref-changed/source-code-after', [ 'Mftf (MINOR)', + 'suite-after-action-group-ref-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/after/z/ref | ref was changed | M417' ], 'Minor change is detected.' @@ -755,6 +829,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-after-action-sequence-changed/source-code-after', [ 'Mftf (MAJOR)', + 'suite-after-action-sequence-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/after | sequence was changed | M418' ], 'Major change is detected.' @@ -764,6 +839,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-after-action-type-changed/source-code-after', [ 'Mftf (PATCH)', + 'suite-after-action-type-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/after/y | type was changed | M419' ], 'Patch change is detected.' @@ -773,6 +849,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-before-action-added/source-code-after', [ 'Mftf (MINOR)', + 'suite-before-action-added/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/before/b | was added | M415' ], 'Minor change is detected.' @@ -782,6 +859,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-before-action-changed/source-code-after', [ 'Mftf (PATCH)', + 'suite-before-action-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/before/b/userInput | was changed | M416' ], 'Patch change is detected.' @@ -791,6 +869,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-before-action-removed/source-code-after', [ 'Mftf (MAJOR)', + 'suite-before-action-removed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/before/b | was removed | M412' ], 'Major change is detected.' @@ -800,6 +879,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-before-action-group-ref-changed/source-code-after', [ 'Mftf (MINOR)', + 'suite-before-action-group-ref-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/before/c/ref | ref was changed | M417' ], 'Minor change is detected.' @@ -809,6 +889,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-before-action-sequence-changed/source-code-after', [ 'Mftf (MAJOR)', + 'suite-before-action-sequence-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/before | sequence was changed | M418' ], 'Major change is detected.' @@ -818,6 +899,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-before-action-type-changed/source-code-after', [ 'Mftf (PATCH)', + 'suite-before-action-type-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/before/b | type was changed | M419' ], 'Patch change is detected.' @@ -827,6 +909,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-exclude-added/source-code-after', [ 'Mftf (PATCH)', + 'suite-exclude-added/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/exclude/module1 | was added | M409', 'Suite/SampleSuite/exclude/test1 | was added | M409', ], @@ -837,6 +920,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-exclude-removed/source-code-after', [ 'Mftf (PATCH)', + 'suite-exclude-removed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/exclude/module1 | was removed | M410' ], 'Patch change is detected.' @@ -846,6 +930,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-include-added/source-code-after', [ 'Mftf (PATCH)', + 'suite-include-added/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/include/module1 | was added | M409', 'Suite/SampleSuite/include/test1 | was added | M409', ], @@ -856,6 +941,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-include-removed/source-code-after', [ 'Mftf (PATCH)', + 'suite-include-removed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/include/module1 | was removed | M410' ], 'Patch change is detected.' @@ -865,6 +951,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-include-changed/source-code-after', [ 'Mftf (PATCH)', + 'suite-include-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/include/group1 | was removed | M410', 'Suite/SampleSuite/include/group2 | was added | M409', ], @@ -875,6 +962,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-exclude-changed/source-code-after', [ 'Mftf (PATCH)', + 'suite-exclude-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/exclude/group1 | was removed | M410', 'Suite/SampleSuite/exclude/group2 | was added | M409', ], @@ -885,6 +973,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-after-remove-action-added/source-code-after', [ 'Mftf (MAJOR)', + 'suite-after-remove-action-added/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/after/x | was added | M420' ], 'Major change is detected.' @@ -894,6 +983,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-after-remove-action-removed/source-code-after', [ 'Mftf (MAJOR)', + 'suite-after-remove-action-removed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/after/x | was removed | M421' ], 'Major change is detected.' @@ -903,6 +993,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-before-remove-action-added/source-code-after', [ 'Mftf (MAJOR)', + 'suite-before-remove-action-added/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/before/x | was added | M420' ], 'Major change is detected.' @@ -912,6 +1003,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-before-remove-action-removed/source-code-after', [ 'Mftf (MAJOR)', + 'suite-before-remove-action-removed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/before/x | was removed | M421' ], 'Major change is detected.' @@ -921,6 +1013,7 @@ public function changesDataProvider() $pathToFixtures . '/actionGroup-remove-action-key-changed/source-code-after', [ 'Mftf (MAJOR)', + 'actionGroup-remove-action-key-changed/source-code-before/Magento/TestModule/Test/Mftf/ActionGroup/actionGroup.xml:0', 'ActionGroup/ActionGroup1/action2 | was removed | M406', 'ActionGroup/ActionGroup1/action1 | was added | M404', ], @@ -931,6 +1024,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-before-remove-action-key-changed/source-code-after', [ 'Mftf (MAJOR)', + 'suite-before-remove-action-key-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/before/a | was removed | M421', 'Suite/SampleSuite/before/b | was added | M420', ], @@ -941,6 +1035,7 @@ public function changesDataProvider() $pathToFixtures . '/suite-after-remove-action-key-changed/source-code-after', [ 'Mftf (MAJOR)', + ' suite-after-remove-action-key-changed/source-code-before/Magento/TestModule/Test/Mftf/Suite/suite.xml:0', 'Suite/SampleSuite/after/a | was removed | M421', 'Suite/SampleSuite/after/b | was added | M420', ], @@ -951,6 +1046,7 @@ public function changesDataProvider() $pathToFixtures . '/test-remove-action-key-changed/source-code-after', [ 'Mftf (MAJOR)', + 'test-remove-action-key-changed/source-code-before/Magento/TestModule/Test/Mftf/Test/test.xml:0', 'Test/SampleTest/key2 | was removed | M402', 'Test/SampleTest/key1 | was added | M401', ], diff --git a/tests/Unit/Console/Command/CompareSourceCommandSystemXmlTest.php b/tests/Unit/Console/Command/CompareSourceCommandSystemXmlTest.php index bfda69f7..72170c1b 100644 --- a/tests/Unit/Console/Command/CompareSourceCommandSystemXmlTest.php +++ b/tests/Unit/Console/Command/CompareSourceCommandSystemXmlTest.php @@ -60,7 +60,7 @@ public function changesDataProvider() $pathToFixtures . '/file-added/source-code-after', [ 'Suggested semantic versioning change: MINOR', - 'Magento_TestModule:0 | system.xml | System configuration file was added | M300', + 'Magento/TestModule/etc/adminhtml/system.xml:0 | system.xml | System configuration file was added | M300', ], 'Minor change is detected.', ], @@ -69,7 +69,7 @@ public function changesDataProvider() $pathToFixtures . '/file-removed/source-code-after', [ 'Suggested semantic versioning change: MAJOR', - 'Magento_TestModule:0 | system.xml | System configuration file was added | M301', + 'Magento/TestModule/etc/adminhtml/system.xml:0 | system.xml | System configuration file was added | M301', ], 'Major change is detected.', ], @@ -78,7 +78,7 @@ public function changesDataProvider() $pathToFixtures . '/section-added/source-code-after', [ 'Suggested semantic versioning change: MINOR', - 'Magento_TestModule:0 | added_section | A section-node was added | M306', + 'Magento/TestModule/etc/adminhtml/system.xml:0 | added_section | A section-node was added | M306', ], 'Minor change is detected.', ], @@ -87,7 +87,7 @@ public function changesDataProvider() $pathToFixtures . '/section-removed/source-code-after', [ 'Suggested semantic versioning change: MAJOR', - 'Magento_TestModule:0 | removed_section | a section-node was removed | MM307', + 'Magento/TestModule/etc/adminhtml/system.xml:0 | removed_section | a section-node was removed | MM307', ], 'Major change is detected.', ], @@ -96,7 +96,7 @@ public function changesDataProvider() $pathToFixtures . '/group-added/source-code-after', [ 'Suggested semantic versioning change: MINOR', - 'Magento_TestModule:0 | magento_testmodule/added_group | A group-node was added | M304', + 'Magento/TestModule/etc/adminhtml/system.xml:0 | magento_testmodule/added_group | A group-node was added | M304', ], 'Minor change is detected.', ], @@ -105,7 +105,7 @@ public function changesDataProvider() $pathToFixtures . '/group-removed/source-code-after', [ 'Suggested semantic versioning change: MAJOR', - 'Magento_TestModule:0 | magento_testmodule/removed_group | A group-node was removed | M305', + 'Magento/TestModule/etc/adminhtml/system.xml:0 | magento_testmodule/removed_group | A group-node was removed | M305', ], 'Major change is detected.', ], @@ -114,7 +114,7 @@ public function changesDataProvider() $pathToFixtures . '/field-added/source-code-after', [ 'Suggested semantic versioning change: MINOR', - 'Magento_TestModule:0 | magento_testmodule/general/added_field | A field-node was added | M302', + 'Magento/TestModule/etc/adminhtml/system.xml:0 | magento_testmodule/general/added_field | A field-node was added | M302', ], 'Minor change is detected.', ], @@ -123,7 +123,7 @@ public function changesDataProvider() $pathToFixtures . '/field-removed/source-code-after', [ 'Suggested semantic versioning change: MAJOR', - 'Magento_TestModule:0 | magento_testmodule/general/removed_field | A field-node was removed | M303', + 'Magento/TestModule/etc/adminhtml/system.xml:0 | magento_testmodule/general/removed_field | A field-node was removed | M303', ], 'Major change is detected.', ], diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/AbstractHtmlTestCaseForHtml.php b/tests/Unit/Console/Command/CompareSourceCommandTest/AbstractHtmlTestCaseForHtml.php new file mode 100644 index 00000000..e993f148 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/AbstractHtmlTestCaseForHtml.php @@ -0,0 +1,197 @@ +command = new CompareSourceCommand(); + $this->svcLogPath = TESTS_TEMP_DIR . '/svc-' . time() . '.html'; + } + + protected function tearDown() + { + parent::tearDown(); + unlink($this->svcLogPath); + } + + /** + * Executes the command that shall be tested and performs assertions. + * + * 1. Run semantic version checker command to compare 2 source code directories + * 2. Assert that SVC log contains expected entries + * 3. Assert console output + * 4. Assert return code + * + * @param string $pathToSourceCodeBefore + * @param string $pathToSourceCodeAfter + * @param int $allowedChangeLevel + * @param HtmlParseInfoContainer[] $expectedHtmlEntries + * @param array $expectedPackageSection + * @param string $expectedOutput + * @param $expectedStatusCode + * @param $reportTypes + * @param bool $shouldSkipTest + * @throws Exception + */ + protected function doTestExecute( + string $pathToSourceCodeBefore, + string $pathToSourceCodeAfter, + int $allowedChangeLevel, + array $expectedHtmlEntries, + array $expectedPackageSection, + string $expectedOutput, + int $expectedStatusCode, + array $reportTypes, + bool $shouldSkipTest + ): void { + try { + $commandTester = $this->executeCommand($pathToSourceCodeBefore, $pathToSourceCodeAfter, $allowedChangeLevel, $reportTypes); + $svcDom = $this->getSvcReportDOM(); + self::assertJsonContent($expectedPackageSection, $svcDom); + foreach ($expectedHtmlEntries as $expectedHtmlEntry) { + $this->assertHtml($expectedHtmlEntry->xpath, $expectedHtmlEntry->pattern, $svcDom); + } + $this->assertContains($expectedOutput, $commandTester->getDisplay()); + $this->assertEquals($expectedStatusCode, $commandTester->getStatusCode()); + } catch (Exception $e) { + if ($shouldSkipTest) { + $this->markTestSkipped($e->getMessage()); + } else { + throw $e; + } + } + } + + /** + * Validate json in html svc document + * + * @param array $expectedJson + * @param DOMDocument $docDom + */ + private static function assertJsonContent(array $expectedJson, DOMDocument $docDom) + { + if (!$expectedJson) { + $xpathQuery = '/html/body/table/tbody/tr[last()]/td[2]'; + $pattern = '#No BIC changes found to packages#i'; + self::assertHtml($xpathQuery, $pattern, $docDom); + } else { + $docXpath = new DOMXPath($docDom); + $xpathQuery = '//*[@id="packageChangesJson"]/text()'; + static::assertHtml($xpathQuery, null, $docDom); //ensure xpath resolves + $jsonText = $docDom->saveHTML($docXpath->query($xpathQuery)->item(0)); + $encodedJson = json_decode($jsonText); + //store expectedJson in same format + $expectedJson = json_decode(json_encode($expectedJson)); + sort($expectedJson); + sort($encodedJson); + self::assertEquals($expectedJson, $encodedJson); + } + } + + /** + * Assert HTML document resolves xpath, resolves finding pattern, or resolves finding pattern within resolved xpath + * + * @param $xpathQuery + * @param $regex + * @param DOMDocument $docDom + */ + public static function assertHtml($xpathQuery, $regex, DOMDocument $docDom) + { + $docXpath = new DOMXPath($docDom); + if ($xpathQuery) { + $nodeList = $docXpath->query($xpathQuery); + if (!$nodeList || !$nodeList->length) { + $body = $docXpath->document->saveHTML(); + static::fail('xpath selector: ' . $xpathQuery . " was invalid. Unable to return result from document:\n" . $body); //throws exception + } + if ($regex) { + $body = $docDom->saveHTML($nodeList->item(0)); + static::assertRegExp($regex, $body); + } + } else { + $body = $docXpath->document->saveHTML(); + static::assertRegExp($regex, $body); + } + } + + /** + * Executes {@link CompareSourceCommandTest::$command} via {@link CommandTester}, using the arguments as command + * line parameters. + * + * The command line parameters are specified as follows: + *
    + *
  • source-before: The content of the argument $pathToSourceCodeBefore
  • + *
  • source-after: The content of the argument $pathToSourceCodeAfter
  • + *
  • --log-output-location: The content of {@link CompareSourceCommandTest::$svcLogPath}
  • + *
  • --include-patterns: The path to the file ./_files/application_includes.txt
  • + *
+ * + * @param string $pathToSourceCodeBefore + * @param string $pathToSourceCodeAfter + * @param int $allowedChangeLevel + * @param array $reportTypes + * @return CommandTester + */ + protected function executeCommand(string $pathToSourceCodeBefore, string $pathToSourceCodeAfter, int $allowedChangeLevel, array $reportTypes): CommandTester + { + $commandTester = new CommandTester($this->command); + $commandTester->execute( + [ + 'source-before' => $pathToSourceCodeBefore, + 'source-after' => $pathToSourceCodeAfter, + '--log-output-location' => $this->svcLogPath, + '--include-patterns' => __DIR__ . '/_files/application_includes.txt', + '--report-type' => $reportTypes, + 'allowed-change-level' => $allowedChangeLevel, + ] + ); + return $commandTester; + } + + /** + * Returns the contents of the file specified in {@link CompareSourceCommandTest::$svcLogPath}. + * + * @return DOMDocument + */ + private function getSvcReportDOM(): ?DOMDocument + { + $source = file_get_contents($this->svcLogPath); + if (!$source) { + return null; + } + $doc = new DOMDocument(); + $doc->loadHTML($source); + return $doc; + } +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/HtmlParseInfoContainer.php b/tests/Unit/Console/Command/CompareSourceCommandTest/HtmlParseInfoContainer.php new file mode 100644 index 00000000..9ec39b05 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/HtmlParseInfoContainer.php @@ -0,0 +1,40 @@ +xpath = $xpath; + $this->pattern = $pattern; + } +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/api-class/added-extends/TestClass.php b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/api-class/added-extends/TestClass.php new file mode 100644 index 00000000..18cafd21 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/api-class/added-extends/TestClass.php @@ -0,0 +1,14 @@ + + + + + + + + + + +
+ diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/db_schema/add-foreign-key/Magento/DbSchema/etc/db_schema_whitelist.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/db_schema/add-foreign-key/Magento/DbSchema/etc/db_schema_whitelist.json new file mode 100644 index 00000000..92a312ec --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/db_schema/add-foreign-key/Magento/DbSchema/etc/db_schema_whitelist.json @@ -0,0 +1,14 @@ +{ + "unit_test_table": { + "column": { + "id_column": true, + "severity": true, + "title": true, + "time_occurred": true + }, + "constraint": { + "PRIMARY": true, + "FL_ALLOWED_SEVERITIES": true + } + } +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/db_schema/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/db_schema/composer.json new file mode 100644 index 00000000..ae34995d --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/db_schema/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/db_schema", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/di_xml/change-name/Magento/TestModule/etc/di.xml b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/di_xml/change-name/Magento/TestModule/etc/di.xml new file mode 100644 index 00000000..e3db9aec --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/di_xml/change-name/Magento/TestModule/etc/di.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/di_xml/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/di_xml/composer.json new file mode 100644 index 00000000..6472414d --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/di_xml/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/di_xml", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/layout_xml/block_remove/Magento/Customer/view/adminhtml/layout/customer_index_viewwishlist.xml b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/layout_xml/block_remove/Magento/Customer/view/adminhtml/layout/customer_index_viewwishlist.xml new file mode 100644 index 00000000..ce6713c8 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/layout_xml/block_remove/Magento/Customer/view/adminhtml/layout/customer_index_viewwishlist.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/layout_xml/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/layout_xml/composer.json new file mode 100644 index 00000000..71466502 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/layout_xml/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/layout_xml", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/less/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/less/composer.json new file mode 100644 index 00000000..288a3893 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/less/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/less", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/less/removed-import/Magento/TestModule/view/frontend/web/css/source/test.less b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/less/removed-import/Magento/TestModule/view/frontend/web/css/source/test.less new file mode 100644 index 00000000..8ef7d114 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/less/removed-import/Magento/TestModule/view/frontend/web/css/source/test.less @@ -0,0 +1 @@ +// Exemplary import declaration diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/mftf/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/mftf/composer.json new file mode 100644 index 00000000..c704e264 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/mftf/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/mftf", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/mftf/suite-after-action-changed/Magento/TestModule/Test/Mftf/Suite/suite.xml b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/mftf/suite-after-action-changed/Magento/TestModule/Test/Mftf/Suite/suite.xml new file mode 100644 index 00000000..9cce57aa --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/mftf/suite-after-action-changed/Magento/TestModule/Test/Mftf/Suite/suite.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/system_xml/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/system_xml/composer.json new file mode 100644 index 00000000..8e67e7a7 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/system_xml/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/system_xml", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/system_xml/field_removed/Magento/TestModule/etc/adminhtml/system.xml b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/system_xml/field_removed/Magento/TestModule/etc/adminhtml/system.xml new file mode 100644 index 00000000..d1a27c17 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/system_xml/field_removed/Magento/TestModule/etc/adminhtml/system.xml @@ -0,0 +1,19 @@ + + + + +
+ + + + + +
+
+
diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/xsd-schema/attribute-removed/Magento/TestModule/etc/test-schema.xsd b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/xsd-schema/attribute-removed/Magento/TestModule/etc/test-schema.xsd new file mode 100644 index 00000000..3be917f6 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/xsd-schema/attribute-removed/Magento/TestModule/etc/test-schema.xsd @@ -0,0 +1,15 @@ + + + + + + + Type to which a required attribute is added + + + diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/xsd-schema/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/xsd-schema/composer.json new file mode 100644 index 00000000..6b984e8e --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-after/xsd-schema/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/xsd-schema", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/api-class/added-extends/TestClass.php b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/api-class/added-extends/TestClass.php new file mode 100644 index 00000000..7f9a6cf5 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/api-class/added-extends/TestClass.php @@ -0,0 +1,14 @@ + + + + + + + + + +
+ diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/db_schema/add-foreign-key/Magento/DbSchema/etc/db_schema_whitelist.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/db_schema/add-foreign-key/Magento/DbSchema/etc/db_schema_whitelist.json new file mode 100644 index 00000000..78333fb3 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/db_schema/add-foreign-key/Magento/DbSchema/etc/db_schema_whitelist.json @@ -0,0 +1,13 @@ +{ + "unit_test_table": { + "column": { + "id_column": true, + "severity": true, + "title": true, + "time_occurred": true + }, + "constraint": { + "PRIMARY": true + } + } +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/db_schema/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/db_schema/composer.json new file mode 100644 index 00000000..ae34995d --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/db_schema/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/db_schema", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/di_xml/change-name/Magento/TestModule/etc/di.xml b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/di_xml/change-name/Magento/TestModule/etc/di.xml new file mode 100644 index 00000000..f07ce18d --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/di_xml/change-name/Magento/TestModule/etc/di.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/di_xml/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/di_xml/composer.json new file mode 100644 index 00000000..6472414d --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/di_xml/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/di_xml", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/layout_xml/block_remove/Magento/Customer/view/adminhtml/layout/customer_index_viewwishlist.xml b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/layout_xml/block_remove/Magento/Customer/view/adminhtml/layout/customer_index_viewwishlist.xml new file mode 100644 index 00000000..6551657b --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/layout_xml/block_remove/Magento/Customer/view/adminhtml/layout/customer_index_viewwishlist.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/layout_xml/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/layout_xml/composer.json new file mode 100644 index 00000000..71466502 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/layout_xml/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/layout_xml", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/less/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/less/composer.json new file mode 100644 index 00000000..288a3893 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/less/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/less", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/less/removed-import/Magento/TestModule/view/frontend/web/css/source/test.less b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/less/removed-import/Magento/TestModule/view/frontend/web/css/source/test.less new file mode 100644 index 00000000..556875e4 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/less/removed-import/Magento/TestModule/view/frontend/web/css/source/test.less @@ -0,0 +1,2 @@ +// Exemplary import declaration +@import 'testimport'; diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/mftf/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/mftf/composer.json new file mode 100644 index 00000000..c704e264 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/mftf/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/mftf", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/mftf/suite-after-action-changed/Magento/TestModule/Test/Mftf/Suite/suite.xml b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/mftf/suite-after-action-changed/Magento/TestModule/Test/Mftf/Suite/suite.xml new file mode 100644 index 00000000..3fa2815d --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/mftf/suite-after-action-changed/Magento/TestModule/Test/Mftf/Suite/suite.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/system_xml/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/system_xml/composer.json new file mode 100644 index 00000000..8e67e7a7 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/system_xml/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/system_xml", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/system_xml/field_removed/Magento/TestModule/etc/adminhtml/system.xml b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/system_xml/field_removed/Magento/TestModule/etc/adminhtml/system.xml new file mode 100644 index 00000000..0182c86c --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/system_xml/field_removed/Magento/TestModule/etc/adminhtml/system.xml @@ -0,0 +1,22 @@ + + + + +
+ + + + + + + + +
+
+
diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/xsd-schema/attribute-removed/Magento/TestModule/etc/test-schema.xsd b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/xsd-schema/attribute-removed/Magento/TestModule/etc/test-schema.xsd new file mode 100644 index 00000000..fc165471 --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/xsd-schema/attribute-removed/Magento/TestModule/etc/test-schema.xsd @@ -0,0 +1,18 @@ + + + + + + + Type from which attributes are removed + + + + + + diff --git a/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/xsd-schema/composer.json b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/xsd-schema/composer.json new file mode 100644 index 00000000..6b984e8e --- /dev/null +++ b/tests/Unit/Console/Command/CompareSourceCommandTest/_files/all/source-code-before/xsd-schema/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/xsd-schema", + "description": "module composer package" +} diff --git a/tests/Unit/Console/Command/CompareSourceCommandXsdSchemasTest.php b/tests/Unit/Console/Command/CompareSourceCommandXsdSchemasTest.php index 97d67413..60e6c467 100644 --- a/tests/Unit/Console/Command/CompareSourceCommandXsdSchemasTest.php +++ b/tests/Unit/Console/Command/CompareSourceCommandXsdSchemasTest.php @@ -60,6 +60,7 @@ public function changesDataProvider() $pathToFixtures . '/optional-node-added/source-code-after', [ 'Suggested semantic versioning change: MINOR', + 'optional-node-added/source-code-after/Magento/TestModule/etc/test-schema.xsd:0', 'addedOptionalElement | An optional node was added | M0133', ], 'Minor change is detected.', @@ -69,6 +70,7 @@ public function changesDataProvider() $pathToFixtures . '/optional-attribute-added/source-code-after', [ 'Suggested semantic versioning change: MINOR', + 'optional-attribute-added/source-code-after/Magento/TestModule/etc/test-schema.xsd:0', 'optionalAttribute | An optional attribute was added | M0134', ], 'Minor change is detected.', @@ -78,6 +80,7 @@ public function changesDataProvider() $pathToFixtures . '/required-node-added/source-code-after', [ 'Suggested semantic versioning change: MAJOR', + 'required-node-added/source-code-after/Magento/TestModule/etc/test-schema.xsd:0', 'addedRequiredElement | A required node was added | M0135', ], 'Major change is detected.', @@ -87,6 +90,7 @@ public function changesDataProvider() $pathToFixtures . '/required-attribute-added/source-code-after', [ 'Suggested semantic versioning change: MAJOR', + 'required-attribute-added/source-code-after/Magento/TestModule/etc/test-schema.xsd:0', 'requiredAttribute | A required attribute was added | M0136', ], 'Major change is detected.', @@ -96,8 +100,8 @@ public function changesDataProvider() $pathToFixtures . '/node-removed/source-code-after', [ 'Suggested semantic versioning change: MAJOR', - 'requiredElement | A node was removed | M0137', - 'optionalElement | A node was removed | M0137', + 'node-removed/source-code-before/Magento/TestModule/etc/test-schema.xsd:0 | requiredElement | A node was removed | M0137', + 'node-removed/source-code-before/Magento/TestModule/etc/test-schema.xsd:0 | optionalElement | A node was removed | M0137', ], 'Major change is detected.', ], @@ -106,8 +110,8 @@ public function changesDataProvider() $pathToFixtures . '/attribute-removed/source-code-after', [ 'Suggested semantic versioning change: MAJOR', - 'requiredAttribute | An attribute was removed | M0138', - 'optionalAttribute | An attribute was removed | M0138', + 'attribute-removed/source-code-before/Magento/TestModule/etc/test-schema.xsd:0 | requiredAttribute | An attribute was removed | M0138', + 'attribute-removed/source-code-before/Magento/TestModule/etc/test-schema.xsd:0 | optionalAttribute | An attribute was removed | M0138', ], 'Major change is detected.', ], @@ -116,7 +120,8 @@ public function changesDataProvider() $pathToFixtures . '/schema-declaration-removed/source-code-after', [ 'Suggested semantic versioning change: MAJOR', - '/etc/test-schema.xsd | A schema declaration was removed | M0139', + 'schema-declaration-removed/source-code-before/Magento/TestModule/etc/test-schema.xsd:0', + '/etc/test-schema.xsd | A schema declaration was removed | M0139' ], 'Major change is detected.', ], @@ -125,6 +130,7 @@ public function changesDataProvider() $pathToFixtures . '/schema-declaration-added/source-code-after', [ 'Suggested semantic versioning change: MINOR', + 'schema-declaration-added/source-code-after/Magento/TestModule/etc/test-schema.xsd:0', '/etc/test-schema.xsd | A schema declaration was added | M0140', ], 'Minor change is detected.', @@ -134,6 +140,7 @@ public function changesDataProvider() $pathToFixtures . '/module-added/source-code-after', [ 'Suggested semantic versioning change: MINOR', + 'module-added/source-code-after/Magento/TestModule/etc/test-schema.xsd:0', '/etc/test-schema.xsd | A schema declaration was added | M0140', ], 'Minor change is detected.', @@ -143,6 +150,7 @@ public function changesDataProvider() $pathToFixtures . '/module-removed/source-code-after', [ 'Suggested semantic versioning change: MAJOR', + 'module-removed/source-code-before/Magento/TestModule/etc/test-schema.xsd:0', '/etc/test-schema.xsd | A schema declaration was removed | M0139', ], 'Major change is detected.', diff --git a/tests/Unit/Console/Command/HtmlTest.php b/tests/Unit/Console/Command/HtmlTest.php new file mode 100644 index 00000000..65edb3d6 --- /dev/null +++ b/tests/Unit/Console/Command/HtmlTest.php @@ -0,0 +1,166 @@ +api annotation. + * + * @param string $pathToSourceCodeBefore + * @param string $pathToSourceCodeAfter + * @param int $allowedChangeLevel + * @param array $expectedHtmlEntries + * @param array $expectedPackageSection + * @param string $expectedOutput + * @param int $expectedStatusCode + * @param array $reportTypes + * @param bool $shouldSkipTest + * @return void + * @throws \Exception + * @dataProvider changesDataProvider + */ + public function testExecute( + string $pathToSourceCodeBefore, + string $pathToSourceCodeAfter, + int $allowedChangeLevel, + array $expectedHtmlEntries, + array $expectedPackageSection, + string $expectedOutput, + int $expectedStatusCode, + array $reportTypes, + bool $shouldSkipTest = false + ) { + $this->doTestExecute( + $pathToSourceCodeBefore, + $pathToSourceCodeAfter, + $allowedChangeLevel, + $expectedHtmlEntries, + $expectedPackageSection, + $expectedOutput, + $expectedStatusCode, + $reportTypes, + $shouldSkipTest + ); + } + + public function changesDataProvider() + { + $pathToFixtures = __DIR__ . '/CompareSourceCommandTest/_files/all'; + + return [ + 'test disallowing all versioned changes for all report types (excludes NonApi)' => [ + $pathToFixtures . '/source-code-before', + $pathToFixtures . '/source-code-after', + Level::NONE, + [ + new HtmlParseInfoContainer('#MAJOR#', '//html/body/table/tbody/tr[1]/td[2]'), + new HtmlParseInfoContainer('#Package Level Changes#', '//html/body/table/tbody/tr[last()]/td[1]'), + ], + [ + ['name' => 'test/api-class', 'level' => 'MINOR' ], + ['name' => 'test/api-trait', 'level' => 'MAJOR' ], + ['name' => 'test/layout_xml', 'level' => 'MAJOR' ], + ['name' => 'test/db_schema', 'level' => 'MAJOR' ], + ['name' => 'test/di_xml', 'level' => 'MAJOR' ], + ['name' => 'test/system_xml', 'level' => 'MAJOR' ], + ['name' => 'test/xsd-schema', 'level' => 'MAJOR' ], + ['name' => 'test/less', 'level' => 'MAJOR' ], + ['name' => 'test/mftf', 'level' => 'PATCH' ], + ], + 'Major change is detected.', + -1, + self::getAllReportTypes() + ], + 'test disallowing only Major changes for all types (excludes Non-api php files)' => [ + $pathToFixtures . '/source-code-before', + $pathToFixtures . '/source-code-after', + Level::MINOR, + [ + new HtmlParseInfoContainer('#MAJOR#', '//html/body/table/tbody/tr[1]/td[2]'), + new HtmlParseInfoContainer('#Package Level Changes#', '//html/body/table/tbody/tr[last()]/td[1]'), + ], + [ + ['name' => 'test/api-trait', 'level' => 'MAJOR' ], + ['name' => 'test/layout_xml', 'level' => 'MAJOR' ], + ['name' => 'test/db_schema', 'level' => 'MAJOR' ], + ['name' => 'test/di_xml', 'level' => 'MAJOR' ], + ['name' => 'test/system_xml', 'level' => 'MAJOR' ], + ['name' => 'test/xsd-schema', 'level' => 'MAJOR' ], + ['name' => 'test/less', 'level' => 'MAJOR' ], + ], + 'Major change is detected.', + -1, + self::getAllReportTypes() + ], + 'test allowing only patch changes for all types (excludes Non-api php files)' => [ + $pathToFixtures . '/source-code-before', + $pathToFixtures . '/source-code-after', + Level::PATCH, + [ + new HtmlParseInfoContainer('#MAJOR#', '//html/body/table/tbody/tr[1]/td[2]'), + new HtmlParseInfoContainer('#Package Level Changes#', '//html/body/table/tbody/tr[last()]/td[1]'), + ], + [ + ['name' => 'test/api-class', 'level' => 'MINOR' ], + ['name' => 'test/api-trait', 'level' => 'MAJOR' ], + ['name' => 'test/layout_xml', 'level' => 'MAJOR' ], + ['name' => 'test/db_schema', 'level' => 'MAJOR' ], + ['name' => 'test/di_xml', 'level' => 'MAJOR' ], + ['name' => 'test/system_xml', 'level' => 'MAJOR' ], + ['name' => 'test/xsd-schema', 'level' => 'MAJOR' ], + ['name' => 'test/less', 'level' => 'MAJOR' ], + ], + 'Major change is detected.', + -1, + self::getAllReportTypes() + ], + 'test allowing all changes for all types (excludes Non-api php files)' => [ + $pathToFixtures . '/source-code-before', + $pathToFixtures . '/source-code-after', + Level::MAJOR, + [ + new HtmlParseInfoContainer('#MAJOR#', '//html/body/table/tbody/tr[1]/td[2]'), + new HtmlParseInfoContainer('#Package Level Changes#', '//html/body/table/tbody/tr[last()]/td[1]'), + ], + [], + 'Major change is detected.', + 0, + self::getAllReportTypes() + ], + ]; + } + + /** + * Get all report types + * + * @return array + */ + private static function getAllReportTypes(): array + { + if (!self::$reportTypesList) { + self::$reportTypesList = (new ReflectionClass(ReportTypes::class))->getConstants(); + } + return self::$reportTypesList; + } +}