Skip to content

Commit d1c3981

Browse files
committed
MC-36785: Unable to set YouTube API key by CLI
1 parent e7e156c commit d1c3981

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

app/code/Magento/Config/App/Config/Source/ModularConfigSource.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Config\Model\Config\Structure\Reader as ConfigStructureReader;
99
use Magento\Framework\App\Area;
1010
use Magento\Framework\App\Config\ConfigSourceInterface;
11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\DataObject;
1213
use Magento\Framework\App\Config\Initial\Reader as InitialConfigReader;
1314

@@ -31,14 +32,15 @@ class ModularConfigSource implements ConfigSourceInterface
3132

3233
/**
3334
* @param InitialConfigReader $initialConfigReader
34-
* @param ConfigStructureReader $configStructureReader
35+
* @param ConfigStructureReader|null $configStructureReader
3536
*/
3637
public function __construct(
3738
InitialConfigReader $initialConfigReader,
38-
ConfigStructureReader $configStructureReader
39+
?ConfigStructureReader $configStructureReader = null
3940
) {
4041
$this->initialConfigReader = $initialConfigReader;
41-
$this->configStructureReader = $configStructureReader;
42+
$this->configStructureReader = $configStructureReader
43+
?? ObjectManager::getInstance()->get(ConfigStructureReader::class);
4244
}
4345

4446
/**
@@ -63,18 +65,6 @@ public function get($path = '')
6365
return $data->getData('data' . $path) ?: [];
6466
}
6567

66-
private function addPathKey(array $data, string $path): array
67-
{
68-
if (strpos($path, '/') !== false) {
69-
list ($key, $subPath) = explode('/', $path, 2);
70-
$data[$key] = $this->addPathKey($data[$key] ?? [], $subPath);
71-
} else {
72-
$data += [$path => null];
73-
}
74-
75-
return $data;
76-
}
77-
7868
/**
7969
* Merge initial config with config structure
8070
*
@@ -84,7 +74,7 @@ private function addPathKey(array $data, string $path): array
8474
*/
8575
private function merge(array $config, array $sections): array
8676
{
87-
foreach ($sections as $key => $section) {
77+
foreach ($sections as $section) {
8878
if (isset($section['children'])) {
8979
$config[$section['id']] = $this->merge(
9080
$config[$section['id']] ?? [],

app/code/Magento/Config/Test/Unit/App/Config/Source/ModularConfigSourceTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
namespace Magento\Config\Test\Unit\App\Config\Source;
99

1010
use Magento\Config\App\Config\Source\ModularConfigSource;
11-
use Magento\Framework\App\Config\Initial\Reader;
11+
use Magento\Config\Model\Config\Structure\Reader as ConfigStructureReader;
12+
use Magento\Framework\App\Config\Initial\Reader as InitialConfigReader;
1213
use PHPUnit\Framework\MockObject\MockObject;
1314
use PHPUnit\Framework\TestCase;
1415

@@ -18,9 +19,14 @@
1819
class ModularConfigSourceTest extends TestCase
1920
{
2021
/**
21-
* @var Reader|MockObject
22+
* @var InitialConfigReader|MockObject
2223
*/
23-
private $reader;
24+
private $initialConfigReader;
25+
26+
/**
27+
* @var ConfigStructureReader|MockObject
28+
*/
29+
private $configStructureReader;
2430

2531
/**
2632
* @var ModularConfigSource
@@ -29,15 +35,17 @@ class ModularConfigSourceTest extends TestCase
2935

3036
protected function setUp(): void
3137
{
32-
$this->reader = $this->getMockBuilder(Reader::class)
33-
->disableOriginalConstructor()
34-
->getMock();
35-
$this->source = new ModularConfigSource($this->reader);
38+
$this->initialConfigReader = $this->createMock(InitialConfigReader::class);
39+
$this->configStructureReader = $this->createMock(ConfigStructureReader::class);
40+
$this->source = new ModularConfigSource(
41+
$this->initialConfigReader,
42+
$this->configStructureReader
43+
);
3644
}
3745

3846
public function testGet()
3947
{
40-
$this->reader->expects($this->once())
48+
$this->initialConfigReader->expects($this->once())
4149
->method('read')
4250
->willReturn(['data' => ['path' => 'value']]);
4351
$this->assertEquals('value', $this->source->get('path'));

0 commit comments

Comments
 (0)