@@ -32,6 +32,11 @@ class InstallerTest extends \PHPUnit_Framework_TestCase
32
32
*/
33
33
private $ configWriter ;
34
34
35
+ /**
36
+ * @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject
37
+ */
38
+ private $ configReader ;
39
+
35
40
/**
36
41
* @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
37
42
*/
@@ -47,6 +52,16 @@ class InstallerTest extends \PHPUnit_Framework_TestCase
47
52
*/
48
53
private $ moduleLoader ;
49
54
55
+ /**
56
+ * @var \Magento\Framework\Module\ModuleList\DeploymentConfigFactory|\PHPUnit_Framework_MockObject_MockObject
57
+ */
58
+ private $ deploymentConfigFactory ;
59
+
60
+ /**
61
+ * @var \Magento\Framework\Module\ModuleList\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
62
+ */
63
+ private $ deploymentConfig ;
64
+
50
65
/**
51
66
* @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject
52
67
*/
@@ -118,6 +133,7 @@ protected function setUp()
118
133
{
119
134
$ this ->filePermissions = $ this ->getMock ('Magento\Setup\Model\FilePermissions ' , [], [], '' , false );
120
135
$ this ->configWriter = $ this ->getMock ('Magento\Framework\App\DeploymentConfig\Writer ' , [], [], '' , false );
136
+ $ this ->configReader = $ this ->getMock ('Magento\Framework\App\DeploymentConfig\Reader ' , [], [], '' , false );
121
137
$ this ->config = $ this ->getMock ('Magento\Framework\App\DeploymentConfig ' , [], [], '' , false );
122
138
123
139
$ this ->moduleList = $ this ->getMockForAbstractClass ('Magento\Framework\Module\ModuleListInterface ' );
@@ -128,11 +144,20 @@ protected function setUp()
128
144
['Foo_One ' , 'Bar_Two ' ]
129
145
);
130
146
$ this ->moduleLoader = $ this ->getMock ('Magento\Framework\Module\ModuleList\Loader ' , [], [], '' , false );
131
- $ allModules = [
132
- 'Foo_One ' => [],
133
- 'Bar_Two ' => [],
134
- ];
135
- $ this ->moduleLoader ->expects ($ this ->any ())->method ('load ' )->willReturn ($ allModules );
147
+ $ this ->deploymentConfigFactory = $ this ->getMock (
148
+ 'Magento\Framework\Module\ModuleList\DeploymentConfigFactory ' ,
149
+ [],
150
+ [],
151
+ '' ,
152
+ false
153
+ );
154
+ $ this ->deploymentConfig = $ this ->getMock (
155
+ 'Magento\Framework\Module\ModuleList\DeploymentConfig ' ,
156
+ [],
157
+ [],
158
+ '' ,
159
+ false
160
+ );
136
161
$ this ->directoryList = $ this ->getMock ('Magento\Framework\App\Filesystem\DirectoryList ' , [], [], '' , false );
137
162
$ this ->adminFactory = $ this ->getMock ('Magento\Setup\Model\AdminAccountFactory ' , [], [], '' , false );
138
163
$ this ->logger = $ this ->getMockForAbstractClass ('Magento\Setup\Model\LoggerInterface ' );
@@ -153,8 +178,7 @@ protected function setUp()
153
178
* @param \PHPUnit_Framework_MockObject_MockObject|bool $objectManagerProvider
154
179
* @return Installer
155
180
*/
156
- private function createObject ($ connectionFactory = false , $ objectManagerProvider = false )
157
- {
181
+ private function createObject ($ connectionFactory = false , $ objectManagerProvider = false ) {
158
182
if (!$ connectionFactory ) {
159
183
$ connectionFactory = $ this ->getMock ('Magento\Setup\Module\ConnectionFactory ' , [], [], '' , false );
160
184
$ connectionFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ this ->connection );
@@ -163,10 +187,13 @@ private function createObject($connectionFactory = false, $objectManagerProvider
163
187
$ objectManagerProvider = $ this ->getMock ('Magento\Setup\Model\ObjectManagerProvider ' , [], [], '' , false );
164
188
$ objectManagerProvider ->expects ($ this ->any ())->method ('get ' )->willReturn ($ this ->objectManager );
165
189
}
190
+
166
191
return new Installer (
167
192
$ this ->filePermissions ,
168
193
$ this ->configWriter ,
194
+ $ this ->configReader ,
169
195
$ this ->config ,
196
+ $ this ->deploymentConfigFactory ,
170
197
$ this ->moduleList ,
171
198
$ this ->moduleLoader ,
172
199
$ this ->directoryList ,
@@ -196,7 +223,12 @@ public function testInstall()
196
223
[DbConfig::CONFIG_KEY , self ::$ dbConfig ],
197
224
[EncryptConfig::CONFIG_KEY , [EncryptConfig::KEY_ENCRYPTION_KEY => 'encryption_key ' ]]
198
225
]));
199
-
226
+ $ allModules = ['Foo_One ' => [], 'Bar_Two ' => []];
227
+ $ this ->moduleLoader ->expects ($ this ->any ())->method ('load ' )->willReturn ($ allModules );
228
+ $ modules = ['Foo_One ' => 1 , 'Bar_Two ' => 1 ];
229
+ $ this ->deploymentConfig ->expects ($ this ->any ())->method ('getData ' )->willReturn ($ modules );
230
+ $ this ->deploymentConfigFactory ->expects ($ this ->any ())->method ('create ' )->with ($ modules )
231
+ ->willReturn ($ this ->deploymentConfig );
200
232
$ setup = $ this ->getMock ('Magento\Setup\Module\Setup ' , [], [], '' , false );
201
233
$ table = $ this ->getMock ('Magento\Framework\DB\Ddl\Table ' , [], [], '' , false );
202
234
$ connection = $ this ->getMockForAbstractClass ('Magento\Framework\DB\Adapter\AdapterInterface ' );
@@ -282,6 +314,43 @@ public function testCheckApplicationFilePermissions()
282
314
$ this ->assertSame (['message ' => [$ expectedMessage ]], $ this ->object ->getInstallInfo ());
283
315
}
284
316
317
+ public function testUpdateModulesSequence ()
318
+ {
319
+ $ varDir = $ this ->getMockForAbstractClass ('Magento\Framework\Filesystem\Directory\WriteInterface ' );
320
+ $ varDir ->expects ($ this ->exactly (2 ))->method ('getAbsolutePath ' )->willReturn ('/var ' );
321
+ $ this ->filesystem
322
+ ->expects ($ this ->exactly (2 ))
323
+ ->method ('getDirectoryWrite ' )
324
+ ->willReturn ($ varDir );
325
+
326
+ $ allModules = [
327
+ 'Foo_One ' => [],
328
+ 'Bar_Two ' => [],
329
+ 'New_Module ' => [],
330
+ ];
331
+ $ this ->moduleLoader ->expects ($ this ->once ())->method ('load ' )->willReturn ($ allModules );
332
+
333
+ $ expectedModules = [
334
+ 'Bar_Two ' => 0 ,
335
+ 'Foo_One ' => 1 ,
336
+ 'New_Module ' => 1
337
+ ];
338
+
339
+ $ this ->config ->expects ($ this ->atLeastOnce ())->method ('isAvailable ' )->willReturn (true );
340
+ $ this ->deploymentConfigFactory ->expects ($ this ->once ())->method ('create ' )->with ($ expectedModules )
341
+ ->willReturn ($ this ->deploymentConfig );
342
+
343
+ $ newObject = $ this ->createObject (false , false );
344
+ $ this ->configReader ->expects ($ this ->once ())->method ('load ' )
345
+ ->willReturn (['modules ' => ['Bar_Two ' => 0 , 'Foo_One ' => 1 , 'Old_Module ' => 0 ] ]);
346
+ $ this ->configWriter ->expects ($ this ->once ())->method ('update ' )->with ($ this ->deploymentConfig );
347
+ $ this ->logger ->expects ($ this ->at (0 ))->method ('log ' )->with ('File system cleanup: ' );
348
+ $ this ->logger ->expects ($ this ->at (1 ))->method ('log ' )
349
+ ->with ('The directory \'/var \' doesn \'t exist - skipping cleanup ' );
350
+ $ this ->logger ->expects ($ this ->at (3 ))->method ('log ' )->with ('Updating modules: ' );
351
+ $ newObject ->updateModulesSequence ();
352
+ }
353
+
285
354
public function testUninstall ()
286
355
{
287
356
$ this ->config ->expects ($ this ->once ())->method ('isAvailable ' )->willReturn (false );
0 commit comments