5
5
*/
6
6
namespace Magento \Config \Test \Unit \Model ;
7
7
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 ;
9
28
10
29
/**
11
30
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12
31
*/
13
32
class ConfigTest extends \PHPUnit \Framework \TestCase
14
33
{
15
34
/**
16
- * @var \Magento\Config\Model\ Config
35
+ * @var Config
17
36
*/
18
37
private $ model ;
19
38
20
39
/**
21
- * @var \Magento\Framework\Event\ ManagerInterface|MockObject
40
+ * @var ManagerInterface|MockObject
22
41
*/
23
42
private $ eventManagerMock ;
24
43
25
44
/**
26
- * @var \Magento\Config\Model\Config\Structure\ Reader|MockObject
45
+ * @var Reader|MockObject
27
46
*/
28
47
private $ structureReaderMock ;
29
48
30
49
/**
31
- * @var \Magento\Framework\DB\ TransactionFactory|MockObject
50
+ * @var TransactionFactory|MockObject
32
51
*/
33
52
private $ transFactoryMock ;
34
53
35
54
/**
36
- * @var \Magento\Framework\App\Config\ ReinitableConfigInterface|MockObject
55
+ * @var ReinitableConfigInterface|MockObject
37
56
*/
38
57
private $ appConfigMock ;
39
58
40
59
/**
41
- * @var \Magento\Config\Model\Config\ Loader|MockObject
60
+ * @var Loader|MockObject
42
61
*/
43
62
private $ configLoaderMock ;
44
63
45
64
/**
46
- * @var \Magento\Framework\App\Config\ ValueFactory|MockObject
65
+ * @var ValueFactory|MockObject
47
66
*/
48
67
private $ dataFactoryMock ;
49
68
50
69
/**
51
- * @var \Magento\Store\Model\ StoreManagerInterface|MockObject
70
+ * @var StoreManagerInterface|MockObject
52
71
*/
53
72
private $ storeManager ;
54
73
55
74
/**
56
- * @var \Magento\Config\Model\Config\ Structure|MockObject
75
+ * @var Structure|MockObject
57
76
*/
58
77
private $ configStructure ;
59
78
60
79
/**
61
- * @var \Magento\Config\Model\Config\Reader\Source\Deployed\ SettingChecker|MockObject
80
+ * @var SettingChecker|MockObject
62
81
*/
63
82
private $ settingsChecker ;
64
83
65
84
/**
66
- * @var \Magento\Framework\App\ ScopeResolverPool|MockObject
85
+ * @var ScopeResolverPool|MockObject
67
86
*/
68
87
private $ scopeResolverPool ;
69
88
70
89
/**
71
- * @var \Magento\Framework\App\ ScopeResolverInterface|MockObject
90
+ * @var ScopeResolverInterface|MockObject
72
91
*/
73
92
private $ scopeResolver ;
74
93
75
94
/**
76
- * @var \Magento\Framework\App\ ScopeInterface|MockObject
95
+ * @var ScopeInterface|MockObject
77
96
*/
78
97
private $ scope ;
79
98
80
99
/**
81
- * @var \Magento\Store\Model\ ScopeTypeNormalizer|MockObject
100
+ * @var ScopeTypeNormalizer|MockObject
82
101
*/
83
102
private $ scopeTypeNormalizer ;
84
103
85
104
protected function setUp ()
86
105
{
87
- $ this ->eventManagerMock = $ this ->createMock (\ Magento \ Framework \ Event \ ManagerInterface::class);
106
+ $ this ->eventManagerMock = $ this ->createMock (ManagerInterface::class);
88
107
$ this ->structureReaderMock = $ this ->createPartialMock (
89
- \ Magento \ Config \ Model \ Config \ Structure \ Reader::class,
108
+ Reader::class,
90
109
['getConfiguration ' ]
91
110
);
92
- $ this ->configStructure = $ this ->createMock (\ Magento \ Config \ Model \ Config \ Structure::class);
111
+ $ this ->configStructure = $ this ->createMock (Structure::class);
93
112
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 );
101
115
102
116
$ this ->transFactoryMock = $ this ->createPartialMock (
103
- \ Magento \ Framework \ DB \ TransactionFactory::class,
117
+ TransactionFactory::class,
104
118
['create ' , 'addObject ' ]
105
119
);
106
- $ this ->appConfigMock = $ this ->createMock (\ Magento \ Framework \ App \ Config \ ReinitableConfigInterface::class);
120
+ $ this ->appConfigMock = $ this ->createMock (ReinitableConfigInterface::class);
107
121
$ this ->configLoaderMock = $ this ->createPartialMock (
108
- \ Magento \ Config \ Model \ Config \ Loader::class,
122
+ Loader::class,
109
123
['getConfigByPath ' ]
110
124
);
111
- $ this ->dataFactoryMock = $ this ->createMock (\ Magento \ Framework \ App \ Config \ ValueFactory::class);
125
+ $ this ->dataFactoryMock = $ this ->createMock (ValueFactory::class);
112
126
113
- $ this ->storeManager = $ this ->createMock (\ Magento \ Store \ Model \ StoreManagerInterface::class);
127
+ $ this ->storeManager = $ this ->createMock (StoreManagerInterface::class);
114
128
115
- $ this ->settingsChecker = $ this
116
- ->createMock (\Magento \Config \Model \Config \Reader \Source \Deployed \SettingChecker::class);
129
+ $ this ->settingsChecker = $ this ->createMock (SettingChecker::class);
117
130
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);
120
133
$ this ->scopeResolverPool ->method ('get ' )
121
134
->willReturn ($ this ->scopeResolver );
122
- $ this ->scope = $ this ->createMock (\ Magento \ Framework \ App \ ScopeInterface::class);
135
+ $ this ->scope = $ this ->createMock (ScopeInterface::class);
123
136
$ this ->scopeResolver ->method ('getScope ' )
124
137
->willReturn ($ this ->scope );
125
138
126
- $ this ->scopeTypeNormalizer = $ this ->createMock (\ Magento \ Store \ Model \ ScopeTypeNormalizer::class);
139
+ $ this ->scopeTypeNormalizer = $ this ->createMock (ScopeTypeNormalizer::class);
127
140
128
- $ this ->model = new \ Magento \ Config \ Model \ Config (
141
+ $ this ->model = new Config (
129
142
$ this ->appConfigMock ,
130
143
$ this ->eventManagerMock ,
131
144
$ this ->configStructure ,
@@ -160,11 +173,13 @@ public function testSaveEmptiesNonSetArguments()
160
173
161
174
public function testSaveToCheckAdminSystemConfigChangedSectionEvent ()
162
175
{
163
- $ transactionMock = $ this ->createMock (\ Magento \ Framework \ DB \ Transaction::class);
176
+ $ transactionMock = $ this ->createMock (Transaction::class);
164
177
165
- $ this ->transFactoryMock ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ transactionMock ));
178
+ $ this ->transFactoryMock ->method ('create ' )
179
+ ->willReturn ($ transactionMock );
166
180
167
- $ this ->configLoaderMock ->expects ($ this ->any ())->method ('getConfigByPath ' )->will ($ this ->returnValue ([]));
181
+ $ this ->configLoaderMock ->method ('getConfigByPath ' )
182
+ ->willReturn ([]);
168
183
169
184
$ this ->eventManagerMock ->expects (
170
185
$ this ->at (0 )
@@ -190,53 +205,64 @@ public function testSaveToCheckAdminSystemConfigChangedSectionEvent()
190
205
191
206
public function testDoNotSaveReadOnlyFields ()
192
207
{
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 );
195
211
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 ([]);
198
216
199
217
$ this ->model ->setGroups (['1 ' => ['fields ' => ['key ' => ['data ' ]]]]);
200
218
$ this ->model ->setSection ('section ' );
201
219
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 ' );
204
223
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 ' );
208
229
209
230
$ this ->configStructure ->expects ($ this ->at (0 ))
210
231
->method ('getElement ' )
211
232
->with ('section/1 ' )
212
- ->will ( $ this -> returnValue ( $ group) );
233
+ ->willReturn ( $ group );
213
234
$ this ->configStructure ->expects ($ this ->at (1 ))
214
235
->method ('getElement ' )
215
236
->with ('section/1 ' )
216
- ->will ( $ this -> returnValue ( $ group) );
237
+ ->willReturn ( $ group );
217
238
$ this ->configStructure ->expects ($ this ->at (2 ))
218
239
->method ('getElement ' )
219
240
->with ('section/1/key ' )
220
- ->will ( $ this -> returnValue ( $ field) );
241
+ ->willReturn ( $ field );
221
242
222
243
$ backendModel = $ this ->createPartialMock (
223
- \ Magento \ Framework \ App \ Config \ Value::class,
244
+ Value::class,
224
245
['addData ' ]
225
246
);
226
- $ this ->dataFactoryMock ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ backendModel ));
247
+ $ this ->dataFactoryMock ->method ('create ' )
248
+ ->willReturn ($ backendModel );
227
249
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 ' );
230
254
231
255
$ this ->model ->save ();
232
256
}
233
257
234
258
public function testSaveToCheckScopeDataSet ()
235
259
{
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 );
238
263
239
- $ this ->configLoaderMock ->expects ($ this ->any ())->method ('getConfigByPath ' )->will ($ this ->returnValue ([]));
264
+ $ this ->configLoaderMock ->method ('getConfigByPath ' )
265
+ ->willReturn ([]);
240
266
241
267
$ this ->eventManagerMock ->expects ($ this ->at (0 ))
242
268
->method ('dispatch ' )
@@ -251,36 +277,35 @@ public function testSaveToCheckScopeDataSet()
251
277
$ this ->arrayHasKey ('store ' )
252
278
);
253
279
254
- $ group = $ this ->createMock (\ Magento \ Config \ Model \ Config \ Structure \ Element \ Group::class);
280
+ $ group = $ this ->createMock (Group::class);
255
281
$ group ->method ('getPath ' )->willReturn ('section/1 ' );
256
282
257
- $ field = $ this ->createMock (\ Magento \ Config \ Model \ Config \ Structure \ Element \ Field::class);
283
+ $ field = $ this ->createMock (Field::class);
258
284
$ field ->method ('getGroupPath ' )->willReturn ('section/1 ' );
259
285
$ field ->method ('getId ' )->willReturn ('key ' );
260
286
261
287
$ this ->configStructure ->expects ($ this ->at (0 ))
262
288
->method ('getElement ' )
263
289
->with ('section/1 ' )
264
- ->will ( $ this -> returnValue ( $ group) );
290
+ ->willReturn ( $ group );
265
291
$ this ->configStructure ->expects ($ this ->at (1 ))
266
292
->method ('getElement ' )
267
293
->with ('section/1 ' )
268
- ->will ( $ this -> returnValue ( $ group) );
294
+ ->willReturn ( $ group );
269
295
$ this ->configStructure ->expects ($ this ->at (2 ))
270
296
->method ('getElement ' )
271
297
->with ('section/1/key ' )
272
- ->will ( $ this -> returnValue ( $ field) );
298
+ ->willReturn ( $ field );
273
299
$ this ->configStructure ->expects ($ this ->at (3 ))
274
300
->method ('getElement ' )
275
301
->with ('section/1 ' )
276
- ->will ( $ this -> returnValue ( $ group) );
302
+ ->willReturn ( $ group );
277
303
$ this ->configStructure ->expects ($ this ->at (4 ))
278
304
->method ('getElement ' )
279
305
->with ('section/1/key ' )
280
- ->will ( $ this -> returnValue ( $ field) );
306
+ ->willReturn ( $ field );
281
307
282
- $ this ->scopeResolver ->expects ($ this ->atLeastOnce ())
283
- ->method ('getScope ' )
308
+ $ this ->scopeResolver ->method ('getScope ' )
284
309
->with ('1 ' )
285
310
->willReturn ($ this ->scope );
286
311
$ this ->scope ->expects ($ this ->atLeastOnce ())
@@ -296,20 +321,19 @@ public function testSaveToCheckScopeDataSet()
296
321
->method ('normalize ' )
297
322
->with ('website ' )
298
323
->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 );
302
327
303
328
$ this ->model ->setWebsite ('1 ' );
304
329
$ this ->model ->setSection ('section ' );
305
330
$ this ->model ->setGroups (['1 ' => ['fields ' => ['key ' => ['data ' ]]]]);
306
331
307
332
$ backendModel = $ this ->createPartialMock (
308
- \ Magento \ Framework \ App \ Config \ Value::class,
333
+ Value::class,
309
334
['setPath ' , 'addData ' , '__sleep ' , '__wakeup ' ]
310
335
);
311
- $ backendModel ->expects ($ this ->once ())
312
- ->method ('addData ' )
336
+ $ backendModel ->method ('addData ' )
313
337
->with ([
314
338
'field ' => 'key ' ,
315
339
'groups ' => [1 => ['fields ' => ['key ' => ['data ' ]]]],
@@ -323,9 +347,10 @@ public function testSaveToCheckScopeDataSet()
323
347
$ backendModel ->expects ($ this ->once ())
324
348
->method ('setPath ' )
325
349
->with ('section/1/key ' )
326
- ->will ( $ this -> returnValue ( $ backendModel) );
350
+ ->willReturn ( $ backendModel );
327
351
328
- $ this ->dataFactoryMock ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ backendModel ));
352
+ $ this ->dataFactoryMock ->method ('create ' )
353
+ ->willReturn ($ backendModel );
329
354
330
355
$ this ->model ->save ();
331
356
}
0 commit comments