From 7d1195a8e46c44970d844573f1fc7c3d63acd79b Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 25 May 2023 11:25:32 +0100 Subject: [PATCH] Detect when virtualTypes move elsewhere --- .../Command/CompareSourceCommandDiXmlTest.php | 16 ++++++++++++++++ .../Magento/AnotherTestModule/etc/di.xml | 17 +++++++++++++++++ .../Magento/TestModule/etc/di.xml | 17 +++++++++++++++++ .../source-code-after/app/etc/di.xml | 17 +++++++++++++++++ .../Magento/TestModule/etc/di.xml | 17 +++++++++++++++++ src/Analyzer/DiXml/VirtualTypeAnalyzer.php | 11 +++++++++++ src/resources/application_includes.txt | 1 + 7 files changed, 96 insertions(+) create mode 100644 dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-another-module/source-code-after/Magento/AnotherTestModule/etc/di.xml create mode 100644 dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-another-module/source-code-before/Magento/TestModule/etc/di.xml create mode 100644 dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-app-etc/source-code-after/app/etc/di.xml create mode 100644 dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-app-etc/source-code-before/Magento/TestModule/etc/di.xml diff --git a/dev/tests/Unit/Console/Command/CompareSourceCommandDiXmlTest.php b/dev/tests/Unit/Console/Command/CompareSourceCommandDiXmlTest.php index d65b30f5..18ea9b3d 100644 --- a/dev/tests/Unit/Console/Command/CompareSourceCommandDiXmlTest.php +++ b/dev/tests/Unit/Console/Command/CompareSourceCommandDiXmlTest.php @@ -55,6 +55,22 @@ public function changesDataProvider() ], '' ], + 'moved-to-app-etc' => [ + $pathToFixtures . '/moved-to-app-etc/source-code-before', + $pathToFixtures . '/moved-to-app-etc/source-code-after', + [ + '#Suggested semantic versioning change: NONE#', + ], + 'Patch change is detected.', + ], + 'moved-to-another-module' => [ + $pathToFixtures . '/moved-to-another-module/source-code-before', + $pathToFixtures . '/moved-to-another-module/source-code-after', + [ + '#Suggested semantic versioning change: NONE#', + ], + 'Patch change is detected.', + ], 'moved-to-global' => [ $pathToFixtures . '/moved-to-global/source-code-before', $pathToFixtures . '/moved-to-global/source-code-after', diff --git a/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-another-module/source-code-after/Magento/AnotherTestModule/etc/di.xml b/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-another-module/source-code-after/Magento/AnotherTestModule/etc/di.xml new file mode 100644 index 00000000..be21debf --- /dev/null +++ b/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-another-module/source-code-after/Magento/AnotherTestModule/etc/di.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-another-module/source-code-before/Magento/TestModule/etc/di.xml b/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-another-module/source-code-before/Magento/TestModule/etc/di.xml new file mode 100644 index 00000000..27acc9c8 --- /dev/null +++ b/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-another-module/source-code-before/Magento/TestModule/etc/di.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-app-etc/source-code-after/app/etc/di.xml b/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-app-etc/source-code-after/app/etc/di.xml new file mode 100644 index 00000000..0a0d06b2 --- /dev/null +++ b/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-app-etc/source-code-after/app/etc/di.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-app-etc/source-code-before/Magento/TestModule/etc/di.xml b/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-app-etc/source-code-before/Magento/TestModule/etc/di.xml new file mode 100644 index 00000000..81d6c415 --- /dev/null +++ b/dev/tests/Unit/Console/Command/CompareSourceCommandTest/_files/di_xml/moved-to-app-etc/source-code-before/Magento/TestModule/etc/di.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/src/Analyzer/DiXml/VirtualTypeAnalyzer.php b/src/Analyzer/DiXml/VirtualTypeAnalyzer.php index 01355ca9..724ed89c 100644 --- a/src/Analyzer/DiXml/VirtualTypeAnalyzer.php +++ b/src/Analyzer/DiXml/VirtualTypeAnalyzer.php @@ -67,6 +67,17 @@ public function analyze($registryBefore, $registryAfter) continue; } + foreach ($nodesAfter as $newModuleNodes) { + foreach ($newModuleNodes as $nodeAfter) { + if ($nodeBefore->getName() !== $nodeAfter->getName()) { + continue; + } + + $this->triggerNodeChange($nodeBefore, $nodeAfter, $fileBefore); + continue 3; + } + } + $operation = new VirtualTypeRemoved($fileBefore, $name); $this->report->add('di', $operation); } diff --git a/src/resources/application_includes.txt b/src/resources/application_includes.txt index 36776019..bf7532ae 100644 --- a/src/resources/application_includes.txt +++ b/src/resources/application_includes.txt @@ -1,4 +1,5 @@ app/code +app/etc lib/internal/Magento Inventory* Adobe*