Skip to content

Commit 069fa71

Browse files
committed
MAGETWO-97247: Impossible to enable shared catalog through cli command
1 parent 66a0a5d commit 069fa71

File tree

3 files changed

+57
-71
lines changed

3 files changed

+57
-71
lines changed

app/code/Magento/Config/Console/Command/ConfigSet/DefaultProcessor.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\App\Config\ConfigPathResolver;
1212
use Magento\Framework\App\DeploymentConfig;
1313
use Magento\Framework\App\ObjectManager;
14-
use Magento\Framework\App\ScopeResolverPool;
1514
use Magento\Framework\Exception\CouldNotSaveException;
1615
use Magento\Config\Model\PreparedValueFactory;
1716

@@ -47,11 +46,6 @@ class DefaultProcessor implements ConfigSetProcessorInterface
4746
*/
4847
private $preparedValueFactory;
4948

50-
/**
51-
* @var ScopeResolverPool
52-
*/
53-
private $scopeResolverPool;
54-
5549
/**
5650
* @var ConfigFactory
5751
*/
@@ -61,21 +55,18 @@ class DefaultProcessor implements ConfigSetProcessorInterface
6155
* @param PreparedValueFactory $preparedValueFactory The factory for prepared value
6256
* @param DeploymentConfig $deploymentConfig The deployment configuration reader
6357
* @param ConfigPathResolver $configPathResolver The resolver for configuration paths according to source type
64-
* @param ScopeResolverPool|null $scopeResolverPool
6558
* @param ConfigFactory|null $configFactory
6659
*/
6760
public function __construct(
6861
PreparedValueFactory $preparedValueFactory,
6962
DeploymentConfig $deploymentConfig,
7063
ConfigPathResolver $configPathResolver,
71-
ScopeResolverPool $scopeResolverPool = null,
7264
ConfigFactory $configFactory = null
7365
) {
7466
$this->preparedValueFactory = $preparedValueFactory;
7567
$this->deploymentConfig = $deploymentConfig;
7668
$this->configPathResolver = $configPathResolver;
7769

78-
$this->scopeResolverPool = $scopeResolverPool ?? ObjectManager::getInstance()->get(ScopeResolverPool::class);
7970
$this->configFactory = $configFactory ?? ObjectManager::getInstance()->get(ConfigFactory::class);
8071
}
8172

@@ -99,12 +90,9 @@ public function process($path, $value, $scope, $scopeCode)
9990
}
10091

10192
try {
102-
$resolvedScope = $this->scopeResolverPool->get($scope)
103-
->getScope($scopeCode);
10493
$config = $this->configFactory->create([
105-
'scope' => $resolvedScope->getScopeType(),
106-
'scope_id' => $resolvedScope->getId(),
107-
'scope_code' => $resolvedScope->getCode(),
94+
'scope' => $scope,
95+
'scope_code' => $scopeCode,
10896
]);
10997
$config->setDataByPath($path, $value);
11098
$config->save();

app/code/Magento/Config/Model/Config.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class Config extends \Magento\Framework\DataObject
119119
* @param Config\Reader\Source\Deployed\SettingChecker|null $settingChecker
120120
* @param array $data
121121
* @param ScopeResolverPool|null $scopeResolverPool
122+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
122123
*/
123124
public function __construct(
124125
\Magento\Framework\App\Config\ReinitableConfigInterface $config,
@@ -529,7 +530,7 @@ public function setDataByPath($path, $value)
529530
}
530531

531532
/**
532-
* Resolve scope data
533+
* Set scope data
533534
*
534535
* @return void
535536
*/
@@ -545,35 +546,48 @@ private function initScope()
545546
$this->setStore('');
546547
}
547548

548-
if ($this->getScope() && $this->getScopeId() && $this->getScopeCode()) {
549+
if ($this->getScope()) {
549550
$scope = $this->scopeResolverPool->get($this->getScope())
550-
->getScope($this->getScopeId());
551+
->getScope($this->getScopeCode());
551552
if (StoreScopeInterface::SCOPE_WEBSITE === $scope->getScopeType()) {
552553
$this->setWebsite($scope->getId());
553554
} elseif (StoreScopeInterface::SCOPE_STORE === $scope->getScopeType()) {
554555
$this->setStore($scope->getId());
555556
}
557+
$this->setScopeId($scope->getId());
556558
} else {
557-
switch (true) {
558-
case $this->getStore():
559-
$scope = $this->scopeResolverPool->get(StoreScopeInterface::SCOPE_STORE)
560-
->getScope($this->getStore());
561-
break;
562-
case $this->getWebsite():
563-
$scope = $this->scopeResolverPool->get(StoreScopeInterface::SCOPE_WEBSITE)
564-
->getScope($this->getWebsite());
565-
break;
566-
default:
567-
$scope = $this->scopeResolverPool->get(ScopeInterface::SCOPE_DEFAULT)
568-
->getScope(0);
569-
break;
570-
}
559+
$scope = $this->resolveScope();
571560
$this->setScope($scope->getScopeType());
572561
$this->setScopeId($scope->getId());
573562
$this->setScopeCode($scope->getCode());
574563
}
575564
}
576565

