Skip to content

Commit afb0b4e

Browse files
Merge remote-tracking branch '38141/develop' into comprs_nov
2 parents daaa4b3 + b8ecea0 commit afb0b4e

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
lines changed

setup/src/Magento/Setup/Module/Di/Code/Generator/InterceptionConfigurationBuilder.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<?php
22
/**
3-
*
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
65
*/
76

87
namespace Magento\Setup\Module\Di\Code\Generator;
98

109
use Magento\Framework\App\Area;
1110
use Magento\Framework\App\Cache\Manager;
1211
use Magento\Framework\App\Interception\Cache\CompiledConfig;
12+
use Magento\Framework\App\ObjectManager;
1313
use Magento\Framework\Interception\Config\Config as InterceptionConfig;
14-
use Magento\Setup\Module\Di\Code\Reader\Type;
14+
use Magento\Framework\Interception\Definition\Runtime;
15+
use Magento\Framework\Interception\ObjectManager\ConfigInterface;
1516
use Magento\Framework\ObjectManager\InterceptableValidator;
17+
use Magento\Setup\Module\Di\Code\Reader\Type;
1618

1719
class InterceptionConfigurationBuilder
1820
{
@@ -48,25 +50,33 @@ class InterceptionConfigurationBuilder
4850
*/
4951
private $interceptableValidator;
5052

53+
/**
54+
* @var ConfigInterface
55+
*/
56+
private $omConfig;
57+
5158
/**
5259
* @param InterceptionConfig $interceptionConfig
5360
* @param PluginList $pluginList
5461
* @param Type $typeReader
5562
* @param Manager $cacheManager
5663
* @param InterceptableValidator $interceptableValidator
64+
* @param ConfigInterface|null $omConfig
5765
*/
5866
public function __construct(
5967
InterceptionConfig $interceptionConfig,
6068
PluginList $pluginList,
6169
Type $typeReader,
6270
Manager $cacheManager,
63-
InterceptableValidator $interceptableValidator
71+
InterceptableValidator $interceptableValidator,
72+
?ConfigInterface $omConfig = null
6473
) {
6574
$this->interceptionConfig = $interceptionConfig;
6675
$this->pluginList = $pluginList;
6776
$this->typeReader = $typeReader;
6877
$this->cacheManager = $cacheManager;
6978
$this->interceptableValidator = $interceptableValidator;
79+
$this->omConfig = $omConfig ?? ObjectManager::getInstance()->get(ConfigInterface::class);
7080
}
7181

7282
/**
@@ -195,18 +205,26 @@ private function mergeAreaPlugins($inheritedConfig)
195205
* @param array $interceptionConfiguration
196206
* @return array
197207
*/
198-
private function getInterceptedMethods($interceptionConfiguration)
208+
private function getInterceptedMethods(array $interceptionConfiguration): array
199209
{
200-
$pluginDefinitionList = new \Magento\Framework\Interception\Definition\Runtime();
210+
$pluginDefinitionList = new Runtime();
201211
foreach ($interceptionConfiguration as &$plugins) {
202212
$pluginsMethods = [];
213+
203214
foreach ($plugins as $plugin) {
204-
$pluginsMethods = array_unique(
205-
array_merge($pluginsMethods, array_keys($pluginDefinitionList->getMethodList($plugin)))
206-
);
215+
$plugin = $this->omConfig->getOriginalInstanceType($plugin);
216+
217+
$pluginsMethods = [
218+
...$pluginsMethods,
219+
...\array_keys(
220+
$pluginDefinitionList->getMethodList($plugin)
221+
)
222+
];
207223
}
208-
$plugins = $pluginsMethods;
224+
225+
$plugins = \array_unique($pluginsMethods);
209226
}
227+
210228
return $interceptionConfiguration;
211229
}
212230
}

setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Generator/InterceptionConfigurationBuilderTest.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -10,13 +10,13 @@
1010
use Magento\Framework\App\Cache\Manager;
1111
use Magento\Framework\App\Interception\Cache\CompiledConfig;
1212
use Magento\Framework\Interception\Config\Config;
13+
use Magento\Framework\Interception\ObjectManager\ConfigInterface;
1314
use Magento\Framework\ObjectManager\InterceptableValidator;
1415
use Magento\Setup\Module\Di\Code\Generator\InterceptionConfigurationBuilder;
1516
use Magento\Setup\Module\Di\Code\Generator\PluginList;
1617
use Magento\Setup\Module\Di\Code\Reader\Type;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
19-
use stdClass;
2020

2121
class InterceptionConfigurationBuilderTest extends TestCase
2222
{
@@ -50,25 +50,30 @@ class InterceptionConfigurationBuilderTest extends TestCase
5050
*/
5151
private $interceptableValidator;
5252

53+
/**
54+
* @var MockObject
55+
*/
56+
private $omConfig;
57+
5358
protected function setUp(): void
5459
{
55-
$this->interceptionConfig =
56-
$this->createPartialMock(Config::class, ['hasPlugins']);
60+
$this->interceptionConfig = $this->createPartialMock(Config::class, ['hasPlugins']);
5761
$this->pluginList = $this->createPartialMock(
5862
PluginList::class,
5963
['setInterceptedClasses', 'setScopePriorityScheme', 'getPluginsConfig']
6064
);
6165
$this->cacheManager = $this->createMock(Manager::class);
62-
$this->interceptableValidator =
63-
$this->createMock(InterceptableValidator::class);
66+
$this->interceptableValidator = $this->createMock(InterceptableValidator::class);
67+
$this->omConfig = $this->createMock(ConfigInterface::class);
6468

6569
$this->typeReader = $this->createPartialMock(Type::class, ['isConcrete']);
6670
$this->model = new InterceptionConfigurationBuilder(
6771
$this->interceptionConfig,
6872
$this->pluginList,
6973
$this->typeReader,
7074
$this->cacheManager,
71-
$this->interceptableValidator
75+
$this->interceptableValidator,
76+
$this->omConfig
7277
);
7378
}
7479

@@ -106,6 +111,13 @@ public function testGetInterceptionConfiguration($plugins)
106111
->method('getPluginsConfig')
107112
->willReturn(['instance' => $plugins]);
108113

114+
$this->omConfig->expects($this->any())
115+
->method('getOriginalInstanceType')
116+
->willReturnMap([
117+
['stdClass', 'stdClass'],
118+
['virtualTypeClass', 'stdClass'],
119+
]);
120+
109121
$this->model->addAreaCode('areaCode');
110122
$this->model->getInterceptionConfiguration($definedClasses);
111123
}
@@ -115,11 +127,15 @@ public function testGetInterceptionConfiguration($plugins)
115127
*/
116128
public static function getInterceptionConfigurationDataProvider()
117129
{
118-
$someInstance = new stdClass();
119130
return [
120131
[null],
121-
[['plugin' => ['instance' => $someInstance]]],
122-
[['plugin' => ['instance' => $someInstance], 'plugin2' => ['instance' => $someInstance]]]
132+
[['plugin' => ['instance' => 'stdClass']]],
133+
[[
134+
'plugin' => ['instance' => 'stdClass'],
135+
'plugin1' => ['instance' => 'stdClass'],
136+
'plugin2' => ['instance' => 'virtualTypeClass']
137+
]],
138+
[['plugin' => ['instance' => 'virtualTypeClass']]],
123139
];
124140
}
125141
}

0 commit comments

Comments
 (0)