Skip to content

Commit ffe156b

Browse files
author
George Babarus
committed
refactor deployment config reader, change inconsistent load method to constructor structure
1 parent 50a085d commit ffe156b

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
/**
1717
* Deployment configuration reader.
1818
* Loads the merged configuration from config files.
19-
*
2019
* @see FileReader The reader for specific configuration file
2120
*/
2221
class Reader
@@ -107,11 +106,9 @@ public function load($fileKey = null)
107106
}
108107
}
109108
} else {
110-
$configFiles = $this->configFilePool->getPaths();
111-
$allFilesData = [];
112-
$result = [];
113-
foreach (array_keys($configFiles) as $fileKey) {
114-
$configFile = $path . '/' . $this->configFilePool->getPath($fileKey);
109+
$configFiles = $this->getFiles();
110+
foreach ($configFiles as $file) {
111+
$configFile = $path . DIRECTORY_SEPARATOR . $file;
115112
if ($fileDriver->isExists($configFile)) {
116113
$fileData = include $configFile;
117114
if (!is_array($fileData)) {
@@ -120,7 +117,6 @@ public function load($fileKey = null)
120117
} else {
121118
continue;
122119
}
123-
$allFilesData[$configFile] = $fileData;
124120
if ($fileData) {
125121
$result = array_replace_recursive($result, $fileData);
126122
}
@@ -136,6 +132,8 @@ public function load($fileKey = null)
136132
* @param string $pathConfig The path config
137133
* @param bool $ignoreInitialConfigFiles Whether ignore custom pools
138134
* @return array
135+
* @throws FileSystemException
136+
* @throws RuntimeException
139137
* @deprecated 100.2.0 Magento does not support custom config file pools since 2.2.0 version
140138
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
141139
*/

lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ReaderTest.php

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ protected function setUp()
4343
->willReturn(__DIR__ . '/_files');
4444
$this->fileDriver = $this->createMock(File::class);
4545
$this->fileDriver
46-
->expects($this->any())
4746
->method('isExists')
48-
->will($this->returnValueMap([
49-
[__DIR__ . '/_files/config.php', true],
50-
[__DIR__ . '/_files/custom.php', true],
51-
[__DIR__ . '/_files/duplicateConfig.php', true],
52-
[__DIR__ . '/_files/env.php', true],
53-
[__DIR__ . '/_files/mergeOne.php', true],
54-
[__DIR__ . '/_files/mergeTwo.php', true],
55-
[__DIR__ . '/_files/nonexistent.php', false]
56-
]));
47+
->willReturnMap(
48+
[
49+
[__DIR__.'/_files/config.php', true],
50+
[__DIR__.'/_files/custom.php', true],
51+
[__DIR__.'/_files/duplicateConfig.php', true],
52+
[__DIR__.'/_files/env.php', true],
53+
[__DIR__.'/_files/mergeOne.php', true],
54+
[__DIR__.'/_files/mergeTwo.php', true],
55+
[__DIR__.'/_files/nonexistent.php', false]
56+
]
57+
);
5758
$this->driverPool = $this->createMock(DriverPool::class);
5859
$this->driverPool
5960
->expects($this->any())
@@ -152,8 +153,9 @@ public function testLoadInvalidConfigurationFileWithFileKey()
152153
* @expectedException \Magento\Framework\Exception\RuntimeException
153154
* @expectedExceptionMessageRegExp /Invalid configuration file: \'.*\/\_files\/emptyConfig\.php\'/
154155
* @return void
156+
* @throws \Magento\Framework\Exception\FileSystemException
155157
*/
156-
public function testLoadInvalidConfigurationFile()
158+
public function testLoadInvalidConfigurationFile(): void
157159
{
158160
$fileDriver = $this->getMockBuilder(File::class)
159161
->disableOriginalConstructor()
@@ -173,23 +175,14 @@ public function testLoadInvalidConfigurationFile()
173175
$configFilePool = $this->getMockBuilder(ConfigFilePool::class)
174176
->disableOriginalConstructor()
175177
->getMock();
176-
$configFilePool->expects($this->exactly(2))
178+
$configFilePool->expects($this->once())
177179
->method('getPaths')
178180
->willReturn(
179181
[
180182
'configKeyOne' => 'config.php',
181183
'testConfig' => 'emptyConfig.php'
182184
]
183185
);
184-
$configFilePool->expects($this->exactly(2))
185-
->method('getPath')
186-
->withConsecutive(
187-
[$this->identicalTo('configKeyOne')],
188-
[$this->identicalTo('testConfig')]
189-
)->willReturnOnConsecutiveCalls(
190-
'config.php',
191-
'emptyConfig.php'
192-
);
193186
$object = new Reader($this->dirList, $driverPool, $configFilePool);
194187
$object->load();
195188
}

0 commit comments

Comments
 (0)