Skip to content

Commit 751fdbc

Browse files
committed
Merge remote-tracking branch 'origin/MC-34257' into 2.4-develop-pr28
2 parents 88081f1 + 219151e commit 751fdbc

File tree

4 files changed

+116
-23
lines changed

4 files changed

+116
-23
lines changed

app/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@
426426
<argument name="reader" xsi:type="object">Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy</argument>
427427
<argument name="cacheId" xsi:type="string">plugin-list</argument>
428428
<argument name="scopePriorityScheme" xsi:type="array">
429+
<item name="primary" xsi:type="string">primary</item>
429430
<item name="first" xsi:type="string">global</item>
430431
</argument>
431432
</arguments>

lib/internal/Magento/Framework/Interception/PluginList/PluginList.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,18 @@ protected function _loadScopedData()
281281
{
282282
$scope = $this->_configScope->getCurrentScope();
283283
if (false == isset($this->_loadedScopes[$scope])) {
284-
if (false == in_array($scope, $this->_scopePriorityScheme)) {
285-
$this->_scopePriorityScheme[] = $scope;
284+
$index = array_search($scope, $this->_scopePriorityScheme);
285+
/**
286+
* Force current scope to be at the end of the scheme to ensure that default priority scopes are loaded.
287+
* Mostly happens when the current scope is primary.
288+
* For instance if the default scope priority scheme is [primary, global] and current scope is primary,
289+
* the resulted scheme will be [global, primary] so global scope is loaded.
290+
*/
291+
if ($index !== false) {
292+
unset($this->_scopePriorityScheme[$index]);
286293
}
294+
$this->_scopePriorityScheme[] = $scope;
295+
287296
$cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId;
288297
$data = $this->_cache->load($cacheId);
289298
if ($data) {

lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class PluginListTest extends TestCase
6868
private $serializerMock;
6969

7070
/**
71-
* @var ObjectManagerInterface||\PHPUnit\Framework\MockObject\MockObject
71+
* @var ObjectManagerInterface|MockObject
7272
*/
7373
private $objectManagerMock;
7474

@@ -172,15 +172,23 @@ public function testGetPlugin()
172172
}
173173

174174
/**
175-
* @param $expectedResult
176-
* @param $type
177-
* @param $method
178-
* @param $scopeCode
175+
* @param array $expectedResult
176+
* @param string $type
177+
* @param string $method
178+
* @param string $scopeCode
179179
* @param string $code
180+
* @param array $scopePriorityScheme
180181
* @dataProvider getPluginsDataProvider
181182
*/
182-
public function testGetPlugins($expectedResult, $type, $method, $scopeCode, $code = '__self')
183-
{
183+
public function testGetPlugins(
184+
?array $expectedResult,
185+
string $type,
186+
string $method,
187+
string $scopeCode,
188+
string $code = '__self',
189+
array $scopePriorityScheme = ['global']
190+
): void {
191+
$this->setScopePriorityScheme($scopePriorityScheme);
184192
$this->configScopeMock->expects(
185193
$this->any()
186194
)->method(
@@ -245,7 +253,47 @@ public function getPluginsDataProvider()
245253
ItemContainer::class,
246254
'getName',
247255
'backend'
248-
]
256+
],
257+
[
258+
// even though the scope is primary, both primary and global scopes are loaded
259+
// because global is in default priority scheme
260+
[
261+
4 => [
262+
'primary_plugin',
263+
'simple_plugin',
264+
]
265+
],
266+
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
267+
'getName',
268+
'primary',
269+
'__self',
270+
['primary', 'global']
271+
],
272+
[
273+
[
274+
4 => [
275+
'primary_plugin',
276+
'simple_plugin',
277+
]
278+
],
279+
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
280+
'getName',
281+
'global',
282+
'__self',
283+
['primary', 'global']
284+
],
285+
[
286+
[
287+
4 => [
288+
'primary_plugin',
289+
]
290+
],
291+
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
292+
'getName',
293+
'frontend',
294+
'__self',
295+
['primary', 'global']
296+
],
249297
];
250298
}
251299

@@ -348,4 +396,16 @@ public function testLoadScopeDataWithEmptyData()
348396
)
349397
);
350398
}
399+
400+
/**
401+
* @param array $areaCodes
402+
* @throws \ReflectionException
403+
*/
404+
private function setScopePriorityScheme(array $areaCodes): void
405+
{
406+
$reflection = new \ReflectionClass($this->object);
407+
$reflection_property = $reflection->getProperty('_scopePriorityScheme');
408+
$reflection_property->setAccessible(true);
409+
$reflection_property->setValue($this->object, $areaCodes);
410+
}
351411
}

lib/internal/Magento/Framework/Interception/Test/Unit/_files/reader_mock_map.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,38 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item;
8+
use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item\Enhanced;
9+
use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer;
610
use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainerPlugin\Simple;
11+
use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Advanced;
12+
use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Simple as ItemPluginSimple;
13+
use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash;
714
use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash\Plugin;
815

916
return [
17+
[
18+
'primary',
19+
[
20+
Item::class => [
21+
'plugins' => [
22+
'primary_plugin' => [
23+
'sortOrder' => 1,
24+
'instance' => ItemPluginSimple::class,
25+
],
26+
],
27+
]
28+
],
29+
],
1030
[
1131
'global',
1232
[
13-
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class => [
33+
Item::class => [
1434
'plugins' => [
1535
'simple_plugin' => [
1636
'sortOrder' => 10,
17-
'instance' =>
18-
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Simple::class,
37+
'instance' => ItemPluginSimple::class,
1938
],
2039
],
2140
]
@@ -24,24 +43,23 @@
2443
[
2544
'backend',
2645
[
27-
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class => [
46+
Item::class => [
2847
'plugins' => [
2948
'advanced_plugin' => [
3049
'sortOrder' => 5,
31-
'instance' =>
32-
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Advanced::class,
50+
'instance' => Advanced::class,
3351
],
3452
],
3553
],
36-
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer::class => [
54+
ItemContainer::class => [
3755
'plugins' => [
3856
'simple_plugin' => [
3957
'sortOrder' => 15,
4058
'instance' => Simple::class,
4159
],
4260
],
4361
],
44-
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash::class => [
62+
StartingBackslash::class => [
4563
'plugins' => [
4664
'simple_plugin' => [
4765
'sortOrder' => 20,
@@ -53,14 +71,19 @@
5371
],
5472
[
5573
'frontend',
56-
[\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class => [
57-
'plugins' => ['simple_plugin' => ['disabled' => true]],
58-
], \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item\Enhanced::class => [
74+
[
75+
Item::class => [
76+
'plugins' => [
77+
'simple_plugin' => [
78+
'disabled' => true
79+
]
80+
],
81+
],
82+
Enhanced::class => [
5983
'plugins' => [
6084
'advanced_plugin' => [
6185
'sortOrder' => 5,
62-
'instance' =>
63-
\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Advanced::class,
86+
'instance' => Advanced::class,
6487
],
6588
],
6689
],

0 commit comments

Comments
 (0)