diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php index f59d3f020cae4..18aa56c926edc 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php @@ -21,16 +21,26 @@ class PluginListGeneratorTest extends TestCase { /** - * Generated plugin list config for frontend scope + * Generated plugin list config for frontend scope (scopes sorted alphabetically in PluginListGenerator) */ - const CACHE_ID_FRONTEND = 'primary|global|frontend|plugin-list'; + private const CACHE_ID_FRONTEND = 'frontend|global|primary|plugin-list'; /** - * Generated plugin list config for dummy scope + * Generated plugin list config for dummy scope (scopes sorted alphabetically in PluginListGenerator) */ - const CACHE_ID_DUMMY = 'primary|global|dummy|plugin-list'; + private const CACHE_ID_DUMMY = 'dummy|global|primary|plugin-list'; - private $cacheIds = [self::CACHE_ID_FRONTEND, self::CACHE_ID_DUMMY]; + /** + * Generated plugin list config for global scope (used in tearDown for cleanup) + */ + private const CACHE_ID_GLOBAL = 'global|primary|plugin-list'; + + /** + * Cache IDs to clean up in tearDown + * + * @var array + */ + private $cacheIds = [self::CACHE_ID_GLOBAL, self::CACHE_ID_FRONTEND, self::CACHE_ID_DUMMY]; /** * @var PluginListGenerator diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index 2f86c8703dea5..26f4bab027b4d 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -217,7 +217,10 @@ protected function _loadScopedData() } $this->_scopePriorityScheme[] = $scope; - $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId; + // Normalize cache ID by sorting scopes - ensures consistent ID regardless of processing order + $sortedScheme = array_values($this->_scopePriorityScheme); + sort($sortedScheme); + $cacheId = implode('|', $sortedScheme) . "|" . $this->_cacheId; $configData = $this->configLoader->load($cacheId); if ($configData) { diff --git a/lib/internal/Magento/Framework/Interception/PluginListGenerator.php b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php index 0153ee92a8062..426674b3b41b7 100644 --- a/lib/internal/Magento/Framework/Interception/PluginListGenerator.php +++ b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php @@ -90,10 +90,17 @@ public function write(array $scopes): void foreach ($scopes as $scope) { $this->scopeConfig->setCurrentScope($scope); if (false === isset($this->loadedScopes[$scope])) { - if (false === in_array($scope, $this->scopePriorityScheme, true)) { - $this->scopePriorityScheme[] = $scope; + // Match PluginList::_loadScopedData() behavior - move scope to end + // This ensures cache IDs match between compile-time and runtime + $index = array_search($scope, $this->scopePriorityScheme, true); + if ($index !== false) { + unset($this->scopePriorityScheme[$index]); } - $cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId; + $this->scopePriorityScheme[] = $scope; + // Normalize cache ID by sorting scopes - ensures consistent ID regardless of processing order + $sortedScheme = array_values($this->scopePriorityScheme); + sort($sortedScheme); + $cacheId = implode('|', $sortedScheme) . "|" . $this->cacheId; [ $virtualTypes, $this->scopePriorityScheme, diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php index 22a4f5530c232..72c2586e1b0ec 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -44,12 +44,8 @@ public function __construct( public function doOperation() { $scopes = $this->scopeConfig->getAllScopes(); - // remove primary scope for production mode as it is only called in developer mode - $scopes = array_diff($scopes, ['primary']); - - // sort configuration to have it in the same order on every build - ksort($scopes); - + // Cache IDs are now normalized (sorted) in PluginListGenerator::write() + // so processing order no longer affects cache ID generation $this->configWriter->write($scopes); }