Skip to content

Commit 43c21fc

Browse files
committed
MC-31618: Move static config to files - PLUGIN_LIST
- Add integration test with app isolation;
1 parent 07d6a66 commit 43c21fc

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Interception;
8+
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem\DriverInterface;
11+
use Magento\TestFramework\Application;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/**
15+
* @magentoAppIsolation enabled
16+
*/
17+
class PluginListGeneratorTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* Generated plugin list config for frontend scope
21+
*/
22+
const CACHE_ID = 'primary|global|frontend|plugin-list';
23+
24+
/**
25+
* @var PluginListGenerator
26+
*/
27+
private $model;
28+
29+
/**
30+
* @var DirectoryList
31+
*/
32+
private $directoryList;
33+
34+
/**
35+
* @var DriverInterface
36+
*/
37+
private $file;
38+
39+
/**
40+
* @var Application
41+
*/
42+
private $application;
43+
44+
/**
45+
* @inheritDoc
46+
*/
47+
protected function setUp(): void
48+
{
49+
$this->application = Bootstrap::getInstance()->getBootstrap()->getApplication();
50+
$this->directoryList = new DirectoryList(BP, $this->getCustomDirs());
51+
$this->file = Bootstrap::getObjectManager()->create(DriverInterface::class);
52+
$reader = Bootstrap::getObjectManager()->create(
53+
// phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found."
54+
\Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class
55+
);
56+
$scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class);
57+
$omConfig = Bootstrap::getObjectManager()->create(
58+
\Magento\Framework\Interception\ObjectManager\Config\Developer::class
59+
);
60+
$relations = Bootstrap::getObjectManager()->create(
61+
\Magento\Framework\ObjectManager\Relations\Runtime::class
62+
);
63+
$definitions = Bootstrap::getObjectManager()->create(
64+
\Magento\Framework\Interception\Definition\Runtime::class
65+
);
66+
$classDefinitions = Bootstrap::getObjectManager()->create(
67+
\Magento\Framework\ObjectManager\Definition\Runtime::class
68+
);
69+
// phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found."
70+
$logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class);
71+
$this->model = new PluginListGenerator(
72+
$reader,
73+
$scopeConfig,
74+
$omConfig,
75+
$relations,
76+
$definitions,
77+
$classDefinitions,
78+
$logger,
79+
$this->directoryList,
80+
['primary', 'global']
81+
);
82+
}
83+
84+
/**
85+
* Test plugin list configuration generation and load.
86+
*/
87+
public function testPluginListConfigGeneration()
88+
{
89+
$scopes = ['frontend'];
90+
$this->model->write($scopes);
91+
$configData = $this->model->load(self::CACHE_ID);
92+
$this->assertNotEmpty($configData[0]);
93+
$this->assertNotEmpty($configData[1]);
94+
$this->assertNotEmpty($configData[2]);
95+
$expected = [
96+
1 => [
97+
0 => 'genericHeaderPlugin',
98+
1 => 'asyncCssLoad',
99+
2 => 'response-http-page-cache'
100+
]
101+
];
102+
// Here in test is assumed that this class below has 3 plugins. But the amount of plugins and class itself
103+
// may vary. If it is changed, please update these assertions.
104+
$this->assertArrayHasKey(
105+
'Magento\\Framework\\App\\Response\\Http_sendResponse___self',
106+
$configData[2],
107+
'Processed plugin does not exist in the processed plugins array.'
108+
);
109+
$this->assertSame(
110+
$expected,
111+
$configData[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'],
112+
'Plugin configurations are not equal'
113+
);
114+
}
115+
116+
/**
117+
* Gets customized directory paths
118+
*
119+
* @return array
120+
*/
121+
private function getCustomDirs()
122+
{
123+
$path = DirectoryList::PATH;
124+
$generated = "{$this->application->getTempDir()}/generated";
125+
126+
return [
127+
DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"],
128+
];
129+
}
130+
131+
/**
132+
* @inheritDoc
133+
*/
134+
protected function tearDown(): void
135+
{
136+
$filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA)
137+
. '/' . self::CACHE_ID . '.' . 'php';
138+
139+
if (file_exists($filePath)) {
140+
$this->file->deleteFile($filePath);
141+
}
142+
}
143+
}

0 commit comments

Comments
 (0)