From c723d36b16a559b06c7265da815e9e6143e690e0 Mon Sep 17 00:00:00 2001 From: Oleksandr Shmyheliuk <oshmyheliuk@magento.com> Date: Thu, 10 Nov 2016 10:44:27 +0200 Subject: [PATCH] MAGETWO-56675: Multiple plugins cannot be run in setup area --- .../Interception/PluginList/PluginList.php | 23 +++++++-------- .../Test/Unit/PluginList/PluginListTest.php | 29 +++++++++++++++++++ .../Test/Unit/_files/reader_mock_map.php | 6 ++++ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index ecfb67320cb..bae8f7c118c 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -276,8 +276,8 @@ class PluginList extends Scoped implements InterceptionPluginList $data = $this->_cache->load($cacheId); if ($data) { list($this->_data, $this->_inherited, $this->_processed) = unserialize($data); - foreach ($this->_scopePriorityScheme as $scope) { - $this->_loadedScopes[$scope] = true; + foreach ($this->_scopePriorityScheme as $scopeCode) { + $this->_loadedScopes[$scopeCode] = true; } } else { $virtualTypes = []; @@ -285,18 +285,17 @@ class PluginList extends Scoped implements InterceptionPluginList if (false == isset($this->_loadedScopes[$scopeCode])) { $data = $this->_reader->read($scopeCode); unset($data['preferences']); - if (!count($data)) { - continue; - } - $this->_inherited = []; - $this->_processed = []; - $this->merge($data); - $this->_loadedScopes[$scopeCode] = true; - foreach ($data as $class => $config) { - if (isset($config['type'])) { - $virtualTypes[] = $class; + if (count($data) > 0) { + $this->_inherited = []; + $this->_processed = []; + $this->merge($data); + foreach ($data as $class => $config) { + if (isset($config['type'])) { + $virtualTypes[] = $class; + } } } + $this->_loadedScopes[$scopeCode] = true; } if ($this->isCurrentScope($scopeCode)) { break; diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php index b3fe011a0a4..ac1e510f28b 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php @@ -256,4 +256,33 @@ class PluginListTest extends \PHPUnit_Framework_TestCase $this->assertEquals(null, $this->_model->getNext('Type', 'method')); } + + /** + * @covers \Magento\Framework\Interception\PluginList\PluginList::getNext + * @covers \Magento\Framework\Interception\PluginList\PluginList::_loadScopedData + */ + public function testLoadScopeDataWithEmptyData() + { + $this->_objectManagerMock->expects($this->any()) + ->method('get') + ->will($this->returnArgument(0)); + $this->_configScopeMock->expects($this->any()) + ->method('getCurrentScope') + ->will($this->returnValue('emptyscope')); + + $this->assertEquals( + [4 => ['simple_plugin']], + $this->_model->getNext( + \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class, + 'getName' + ) + ); + $this->assertEquals( + \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Simple::class, + $this->_model->getPlugin( + \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class, + 'simple_plugin' + ) + ); + } } diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/_files/reader_mock_map.php b/lib/internal/Magento/Framework/Interception/Test/Unit/_files/reader_mock_map.php index 87bbe0d35dd..37c5316171f 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/_files/reader_mock_map.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/_files/reader_mock_map.php @@ -77,5 +77,11 @@ return [ ], ] ] + ], + [ + 'emptyscope', + [ + + ] ] ]; -- GitLab