Skip to content

Commit 2b87cb1

Browse files
author
Oleksandr Dubovyk
committed
Merge remote-tracking branch 'local/MC-39132' into PRodubovyk20201222
2 parents 661c15c + 93c78c0 commit 2b87cb1

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ class PluginListGeneratorTest extends TestCase
2323
/**
2424
* Generated plugin list config for frontend scope
2525
*/
26-
const CACHE_ID = 'primary|global|frontend|plugin-list';
26+
const CACHE_ID_FRONTEND = 'primary|global|frontend|plugin-list';
27+
28+
/**
29+
* Generated plugin list config for dummy scope
30+
*/
31+
const CACHE_ID_DUMMY = 'primary|global|dummy|plugin-list';
32+
33+
private $cacheIds = [self::CACHE_ID_FRONTEND, self::CACHE_ID_DUMMY];
2734

2835
/**
2936
* @var PluginListGenerator
@@ -90,31 +97,51 @@ protected function setUp(): void
9097
*/
9198
public function testPluginListConfigGeneration()
9299
{
93-
$scopes = ['frontend'];
100+
$scopes = ['global', 'frontend', 'dummy'];
101+
$globalPlugin = 'genericHeaderPlugin';
102+
$frontendPlugin = 'response-http-page-cache';
94103
$this->model->write($scopes);
95-
$configData = $this->model->load(self::CACHE_ID);
96-
$this->assertNotEmpty($configData[0]);
97-
$this->assertNotEmpty($configData[1]);
98-
$this->assertNotEmpty($configData[2]);
99-
$expected = [
104+
$configDataFrontend = $this->model->load(self::CACHE_ID_FRONTEND);
105+
$this->assertNotEmpty($configDataFrontend[0]);
106+
$this->assertNotEmpty($configDataFrontend[1]);
107+
$this->assertNotEmpty($configDataFrontend[2]);
108+
$expectedFrontend = [
100109
1 => [
101-
0 => 'genericHeaderPlugin',
102-
1 => 'response-http-page-cache'
110+
0 => $globalPlugin,
111+
1 => $frontendPlugin
103112
]
104113
];
105114
// Here in test is assumed that this class below has 3 plugins. But the amount of plugins and class itself
106115
// may vary. If it is changed, please update these assertions.
107116
$this->assertArrayHasKey(
108117
'Magento\\Framework\\App\\Response\\Http_sendResponse___self',
109-
$configData[2],
118+
$configDataFrontend[2],
110119
'Processed plugin does not exist in the processed plugins array.'
111120
);
112121

113122
$this->assertSame(
114-
$expected,
115-
$configData[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'],
123+
$expectedFrontend,
124+
$configDataFrontend[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'],
116125
'Plugin configurations are not equal'
117126
);
127+
128+
$configDataDummy = $this->model->load(self::CACHE_ID_DUMMY);
129+
/**
130+
* Make sure "dummy" scope with no plugins in system should not contain plugins from "frontend" scope
131+
*/
132+
$this->assertNotContains(
133+
$frontendPlugin,
134+
$configDataDummy[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'][1],
135+
'Plugin configurations are not equal. "dummy" scope should not contain plugins from "frontend" scope'
136+
);
137+
/**
138+
* Make sure "dummy" scope with no plugins in system should contain plugins from "global" scope
139+
*/
140+
$this->assertContains(
141+
$globalPlugin,
142+
$configDataDummy[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'][1],
143+
'Plugin configurations are not equal. "dummy" scope should contain plugins from "global" scope'
144+
);
118145
}
119146

120147
/**
@@ -137,11 +164,13 @@ private function getCustomDirs(): array
137164
*/
138165
protected function tearDown(): void
139166
{
140-
$filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA)
141-
. '/' . self::CACHE_ID . '.' . 'php';
167+
foreach ($this->cacheIds as $cacheId) {
168+
$filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA)
169+
. '/' . $cacheId . '.' . 'php';
142170

143-
if (file_exists($filePath)) {
144-
$this->file->deleteFile($filePath);
171+
if (file_exists($filePath)) {
172+
$this->file->deleteFile($filePath);
173+
}
145174
}
146175
}
147176
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ public function loadScopedVirtualTypes($scopePriorityScheme, $loadedScopes, $plu
227227
$data = $this->reader->read($scopeCode) ?: [];
228228
unset($data['preferences']);
229229
if (count($data) > 0) {
230-
$inherited = [];
231-
$processed = [];
232230
$pluginData = $this->merge($data, $pluginData);
233231
foreach ($data as $class => $config) {
234232
if (isset($config['type'])) {
235233
$virtualTypes[] = $class;
236234
}
237235
}
238236
}
237+
$inherited = [];
238+
$processed = [];
239239
$loadedScopes[$scopeCode] = true;
240240
}
241241
if ($this->isCurrentScope($scopeCode)) {

0 commit comments

Comments
 (0)