Skip to content

Commit b58256d

Browse files
MAGETWO-97393: Impossible to enable shared catalog through cli command
1 parent 4d451f8 commit b58256d

File tree

3 files changed

+105
-84
lines changed

3 files changed

+105
-84
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,10 @@ public function testProcess($path, $value, $scope, $scopeCode)
101101
$this->configMockForProcessTest($path, $scope, $scopeCode);
102102

103103
$config = $this->createMock(Config::class);
104-
$this->configFactory->expects($this->once())
105-
->method('create')
104+
$this->configFactory->method('create')
106105
->with(['scope' => $scope, 'scope_code' => $scopeCode])
107106
->willReturn($config);
108-
$config->expects($this->once())
109-
->method('setDataByPath')
107+
$config->method('setDataByPath')
110108
->with($path, $value);
111109
$config->expects($this->once())
112110
->method('save')

app/code/Magento/Config/Test/Unit/Model/ConfigTest.php

Lines changed: 101 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,127 +5,140 @@
55
*/
66
namespace Magento\Config\Test\Unit\Model;
77

8-
use PHPUnit\Framework\MockObject\MockObject;
8+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
9+
use Magento\Config\Model\Config;
10+
use Magento\Framework\App\Config\ReinitableConfigInterface;
11+
use Magento\Framework\Event\ManagerInterface;
12+
use Magento\Config\Model\Config\Structure\Reader;
13+
use Magento\Framework\DB\TransactionFactory;
14+
use Magento\Config\Model\Config\Loader;
15+
use Magento\Framework\App\Config\ValueFactory;
16+
use Magento\Store\Model\StoreManagerInterface;
17+
use Magento\Config\Model\Config\Structure;
18+
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
19+
use Magento\Framework\App\ScopeResolverPool;
20+
use Magento\Framework\App\ScopeResolverInterface;
21+
use Magento\Framework\App\ScopeInterface;
22+
use Magento\Store\Model\ScopeTypeNormalizer;
23+
use Magento\Framework\DB\Transaction;
24+
use Magento\Framework\App\Config\Value;
25+
use Magento\Store\Model\Website;
26+
use Magento\Config\Model\Config\Structure\Element\Group;
27+
use Magento\Config\Model\Config\Structure\Element\Field;
928

