11 require_once
__DIR__ .
'/../Custom/Module/Model/Item.php';
12 require_once
__DIR__ .
'/../Custom/Module/Model/Item/Enhanced.php';
13 require_once
__DIR__ .
'/../Custom/Module/Model/ItemContainer.php';
14 require_once
__DIR__ .
'/../Custom/Module/Model/ItemContainer/Enhanced.php';
15 require_once
__DIR__ .
'/../Custom/Module/Model/ItemContainerPlugin/Simple.php';
16 require_once
__DIR__ .
'/../Custom/Module/Model/ItemPlugin/Simple.php';
17 require_once
__DIR__ .
'/../Custom/Module/Model/ItemPlugin/Advanced.php';
18 require_once
__DIR__ .
'/../Custom/Module/Model/StartingBackslash.php';
19 require_once
__DIR__ .
'/../Custom/Module/Model/StartingBackslash/Plugin.php';
34 private $configScopeMock;
49 private $serializerMock;
54 private $objectManagerMock;
58 $readerMap = include
__DIR__ .
'/../_files/reader_mock_map.php';
60 $readerMock->expects($this->any())->method(
'read')->will($this->returnValueMap($readerMap));
62 $this->configScopeMock = $this->createMock(\
Magento\Framework\Config\ScopeInterface::class);
63 $this->cacheMock = $this->getMockBuilder(\
Magento\Framework\Config\CacheInterface::class)
65 ->getMockForAbstractClass();
67 $this->cacheMock->expects($this->any())
69 ->will($this->returnValue(
false));
71 $omConfigMock = $this->getMockForAbstractClass(
75 $omConfigMock->expects($this->any())->method(
'getOriginalInstanceType')->will($this->returnArgument(0));
77 $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
79 ->getMockForAbstractClass();
80 $this->objectManagerMock->expects($this->any())
82 ->willReturnArgument(0);
83 $this->serializerMock = $this->createMock(SerializerInterface::class);
85 $definitions = new \Magento\Framework\ObjectManager\Definition\Runtime();
87 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
88 $this->
object = $objectManagerHelper->getObject(
89 \
Magento\Framework\Interception\PluginList\PluginList::class,
91 'reader' => $readerMock,
92 'configScope' => $this->configScopeMock,
93 'cache' => $this->cacheMock,
95 'omConfig' => $omConfigMock,
96 'definitions' =>
new \
Magento\Framework\Interception\Definition\Runtime(),
97 'objectManager' => $this->objectManagerMock,
98 'classDefinitions' => $definitions,
99 'scopePriorityScheme' => [
'global'],
100 'cacheId' =>
'interception',
101 'serializer' => $this->serializerMock
105 $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
106 $objectManagerHelper->setBackwardCompatibleProperty(
115 $this->configScopeMock->expects($this->any())->method(
'getCurrentScope')->will($this->returnValue(
'backend'));
116 $this->
object->getNext(\
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
'getName');
117 $this->
object->getNext(
118 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer::class,
121 $this->
object->getNext(
122 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash::class,
126 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Simple::class,
127 $this->object->getPlugin(
128 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
133 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Advanced::class,
134 $this->object->getPlugin(
135 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
140 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainerPlugin\Simple::class,
141 $this->object->getPlugin(
142 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer::class,
147 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash\Plugin::class,
148 $this->object->getPlugin(
149 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash::class,
165 $this->configScopeMock->expects(
170 $this->returnValue($scopeCode)
172 $this->assertEquals($expectedResult, $this->object->getNext(
$type,
$method,
$code));
182 [4 => [
'simple_plugin']], \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
188 [2 =>
'advanced_plugin', 4 => [
'advanced_plugin']],
189 \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
195 [4 => [
'simple_plugin']],
196 \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
203 [
null, \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
'getName',
'frontend'],
206 [4 => [
'simple_plugin']],
207 \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item\Enhanced::class,
213 [2 =>
'advanced_plugin', 4 => [
'advanced_plugin']],
214 \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item\Enhanced::class,
220 \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer::class,
225 [4 => [
'simple_plugin']],
226 \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer::class,
240 $this->configScopeMock->expects($this->any())
241 ->method(
'getCurrentScope')
242 ->will($this->returnValue(
'frontend'));
244 $this->
object->getNext(
'SomeType',
'someMethod');
249 $this->configScopeMock->expects($this->exactly(3))
250 ->method(
'getCurrentScope')
251 ->will($this->returnValue(
'scope'));
252 $this->serializerMock->expects($this->once())
253 ->method(
'serialize');
254 $this->serializerMock->expects($this->never())
255 ->method(
'unserialize');
256 $this->cacheMock->expects($this->once())
259 $this->assertEquals(
null, $this->object->getNext(
'Type',
'method'));
268 $this->loggerMock->expects($this->once())
270 ->with(
"Reference to undeclared plugin with name 'simple_plugin'.");
271 $this->configScopeMock->expects($this->any())
272 ->method(
'getCurrentScope')
273 ->will($this->returnValue(
'frontend'));
275 $this->assertNull($this->object->getNext(
'typeWithoutInstance',
'someMethod'));
284 $this->configScopeMock->expects($this->once())
285 ->method(
'getCurrentScope')
286 ->will($this->returnValue(
'scope'));
288 $data = [[
'key'], [
'key'], [
'key']];
289 $serializedData =
'serialized data';
291 $this->serializerMock->expects($this->never())
292 ->method(
'serialize');
293 $this->serializerMock->expects($this->once())
294 ->method(
'unserialize')
296 $this->cacheMock->expects($this->once())
298 ->with(
'global|scope|interception')
299 ->willReturn($serializedData);
301 $this->assertEquals(
null, $this->object->getNext(
'Type',
'method'));
310 $this->objectManagerMock->expects($this->any())
312 ->will($this->returnArgument(0));
313 $this->configScopeMock->expects($this->any())
314 ->method(
'getCurrentScope')
315 ->will($this->returnValue(
'emptyscope'));
318 [4 => [
'simple_plugin']],
319 $this->object->getNext(
320 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
325 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Simple::class,
326 $this->object->getPlugin(
327 \
Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class,
testInheritPluginsWithNonExistingClass()
defined('TESTS_BP')||define('TESTS_BP' __DIR__
testInheritPluginsWithNotExistingPlugin()
testLoadScopeDataWithEmptyData()
testGetPlugins($expectedResult, $type, $method, $scopeCode, $code='__self')
testLoadScopedDataNotCached()
testLoadScopedDataCached()