@@ -14,46 +14,52 @@ class ModuleEnableDisableCommandTest extends \PHPUnit_Framework_TestCase
14
14
/**
15
15
* @var \Magento\Setup\Model\ObjectManagerProvider|\PHPUnit_Framework_MockObject_MockObject
16
16
*/
17
- private $ objectManagerProvider ;
17
+ private $ objectManagerProviderMock ;
18
18
19
19
/**
20
20
* @var \Magento\Framework\Module\Status|\PHPUnit_Framework_MockObject_MockObject
21
21
*/
22
- private $ status ;
22
+ private $ statusMock ;
23
23
24
24
/**
25
25
* @var \Magento\Framework\App\Cache|\PHPUnit_Framework_MockObject_MockObject
26
26
*/
27
- private $ cache ;
27
+ private $ cacheMock ;
28
28
29
29
/**
30
30
* @var \Magento\Framework\App\State\CleanupFiles|\PHPUnit_Framework_MockObject_MockObject
31
31
*/
32
- private $ cleanupFiles ;
32
+ private $ cleanupFilesMock ;
33
33
34
34
/**
35
35
* @var \Magento\Framework\Module\FullModuleList|\PHPUnit_Framework_MockObject_MockObject
36
36
*/
37
- private $ fullModuleList ;
37
+ private $ fullModuleListMock ;
38
+
39
+ /**
40
+ * @var \Magento\Framework\App\DeploymentConfig
41
+ */
42
+ private $ deploymentConfigMock ;
38
43
39
44
protected function setUp ()
40
45
{
41
- $ this ->objectManagerProvider = $ this ->getMock ('Magento\Setup\Model\ObjectManagerProvider ' , [], [], '' , false );
46
+ $ this ->objectManagerProviderMock = $ this ->getMock ('Magento\Setup\Model\ObjectManagerProvider ' , [], [], '' , false );
42
47
$ objectManager = $ this ->getMockForAbstractClass ('Magento\Framework\ObjectManagerInterface ' );
43
- $ this ->objectManagerProvider ->expects ($ this ->any ())
48
+ $ this ->objectManagerProviderMock ->expects ($ this ->any ())
44
49
->method ('get ' )
45
50
->will ($ this ->returnValue ($ objectManager ));
46
- $ this ->status = $ this ->getMock ('Magento\Framework\Module\Status ' , [], [], '' , false );
47
- $ this ->cache = $ this ->getMock ('Magento\Framework\App\Cache ' , [], [], '' , false );
48
- $ this ->cleanupFiles = $ this ->getMock ('Magento\Framework\App\State\CleanupFiles ' , [], [], '' , false );
49
- $ this ->fullModuleList = $ this ->getMock ('Magento\Framework\Module\FullModuleList ' , [], [], '' , false );
51
+ $ this ->statusMock = $ this ->getMock ('Magento\Framework\Module\Status ' , [], [], '' , false );
52
+ $ this ->cacheMock = $ this ->getMock ('Magento\Framework\App\Cache ' , [], [], '' , false );
53
+ $ this ->cleanupFilesMock = $ this ->getMock ('Magento\Framework\App\State\CleanupFiles ' , [], [], '' , false );
54
+ $ this ->fullModuleListMock = $ this ->getMock ('Magento\Framework\Module\FullModuleList ' , [], [], '' , false );
55
+ $ this ->deploymentConfigMock = $ this ->getMock (\Magento \Framework \App \DeploymentConfig::class, [], [], '' , false );
50
56
$ objectManager ->expects ($ this ->any ())
51
57
->method ('get ' )
52
58
->will ($ this ->returnValueMap ([
53
- ['Magento\Framework\Module\Status ' , $ this ->status ],
54
- ['Magento\Framework\App\Cache ' , $ this ->cache ],
55
- ['Magento\Framework\App\State\CleanupFiles ' , $ this ->cleanupFiles ],
56
- ['Magento\Framework\Module\FullModuleList ' , $ this ->fullModuleList ],
59
+ ['Magento\Framework\Module\Status ' , $ this ->statusMock ],
60
+ ['Magento\Framework\App\Cache ' , $ this ->cacheMock ],
61
+ ['Magento\Framework\App\State\CleanupFiles ' , $ this ->cleanupFilesMock ],
62
+ ['Magento\Framework\Module\FullModuleList ' , $ this ->fullModuleListMock ],
57
63
]));
58
64
}
59
65
@@ -66,29 +72,23 @@ protected function setUp()
66
72
*/
67
73
public function testExecute ($ isEnable , $ clearStaticContent , $ expectedMessage )
68
74
{
69
- $ this ->status ->expects ($ this ->once ())
75
+ $ this ->statusMock ->expects ($ this ->once ())
70
76
->method ('getModulesToChange ' )
71
77
->with ($ isEnable , ['Magento_Module1 ' , 'Magento_Module2 ' ])
72
78
->will ($ this ->returnValue (['Magento_Module1 ' ]));
73
-
74
- $ this ->status ->expects ($ this ->any ())
79
+ $ this ->statusMock ->expects ($ this ->any ())
75
80
->method ('checkConstraints ' )
76
81
->will ($ this ->returnValue ([]));
77
-
78
- $ this ->status ->expects ($ this ->once ())
82
+ $ this ->statusMock ->expects ($ this ->once ())
79
83
->method ('setIsEnabled ' )
80
84
->with ($ isEnable , ['Magento_Module1 ' ]);
81
-
82
- $ this ->cache ->expects ($ this ->once ())
85
+ $ this ->cacheMock ->expects ($ this ->once ())
83
86
->method ('clean ' );
84
- $ this ->cleanupFiles ->expects ($ this ->once ())
87
+ $ this ->cleanupFilesMock ->expects ($ this ->once ())
85
88
->method ('clearCodeGeneratedClasses ' );
86
- $ this ->cleanupFiles ->expects ($ clearStaticContent ? $ this ->once () : $ this ->never ())
89
+ $ this ->cleanupFilesMock ->expects ($ clearStaticContent ? $ this ->once () : $ this ->never ())
87
90
->method ('clearMaterializedViewFiles ' );
88
-
89
- $ commandTester = $ isEnable
90
- ? new CommandTester (new ModuleEnableCommand ($ this ->objectManagerProvider ))
91
- : new CommandTester (new ModuleDisableCommand ($ this ->objectManagerProvider ));
91
+ $ commandTester = $ this ->getCommandTester ($ isEnable );
92
92
$ input = ['module ' => ['Magento_Module1 ' , 'Magento_Module2 ' ]];
93
93
if ($ clearStaticContent ) {
94
94
$ input ['--clear-static-content ' ] = true ;
@@ -106,14 +106,14 @@ public function executeDataProvider()
106
106
'enable, do not clear static content ' => [
107
107
true ,
108
108
false ,
109
- '%amodules have been enabled%aMagento_Module1%a ' .
110
- 'Info: Some modules might require static view files to be cleared.%a '
109
+ '%amodules have been enabled%aMagento_Module1%a '
110
+ . 'Info: Some modules might require static view files to be cleared.%a '
111
111
],
112
112
'disable, do not clear static content ' => [
113
113
false ,
114
114
false ,
115
- '%amodules have been disabled%aMagento_Module1%a ' .
116
- 'Info: Some modules might require static view files to be cleared.%a '
115
+ '%amodules have been disabled%aMagento_Module1%a '
116
+ . 'Info: Some modules might require static view files to be cleared.%a '
117
117
],
118
118
'enable, clear static content ' => [
119
119
true ,
@@ -124,29 +124,29 @@ public function executeDataProvider()
124
124
false ,
125
125
true ,
126
126
'%amodules have been disabled%aMagento_Module1%aGenerated static view files cleared%a '
127
- ],
127
+ ]
128
128
];
129
129
}
130
130
131
131
public function testExecuteEnableInvalidModule ()
132
132
{
133
- $ this ->status ->expects ($ this ->once ())
133
+ $ this ->statusMock ->expects ($ this ->once ())
134
134
->method ('getModulesToChange ' )
135
135
->with (true , ['invalid ' ])
136
136
->willThrowException (new \LogicException ('Unknown module(s): invalid ' ));
137
- $ commandTester = new CommandTester ( new ModuleEnableCommand ( $ this ->objectManagerProvider ) );
137
+ $ commandTester = $ this ->getCommandTester ( true );
138
138
$ input = ['module ' => ['invalid ' ]];
139
139
$ commandTester ->execute ($ input );
140
140
$ this ->assertEquals ('Unknown module(s): invalid ' . PHP_EOL , $ commandTester ->getDisplay ());
141
141
}
142
142
143
143
public function testExecuteDisableInvalidModule ()
144
144
{
145
- $ this ->status ->expects ($ this ->once ())
145
+ $ this ->statusMock ->expects ($ this ->once ())
146
146
->method ('getModulesToChange ' )
147
147
->with (false , ['invalid ' ])
148
148
->willThrowException (new \LogicException ('Unknown module(s): invalid ' ));
149
- $ commandTester = new CommandTester ( new ModuleDisableCommand ( $ this ->objectManagerProvider ) );
149
+ $ commandTester = $ this ->getCommandTester ( false );
150
150
$ input = ['module ' => ['invalid ' ]];
151
151
$ commandTester ->execute ($ input );
152
152
$ this ->assertEquals ('Unknown module(s): invalid ' . PHP_EOL , $ commandTester ->getDisplay ());
@@ -155,31 +155,26 @@ public function testExecuteDisableInvalidModule()
155
155
/**
156
156
* @param bool $isEnable
157
157
* @param string $expectedMessage
158
+ * @param bool $isInstalled
158
159
*
159
160
* @dataProvider executeAllDataProvider
160
161
*/
161
162
public function testExecuteAll ($ isEnable , $ expectedMessage )
162
163
{
163
- $ this ->fullModuleList ->expects ($ this ->once ())
164
+ $ this ->fullModuleListMock ->expects ($ this ->once ())
164
165
->method ('getNames ' )
165
166
->will ($ this ->returnValue (['Magento_Module1 ' , 'Magento_Module2 ' ]));
166
-
167
- $ this ->status ->expects ($ this ->once ())
167
+ $ this ->statusMock ->expects ($ this ->once ())
168
168
->method ('getModulesToChange ' )
169
169
->with ($ isEnable , ['Magento_Module1 ' , 'Magento_Module2 ' ])
170
170
->will ($ this ->returnValue (['Magento_Module1 ' ]));
171
-
172
- $ this ->status ->expects ($ this ->any ())
171
+ $ this ->statusMock ->expects ($ this ->any ())
173
172
->method ('checkConstraints ' )
174
173
->will ($ this ->returnValue ([]));
175
-
176
- $ this ->status ->expects ($ this ->once ())
174
+ $ this ->statusMock ->expects ($ this ->once ())
177
175
->method ('setIsEnabled ' )
178
176
->with ($ isEnable , ['Magento_Module1 ' ]);
179
-
180
- $ commandTester = $ isEnable
181
- ? new CommandTester (new ModuleEnableCommand ($ this ->objectManagerProvider ))
182
- : new CommandTester (new ModuleDisableCommand ($ this ->objectManagerProvider ));
177
+ $ commandTester = $ this ->getCommandTester ($ isEnable );
183
178
$ input = ['--all ' => true ];
184
179
$ commandTester ->execute ($ input );
185
180
$ this ->assertStringMatchesFormat ($ expectedMessage , $ commandTester ->getDisplay ());
@@ -203,21 +198,16 @@ public function executeAllDataProvider()
203
198
*/
204
199
public function testExecuteWithConstraints ($ isEnable )
205
200
{
206
- $ this ->status ->expects ($ this ->once ())
201
+ $ this ->statusMock ->expects ($ this ->once ())
207
202
->method ('getModulesToChange ' )
208
203
->with ($ isEnable , ['Magento_Module1 ' , 'Magento_Module2 ' ])
209
204
->will ($ this ->returnValue (['Magento_Module1 ' ]));
210
-
211
- $ this ->status ->expects ($ this ->any ())
205
+ $ this ->statusMock ->expects ($ this ->any ())
212
206
->method ('checkConstraints ' )
213
207
->will ($ this ->returnValue (['constraint1 ' , 'constraint2 ' ]));
214
-
215
- $ this ->status ->expects ($ this ->never ())
208
+ $ this ->statusMock ->expects ($ this ->never ())
216
209
->method ('setIsEnabled ' );
217
-
218
- $ commandTester = $ isEnable
219
- ? new CommandTester (new ModuleEnableCommand ($ this ->objectManagerProvider ))
220
- : new CommandTester (new ModuleDisableCommand ($ this ->objectManagerProvider ));
210
+ $ commandTester = $ this ->getCommandTester ($ isEnable );
221
211
$ commandTester ->execute (['module ' => ['Magento_Module1 ' , 'Magento_Module2 ' ]]);
222
212
$ this ->assertStringMatchesFormat (
223
213
'Unable to change status of modules%aconstraint1%aconstraint2%a ' ,
@@ -244,21 +234,16 @@ public function executeWithConstraintsDataProvider()
244
234
*/
245
235
public function testExecuteForce ($ isEnable , $ expectedMessage )
246
236
{
247
- $ this ->status ->expects ($ this ->once ())
237
+ $ this ->statusMock ->expects ($ this ->once ())
248
238
->method ('getModulesToChange ' )
249
239
->with ($ isEnable , ['Magento_Module1 ' , 'Magento_Module2 ' ])
250
240
->will ($ this ->returnValue (['Magento_Module1 ' ]));
251
-
252
- $ this ->status ->expects ($ this ->never ())
241
+ $ this ->statusMock ->expects ($ this ->never ())
253
242
->method ('checkConstraints ' );
254
-
255
- $ this ->status ->expects ($ this ->once ())
243
+ $ this ->statusMock ->expects ($ this ->once ())
256
244
->method ('setIsEnabled ' )
257
245
->with ($ isEnable , ['Magento_Module1 ' ]);
258
-
259
- $ commandTester = $ isEnable
260
- ? new CommandTester (new ModuleEnableCommand ($ this ->objectManagerProvider ))
261
- : new CommandTester (new ModuleDisableCommand ($ this ->objectManagerProvider ));
246
+ $ commandTester = $ this ->getCommandTester ($ isEnable );
262
247
$ commandTester ->execute (['module ' => ['Magento_Module1 ' , 'Magento_Module2 ' ], '--force ' => true ]);
263
248
$ this ->assertStringMatchesFormat (
264
249
$ expectedMessage . '%amodules might not function properly%a ' ,
@@ -284,21 +269,31 @@ public function executeExecuteForceDataProvider()
284
269
*/
285
270
public function testExecuteNoChanges ($ isEnable )
286
271
{
287
- $ this ->status ->expects ($ this ->once ())
272
+ $ this ->statusMock ->expects ($ this ->once ())
288
273
->method ('getModulesToChange ' )
289
274
->with ($ isEnable , ['Magento_Module1 ' , 'Magento_Module2 ' ])
290
275
->will ($ this ->returnValue ([]));
291
-
292
- $ this ->status ->expects ($ this ->never ())
276
+ $ this ->statusMock ->expects ($ this ->never ())
293
277
->method ('setIsEnabled ' );
294
-
295
- $ commandTester = $ isEnable
296
- ? new CommandTester (new ModuleEnableCommand ($ this ->objectManagerProvider ))
297
- : new CommandTester (new ModuleDisableCommand ($ this ->objectManagerProvider ));
278
+ $ commandTester = $ this ->getCommandTester ($ isEnable );
298
279
$ commandTester ->execute (['module ' => ['Magento_Module1 ' , 'Magento_Module2 ' ]]);
299
280
$ this ->assertStringMatchesFormat (
300
281
'No modules were changed%a ' ,
301
282
$ commandTester ->getDisplay ()
302
283
);
303
284
}
285
+
286
+ /**
287
+ * @param bool $isEnable
288
+ * @return CommandTester
289
+ */
290
+ private function getCommandTester ($ isEnable )
291
+ {
292
+ $ class = $ isEnable ? ModuleEnableCommand::class : ModuleDisableCommand::class;
293
+ $ command = new $ class ($ this ->objectManagerProviderMock );
294
+ $ deploymentConfigProperty = new \ReflectionProperty ($ class , 'deploymentConfig ' );
295
+ $ deploymentConfigProperty ->setAccessible (true );
296
+ $ deploymentConfigProperty ->setValue ($ command , $ this ->deploymentConfigMock );
297
+ return new CommandTester ($ command );
298
+ }
304
299
}
0 commit comments