1029
/**
1130
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1231
*/
1332
class ConfigTest extends \PHPUnit\Framework\TestCase
1433
{
1534
/**
16-
* @var \Magento\Config\Model\Config
35+
* @var Config
1736
*/
1837
private $model;
1938

2039
/**
21-
* @var \Magento\Framework\Event\ManagerInterface|MockObject
40+
* @var ManagerInterface|MockObject
2241
*/
2342
private $eventManagerMock;
2443

2544
/**
26-
* @var \Magento\Config\Model\Config\Structure\Reader|MockObject
45+
* @var Reader|MockObject
2746
*/
2847
private $structureReaderMock;
2948

3049
/**
31-
* @var \Magento\Framework\DB\TransactionFactory|MockObject
50+
* @var TransactionFactory|MockObject
3251
*/
3352
private $transFactoryMock;
3453

3554
/**
36-
* @var \Magento\Framework\App\Config\ReinitableConfigInterface|MockObject
55+
* @var ReinitableConfigInterface|MockObject
3756
*/
3857
private $appConfigMock;
3958

4059
/**
41-
* @var \Magento\Config\Model\Config\Loader|MockObject
60+
* @var Loader|MockObject
4261
*/
4362
private $configLoaderMock;
4463

4564
/**
46-
* @var \Magento\Framework\App\Config\ValueFactory|MockObject
65+
* @var ValueFactory|MockObject
4766
*/
4867
private $dataFactoryMock;
4968

5069
/**
51-
* @var \Magento\Store\Model\StoreManagerInterface|MockObject
70+
* @var StoreManagerInterface|MockObject
5271
*/
5372
private $storeManager;
5473

5574
/**
56-
* @var \Magento\Config\Model\Config\Structure|MockObject
75+
* @var Structure|MockObject
5776
*/
5877
private $configStructure;
5978

6079
/**
61-
* @var \Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker|MockObject
80+
* @var SettingChecker|MockObject
6281
*/
6382
private $settingsChecker;
6483

6584
/**
66-
* @var \Magento\Framework\App\ScopeResolverPool|MockObject
85+
* @var ScopeResolverPool|MockObject
6786
*/
6887
private $scopeResolverPool;
6988

7089
/**
71-
* @var \Magento\Framework\App\ScopeResolverInterface|MockObject
90+
* @var ScopeResolverInterface|MockObject
7291
*/
7392
private $scopeResolver;
7493

7594
/**
76-
* @var \Magento\Framework\App\ScopeInterface|MockObject
95+
* @var ScopeInterface|MockObject
7796
*/
7897
private $scope;
7998

8099
/**
81-
* @var \Magento\Store\Model\ScopeTypeNormalizer|MockObject
100+
* @var ScopeTypeNormalizer|MockObject
82101
*/
83102
private $scopeTypeNormalizer;
84103

85104
protected function setUp()
86105
{
87-
$this->eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
106+
$this->eventManagerMock = $this->createMock(ManagerInterface::class);
88107
$this->structureReaderMock = $this->createPartialMock(
89-
\Magento\Config\Model\Config\Structure\Reader::class,
108+
Reader::class,
90109
['getConfiguration']
91110
);
92-
$this->configStructure = $this->createMock(\Magento\Config\Model\Config\Structure::class);
111+
$this->configStructure = $this->createMock(Structure::class);
93112

94-
$this->structureReaderMock->expects(
95-
$this->any()
96-
)->method(
97-
'getConfiguration'
98-
)->will(
99-
$this->returnValue($this->configStructure)
100-
);
113+
$this->structureReaderMock->method('getConfiguration')
114+
->willReturn($this->configStructure);
101115

102116
$this->transFactoryMock = $this->createPartialMock(
103-
\Magento\Framework\DB\TransactionFactory::class,
117+
TransactionFactory::class,
104118
['create', 'addObject']
105119
);
106-
$this->appConfigMock = $this->createMock(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
120+
$this->appConfigMock = $this->createMock(ReinitableConfigInterface::class);
107121
$this->configLoaderMock = $this->createPartialMock(
108-
\Magento\Config\Model\Config\Loader::class,
122+
Loader::class,
109123
['getConfigByPath']
110124
);
111-
$this->dataFactoryMock = $this->createMock(\Magento\Framework\App\Config\ValueFactory::class);
125+
$this->dataFactoryMock = $this->createMock(ValueFactory::class);
112126

113-
$this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
127+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
114128

115-
$this->settingsChecker = $this
116-
->createMock(\Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker::class);
129+
$this->settingsChecker = $this->createMock(SettingChecker::class);
117130

118-
$this->scopeResolverPool = $this->createMock(\Magento\Framework\App\ScopeResolverPool::class);
119-
$this->scopeResolver = $this->createMock(\Magento\Framework\App\ScopeResolverInterface::class);
131+
$this->scopeResolverPool = $this->createMock(ScopeResolverPool::class);
132+
$this->scopeResolver = $this->createMock(ScopeResolverInterface::class);
120133
$this->scopeResolverPool->method('get')
121134
->willReturn($this->scopeResolver);
122-
$this->scope = $this->createMock(\Magento\Framework\App\ScopeInterface::class);
135+
$this->scope = $this->createMock(ScopeInterface::class);
123136
$this->scopeResolver->method('getScope')
124137
->willReturn($this->scope);
125138

126-
$this->scopeTypeNormalizer = $this->createMock(\Magento\Store\Model\ScopeTypeNormalizer::class);
139+
$this->scopeTypeNormalizer = $this->createMock(ScopeTypeNormalizer::class);
127140

128-
$this->model = new \Magento\Config\Model\Config(
141+
$this->model = new Config(
129142
$this->appConfigMock,
130143
$this->eventManagerMock,
131144
$this->configStructure,
@@ -160,11 +173,13 @@ public function testSaveEmptiesNonSetArguments()
160173

161174
public function testSaveToCheckAdminSystemConfigChangedSectionEvent()
162175
{
163-
$transactionMock = $this->createMock(\Magento\Framework\DB\Transaction::class);
176+
$transactionMock = $this->createMock(Transaction::class);
164177

165-
$this->transFactoryMock->expects($this->any())->method('create')->will($this->returnValue($transactionMock));
178+
$this->transFactoryMock->method('create')
179+
->willReturn($transactionMock);
166180

167-
$this->configLoaderMock->expects($this->any())->method('getConfigByPath')->will($this->returnValue([]));
181+
$this->configLoaderMock->method('getConfigByPath')
182+
->willReturn([]);
168183

169184
$this->eventManagerMock->expects(
170185
$this->at(0)
@@ -190,53 +205,64 @@ public function testSaveToCheckAdminSystemConfigChangedSectionEvent()
190205

191206
public function testDoNotSaveReadOnlyFields()
192207
{
193-
$transactionMock = $this->createMock(\Magento\Framework\DB\Transaction::class);
194-
$this->transFactoryMock->expects($this->any())->method('create')->will($this->returnValue($transactionMock));
208+
$transactionMock = $this->createMock(Transaction::class);
209+
$this->transFactoryMock->method('create')
210+
->willReturn($transactionMock);
195211

196-
$this->settingsChecker->expects($this->any())->method('isReadOnly')->will($this->returnValue(true));
197-
$this->configLoaderMock->expects($this->any())->method('getConfigByPath')->will($this->returnValue([]));
212+
$this->settingsChecker->method('isReadOnly')
213+
->willReturn(true);
214+
$this->configLoaderMock->method('getConfigByPath')
215+
->willReturn([]);
198216

199217
$this->model->setGroups(['1' => ['fields' => ['key' => ['data']]]]);
200218
$this->model->setSection('section');
201219

202-
$group = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Group::class);
203-
$group->method('getPath')->willReturn('section/1');
220+
$group = $this->createMock(Group::class);
221+
$group->method('getPath')
222+
->willReturn('section/1');
204223

205-
$field = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Field::class);
206-
$field->method('getGroupPath')->willReturn('section/1');
207-
$field->method('getId')->willReturn('key');
224+
$field = $this->createMock(Field::class);
225+
$field->method('getGroupPath')
226+
->willReturn('section/1');
227+
$field->method('getId')
228+
->willReturn('key');
208229

209230
$this->configStructure->expects($this->at(0))
210231
->method('getElement')
211232
->with('section/1')
212-
->will($this->returnValue($group));
233+
->willReturn($group);
213234
$this->configStructure->expects($this->at(1))
214235
->method('getElement')
215236
->with('section/1')
216-
->will($this->returnValue($group));
237+
->willReturn($group);
217238
$this->configStructure->expects($this->at(2))
218239
->method('getElement')
219240
->with('section/1/key')
220-
->will($this->returnValue($field));
241+
->willReturn($field);
221242

222243
$backendModel = $this->createPartialMock(
223-
\Magento\Framework\App\Config\Value::class,
244+
Value::class,
224245
['addData']
225246
);
226-
$this->dataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($backendModel));
247+
$this->dataFactoryMock->method('create')
248+
->willReturn($backendModel);
227249

228-
$this->transFactoryMock->expects($this->never())->method('addObject');
229-
$backendModel->expects($this->never())->method('addData');
250+
$this->transFactoryMock->expects($this->never())
251+
->method('addObject');
252+
$backendModel->expects($this->never())
253+
->method('addData');
230254

231255
$this->model->save();
232256
}
233257

234258
public function testSaveToCheckScopeDataSet()
235259
{
236-
$transactionMock = $this->createMock(\Magento\Framework\DB\Transaction::class);
237-
$this->transFactoryMock->expects($this->any())->method('create')->will($this->returnValue($transactionMock));
260+
$transactionMock = $this->createMock(Transaction::class);
261+
$this->transFactoryMock->method('create')
262+
->willReturn($transactionMock);
238263

239-
$this->configLoaderMock->expects($this->any())->method('getConfigByPath')->will($this->returnValue([]));
264+
$this->configLoaderMock->method('getConfigByPath')
265+
->willReturn([]);
240266

241267
$this->eventManagerMock->expects($this->at(0))
242268
->method('dispatch')
@@ -251,36 +277,35 @@ public function testSaveToCheckScopeDataSet()
251277
$this->arrayHasKey('store')
252278
);
253279

254-
$group = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Group::class);
280+
$group = $this->createMock(Group::class);
255281
$group->method('getPath')->willReturn('section/1');
256282

257-
$field = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Field::class);
283+
$field = $this->createMock(Field::class);
258284
$field->method('getGroupPath')->willReturn('section/1');
259285
$field->method('getId')->willReturn('key');
260286

261287
$this->configStructure->expects($this->at(0))
262288
->method('getElement')
263289
->with('section/1')
264-
->will($this->returnValue($group));
290+
->willReturn($group);
265291
$this->configStructure->expects($this->at(1))
266292
->method('getElement')
267293
->with('section/1')
268-
->will($this->returnValue($group));
294+
->willReturn($group);
269295
$this->configStructure->expects($this->at(2))
270296
->method('getElement')
271297
->with('section/1/key')
272-
->will($this->returnValue($field));
298+
->willReturn($field);
273299
$this->configStructure->expects($this->at(3))
274300
->method('getElement')
275301
->with('section/1')
276-
->will($this->returnValue($group));
302+
->willReturn($group);
277303
$this->configStructure->expects($this->at(4))
278304
->method('getElement')
279305
->with('section/1/key')
280-
->will($this->returnValue($field));
306+
->willReturn($field);
281307

282-
$this->scopeResolver->expects($this->atLeastOnce())
283-
->method('getScope')
308+
$this->scopeResolver->method('getScope')
284309
->with('1')
285310
->willReturn($this->scope);
286311
$this->scope->expects($this->atLeastOnce())
@@ -296,20 +321,19 @@ public function testSaveToCheckScopeDataSet()
296321
->method('normalize')
297322
->with('website')
298323
->willReturn('websites');
299-
$website = $this->createMock(\Magento\Store\Model\Website::class);
300-
$this->storeManager->expects($this->any())->method('getWebsites')->will($this->returnValue([$website]));
301-
$this->storeManager->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue(true));
324+
$website = $this->createMock(Website::class);
325+
$this->storeManager->method('getWebsites')->willReturn([$website]);
326+
$this->storeManager->method('isSingleStoreMode')->willReturn(true);
302327

303328
$this->model->setWebsite('1');
304329
$this->model->setSection('section');
305330
$this->model->setGroups(['1' => ['fields' => ['key' => ['data']]]]);
306331

307332
$backendModel = $this->createPartialMock(
308-
\Magento\Framework\App\Config\Value::class,
333+
Value::class,
309334
['setPath', 'addData', '__sleep', '__wakeup']
310335
);
311-
$backendModel->expects($this->once())
312-
->method('addData')
336+
$backendModel->method('addData')
313337
->with([
314338
'field' => 'key',
315339
'groups' => [1 => ['fields' => ['key' => ['data']]]],
@@ -323,9 +347,10 @@ public function testSaveToCheckScopeDataSet()
323347
$backendModel->expects($this->once())
324348
->method('setPath')
325349
->with('section/1/key')
326-
->will($this->returnValue($backendModel));
350+
->willReturn($backendModel);
327351

328-
$this->dataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($backendModel));
352+
$this->dataFactoryMock->method('create')
353+
->willReturn($backendModel);
329354

330355
$this->model->save();
331356
}

app/code/Magento/Paypal/Test/Unit/Model/Config/Structure/Element/FieldPluginTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public function testAroundGetConfigPathHasResult()
4747

4848
public function testAroundGetConfigPathNonPaymentSection()
4949
{
50-
$this->subjectMock->expects($this->once())
51-
->method('getPath')
50+
$this->subjectMock->method('getPath')
5251
->willReturn('non-payment/group/field');
5352

5453
$this->assertNull($this->plugin->afterGetConfigPath($this->subjectMock, null));
@@ -62,8 +61,7 @@ public function testAroundGetConfigPathNonPaymentSection()
6261
*/
6362
public function testAroundGetConfigPath($subjectPath, $expectedConfigPath)
6463
{
65-
$this->subjectMock->expects($this->exactly(2))
66-
->method('getPath')
64+
$this->subjectMock->method('getPath')
6765
->willReturn($subjectPath);
6866

6967
$this->assertEquals($expectedConfigPath, $this->plugin->afterGetConfigPath($this->subjectMock, null));

0 commit comments

Comments
 (0)