566+
/**
567+
* Resolve scope
568+
*
569+
* @return ScopeInterface
570+
*/
571+
private function resolveScope(): ScopeInterface
572+
{
573+
switch (true) {
574+
case $this->getStore():
575+
$scope = $this->scopeResolverPool->get(StoreScopeInterface::SCOPE_STORE)
576+
->getScope($this->getStore());
577+
break;
578+
case $this->getWebsite():
579+
$scope = $this->scopeResolverPool->get(StoreScopeInterface::SCOPE_WEBSITE)
580+
->getScope($this->getWebsite());
581+
break;
582+
default:
583+
$scope = $this->scopeResolverPool->get(ScopeInterface::SCOPE_DEFAULT)
584+
->getScope(0);
585+
break;
586+
}
587+
588+
return $scope;
589+
}
590+
577591
/**
578592
* Return formatted config data for current section
579593
*

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/DefaultProcessorTest.php

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
use Magento\Config\App\Config\Type\System;
99
use Magento\Config\Console\Command\ConfigSet\DefaultProcessor;
10+
use Magento\Config\Model\Config;
11+
use Magento\Config\Model\Config\Factory as ConfigFactory;
1012
use Magento\Framework\App\Config\ConfigPathResolver;
1113
use Magento\Framework\App\Config\ScopeConfigInterface;
1214
use Magento\Framework\App\DeploymentConfig;
1315
use Magento\Store\Model\ScopeInterface;
1416
use Magento\Config\Model\PreparedValueFactory;
1517
use Magento\Framework\App\Config\Value;
16-
use Magento\Framework\App\Config\ValueInterface;
1718
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
1819
use PHPUnit_Framework_MockObject_MockObject as Mock;
1920

@@ -55,17 +56,18 @@ class DefaultProcessorTest extends \PHPUnit\Framework\TestCase
5556
*/
5657
private $resourceModelMock;
5758

59+
/**
60+
* @var ConfigFactory|Mock
61+
*/
62+
private $configFactory;
63+
5864
/**
5965
* @inheritdoc
6066
*/
6167
protected function setUp()
6268
{
63-
$this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
64-
->disableOriginalConstructor()
65-
->getMock();
66-
$this->configPathResolverMock = $this->getMockBuilder(ConfigPathResolver::class)
67-
->disableOriginalConstructor()
68-
->getMock();
69+
$this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
70+
$this->configPathResolverMock = $this->createMock(ConfigPathResolver::class);
6971
$this->resourceModelMock = $this->getMockBuilder(AbstractDb::class)
7072
->disableOriginalConstructor()
7173
->setMethods(['save'])
@@ -74,14 +76,14 @@ protected function setUp()
7476
->disableOriginalConstructor()
7577
->setMethods(['getResource'])
7678
->getMock();
77-
$this->preparedValueFactoryMock = $this->getMockBuilder(PreparedValueFactory::class)
78-
->disableOriginalConstructor()
79-
->getMock();
79+
$this->preparedValueFactoryMock = $this->createMock(PreparedValueFactory::class);
80+
$this->configFactory = $this->createMock(ConfigFactory::class);
8081

8182
$this->model = new DefaultProcessor(
8283
$this->preparedValueFactoryMock,
8384
$this->deploymentConfigMock,
84-
$this->configPathResolverMock
85+
$this->configPathResolverMock,
86+
$this->configFactory
8587
);
8688
}
8789

@@ -98,15 +100,16 @@ public function testProcess($path, $value, $scope, $scopeCode)
98100
{
99101
$this->configMockForProcessTest($path, $scope, $scopeCode);
100102

101-
$this->preparedValueFactoryMock->expects($this->once())
103+
$config = $this->createMock(Config::class);
104+
$this->configFactory->expects($this->once())
102105
->method('create')
103-
->willReturn($this->valueMock);
104-
$this->valueMock->expects($this->once())
105-
->method('getResource')
106-
->willReturn($this->resourceModelMock);
107-
$this->resourceModelMock->expects($this->once())
106+
->with(['scope' => $scope, 'scope_code' => $scopeCode])
107+
->willReturn($config);
108+
$config->expects($this->once())
109+
->method('setDataByPath')
110+
->with($path, $value);
111+
$config->expects($this->once())
108112
->method('save')
109-
->with($this->valueMock)
110113
->willReturnSelf();
111114

112115
$this->model->process($path, $value, $scope, $scopeCode);
@@ -124,28 +127,6 @@ public function processDataProvider()
124127
];
125128
}
126129

127-
public function testProcessWithWrongValueInstance()
128-
{
129-
$path = 'test/test/test';
130-
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
131-
$scopeCode = null;
132-
$value = 'value';
133-
$valueInterfaceMock = $this->getMockBuilder(ValueInterface::class)
134-
->getMockForAbstractClass();
135-
136-
$this->configMockForProcessTest($path, $scope, $scopeCode);
137-
138-
$this->preparedValueFactoryMock->expects($this->once())
139-
->method('create')
140-
->willReturn($valueInterfaceMock);
141-
$this->valueMock->expects($this->never())
142-
->method('getResource');
143-
$this->resourceModelMock->expects($this->never())
144-
->method('save');
145-
146-
$this->model->process($path, $value, $scope, $scopeCode);
147-
}
148-
149130
/**
150131
* @param string $path
151132
* @param string $scope
@@ -185,6 +166,9 @@ public function testProcessLockedValue()
185166
->method('resolve')
186167
->willReturn('system/default/test/test/test');
187168

169+
$this->configFactory->expects($this->never())
170+
->method('create');
171+
188172
$this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
189173
}
190174
}

0 commit comments

Comments
 (0)