Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
use Magento\Framework\App\Area;
use Magento\Framework\App\Cache\Manager;
use Magento\Framework\App\Interception\Cache\CompiledConfig;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Interception\Config\Config as InterceptionConfig;
use Magento\Setup\Module\Di\Code\Reader\Type;
use Magento\Framework\Interception\Definition\Runtime;
use Magento\Framework\Interception\ObjectManager\ConfigInterface;
use Magento\Framework\ObjectManager\InterceptableValidator;
use Magento\Setup\Module\Di\Code\Reader\Type;

class InterceptionConfigurationBuilder
{
Expand Down Expand Up @@ -48,25 +51,33 @@ class InterceptionConfigurationBuilder
*/
private $interceptableValidator;

/**
* @var ConfigInterface
*/
private $omConfig;

/**
* @param InterceptionConfig $interceptionConfig
* @param PluginList $pluginList
* @param Type $typeReader
* @param Manager $cacheManager
* @param InterceptableValidator $interceptableValidator
* @param ConfigInterface|null $omConfig
*/
public function __construct(
InterceptionConfig $interceptionConfig,
PluginList $pluginList,
Type $typeReader,
Manager $cacheManager,
InterceptableValidator $interceptableValidator
InterceptableValidator $interceptableValidator,
?ConfigInterface $omConfig = null
) {
$this->interceptionConfig = $interceptionConfig;
$this->pluginList = $pluginList;
$this->typeReader = $typeReader;
$this->cacheManager = $cacheManager;
$this->interceptableValidator = $interceptableValidator;
$this->omConfig = $omConfig ?? ObjectManager::getInstance()->get(ConfigInterface::class);
}

/**
Expand Down Expand Up @@ -195,18 +206,23 @@ private function mergeAreaPlugins($inheritedConfig)
* @param array $interceptionConfiguration
* @return array
*/
private function getInterceptedMethods($interceptionConfiguration)
private function getInterceptedMethods(array $interceptionConfiguration): array
{
$pluginDefinitionList = new \Magento\Framework\Interception\Definition\Runtime();
$pluginDefinitionList = new Runtime();

foreach ($interceptionConfiguration as &$plugins) {
$pluginsMethods = [];

foreach ($plugins as $plugin) {
$pluginsMethods = array_unique(
array_merge($pluginsMethods, array_keys($pluginDefinitionList->getMethodList($plugin)))
);
$plugin = $this->omConfig->getOriginalInstanceType($plugin);

$pluginsMethods[] = $pluginDefinitionList->getMethodList($plugin);
}
$plugins = $pluginsMethods;

// phpcs:ignore Magento2.Performance.ForeachArrayMerge
$plugins = array_unique(array_merge([], ...$pluginsMethods));
}

return $interceptionConfiguration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Setup\Module\Di\Code\Reader\Type;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\Framework\Interception\ObjectManager\ConfigInterface;

class InterceptionConfigurationBuilderTest extends TestCase
{
Expand Down Expand Up @@ -49,6 +50,11 @@ class InterceptionConfigurationBuilderTest extends TestCase
*/
private $interceptableValidator;

/**
* @var MockObject
*/
private $omConfig;

protected function setUp(): void
{
$this->interceptionConfig =
Expand All @@ -60,14 +66,16 @@ protected function setUp(): void
$this->cacheManager = $this->createMock(Manager::class);
$this->interceptableValidator =
$this->createMock(InterceptableValidator::class);
$this->omConfig = $this->createMock(ConfigInterface::class);

$this->typeReader = $this->createPartialMock(Type::class, ['isConcrete']);
$this->model = new InterceptionConfigurationBuilder(
$this->interceptionConfig,
$this->pluginList,
$this->typeReader,
$this->cacheManager,
$this->interceptableValidator
$this->interceptableValidator,
$this->omConfig
);
}

Expand Down Expand Up @@ -105,6 +113,13 @@ public function testGetInterceptionConfiguration($plugins)
->method('getPluginsConfig')
->willReturn(['instance' => $plugins]);

$this->omConfig->expects($this->any())
->method('getOriginalInstanceType')
->willReturnMap([
['someinstance', 'someinstance'],
['someinstance1', 'someinstance'],
]);

$this->model->addAreaCode('areaCode');
$this->model->getInterceptionConfiguration($definedClasses);
}
Expand All @@ -117,6 +132,7 @@ public function getInterceptionConfigurationDataProvider()
return [
[null],
[['plugin' => ['instance' => 'someinstance']]],
[['plugin' => ['instance' => 'someinstance1']]],
[['plugin' => ['instance' => 'someinstance'], 'plugin2' => ['instance' => 'someinstance']]]
];
}
Expand Down