Skip to content

Commit 49be96f

Browse files
committed
MC-31618: Move static config to files - PLUGIN_LIST
- Add integration test for multiple scopes;
1 parent 8ce092e commit 49be96f

File tree

4 files changed

+151
-17
lines changed

4 files changed

+151
-17
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Interception;
9+
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Filesystem\DriverInterface;
12+
use Magento\TestFramework\Application;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
15+
class PluginListGeneratorMultipleScopesTest extends \PHPUnit\Framework\TestCase
16+
{
17+
/**
18+
* Generated plugin list configs for frontend, adminhtml, graphql scopes
19+
*/
20+
private $cacheIds = [
21+
'primary|global|frontend|plugin-list',
22+
'primary|global|adminhtml|plugin-list',
23+
'primary|global|graphql|plugin-list'
24+
];
25+
26+
/**
27+
* @var PluginListGenerator
28+
*/
29+
private $model;
30+
31+
/**
32+
* @var DirectoryList
33+
*/
34+
private $directoryList;
35+
36+
/**
37+
* @var DriverInterface
38+
*/
39+
private $file;
40+
41+
/**
42+
* @var Application
43+
*/
44+
private $application;
45+
46+
/**
47+
* @inheritDoc
48+
*/
49+
protected function setUp(): void
50+
{
51+
$this->application = Bootstrap::getInstance()->getBootstrap()->getApplication();
52+
$this->directoryList = new DirectoryList(BP, $this->getCustomDirs());
53+
$this->file = Bootstrap::getObjectManager()->create(DriverInterface::class);
54+
$reader = Bootstrap::getObjectManager()->create(
55+
// phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found."
56+
\Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class
57+
);
58+
$scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class);
59+
$omConfig = Bootstrap::getObjectManager()->create(
60+
\Magento\Framework\Interception\ObjectManager\Config\Developer::class
61+
);
62+
$relations = Bootstrap::getObjectManager()->create(
63+
\Magento\Framework\ObjectManager\Relations\Runtime::class
64+
);
65+
$definitions = Bootstrap::getObjectManager()->create(
66+
\Magento\Framework\Interception\Definition\Runtime::class
67+
);
68+
$classDefinitions = Bootstrap::getObjectManager()->create(
69+
\Magento\Framework\ObjectManager\Definition\Runtime::class
70+
);
71+
// phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found."
72+
$logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class);
73+
$this->model = new PluginListGenerator(
74+
$reader,
75+
$scopeConfig,
76+
$omConfig,
77+
$relations,
78+
$definitions,
79+
$classDefinitions,
80+
$logger,
81+
$this->directoryList,
82+
['primary', 'global']
83+
);
84+
}
85+
86+
/**
87+
* Test multiple scopes plugin list configuration generation and load.
88+
*/
89+
public function testPluginListMultipleScopesConfigGeneration()
90+
{
91+
$scopes = ['frontend', 'adminhtml', 'graphql'];
92+
$this->model->write($scopes);
93+
94+
foreach ($this->cacheIds as $cacheId) {
95+
$configData = $this->model->load($cacheId);
96+
$this->assertNotEmpty($configData[0]);
97+
$this->assertNotEmpty($configData[1]);
98+
$this->assertNotEmpty($configData[2]);
99+
}
100+
}
101+
102+
/**
103+
* Gets customized directory paths
104+
*
105+
* @return array
106+
*/
107+
private function getCustomDirs()
108+
{
109+
$path = DirectoryList::PATH;
110+
$generated = "{$this->application->getTempDir()}/generated";
111+
112+
return [
113+
DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"],
114+
];
115+
}
116+
117+
/**
118+
* @inheritDoc
119+
*/
120+
protected function tearDown(): void
121+
{
122+
foreach ($this->cacheIds as $cacheId) {
123+
$filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA)
124+
. '/' . $cacheId . '.' . 'php';
125+
126+
if (file_exists($filePath)) {
127+
$this->file->deleteFile($filePath);
128+
}
129+
}
130+
}
131+
}

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,26 @@ protected function setUp(): void
4646
{
4747
$this->application = Bootstrap::getInstance()->getBootstrap()->getApplication();
4848
$this->directoryList = new DirectoryList(BP, $this->getCustomDirs());
49-
$this->file = new \Magento\Framework\Filesystem\Driver\File();
50-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
51-
$reader = new \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy($objectManager);
52-
$areaList = $this->createMock(\Magento\Framework\App\AreaList::class);
53-
$areaList->method('getCodes')->willReturn([]);
54-
$scopeConfig = new \Magento\Framework\Config\Scope($areaList, 'global');
55-
$omConfig = new \Magento\Framework\Interception\ObjectManager\Config\Developer();
56-
$relations = new \Magento\Framework\ObjectManager\Relations\Runtime();
57-
$definitions = new \Magento\Framework\Interception\Definition\Runtime();
58-
$classDefinitions = new \Magento\Framework\ObjectManager\Definition\Runtime();
59-
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
49+
$this->file = Bootstrap::getObjectManager()->create(DriverInterface::class);
50+
$reader = Bootstrap::getObjectManager()->create(
51+
// phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found."
52+
\Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class
53+
);
54+
$scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class);
55+
$omConfig = Bootstrap::getObjectManager()->create(
56+
\Magento\Framework\Interception\ObjectManager\Config\Developer::class
57+
);
58+
$relations = Bootstrap::getObjectManager()->create(
59+
\Magento\Framework\ObjectManager\Relations\Runtime::class
60+
);
61+
$definitions = Bootstrap::getObjectManager()->create(
62+
\Magento\Framework\Interception\Definition\Runtime::class
63+
);
64+
$classDefinitions = Bootstrap::getObjectManager()->create(
65+
\Magento\Framework\ObjectManager\Definition\Runtime::class
66+
);
67+
// phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found."
68+
$logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class);
6069
$this->model = new PluginListGenerator(
6170
$reader,
6271
$scopeConfig,

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Magento\Framework\Interception;
99

10-
use Magento\Framework\Exception\FileSystemException;
11-
1210
/**
1311
* Interception configuration loader interface.
1412
*/
@@ -19,7 +17,6 @@ interface ConfigLoaderInterface
1917
*
2018
* @param string $cacheId
2119
* @return array
22-
* @throws FileSystemException
2320
*/
2421
public function load(string $cacheId): array;
2522
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Magento\Framework\Interception;
99

10-
use Magento\Framework\Exception\FileSystemException;
11-
1210
/**
1311
* Interception config writer interface.
1412
*/
@@ -19,7 +17,6 @@ interface ConfigWriterInterface
1917
*
2018
* @param array $scopes
2119
* @return void
22-
* @throws FileSystemException
2320
*/
2421
public function write(array $scopes): void;
2522
}

0 commit comments

Comments
 (0)