29
29
use Magento \Framework \Model \ResourceModel \Db \Context ;
30
30
use Magento \Framework \Module \ModuleList \Loader ;
31
31
use Magento \Framework \Module \ModuleListInterface ;
32
+ use Magento \Framework \Module \ModuleResource ;
32
33
use Magento \Framework \ObjectManagerInterface ;
33
34
use Magento \Framework \Registry ;
34
35
use Magento \Framework \Setup \FilePermissions ;
@@ -77,7 +78,7 @@ class InstallerTest extends TestCase
77
78
];
78
79
79
80
/**
80
- * @var Installer
81
+ * @var Installer|MockObject
81
82
*/
82
83
private $ object ;
83
84
@@ -230,9 +231,6 @@ protected function setUp(): void
230
231
$ this ->config = $ this ->createMock (DeploymentConfig::class);
231
232
232
233
$ this ->moduleList = $ this ->getMockForAbstractClass (ModuleListInterface::class);
233
- $ this ->moduleList ->expects ($ this ->any ())->method ('getOne ' )->willReturn (
234
- ['setup_version ' => '2.0.0 ' ]
235
- );
236
234
$ this ->moduleList ->expects ($ this ->any ())->method ('getNames ' )->willReturn (
237
235
['Foo_One ' , 'Bar_Two ' ]
238
236
);
@@ -282,29 +280,35 @@ private function createObject($connectionFactory = false, $objectManagerProvider
282
280
$ objectManagerProvider ->expects ($ this ->any ())->method ('get ' )->willReturn ($ this ->objectManager );
283
281
}
284
282
285
- return new Installer (
286
- $ this ->filePermissions ,
287
- $ this ->configWriter ,
288
- $ this ->configReader ,
289
- $ this ->config ,
290
- $ this ->moduleList ,
291
- $ this ->moduleLoader ,
292
- $ this ->adminFactory ,
293
- $ this ->logger ,
294
- $ connectionFactory ,
295
- $ this ->maintenanceMode ,
296
- $ this ->filesystem ,
297
- $ objectManagerProvider ,
298
- $ this ->contextMock ,
299
- $ this ->configModel ,
300
- $ this ->cleanupFiles ,
301
- $ this ->dbValidator ,
302
- $ this ->setupFactory ,
303
- $ this ->dataSetupFactory ,
304
- $ this ->sampleDataState ,
305
- $ this ->componentRegistrar ,
306
- $ this ->phpReadinessCheck
307
- );
283
+ $ installer = $ this ->getMockBuilder (Installer::class)
284
+ ->enableOriginalConstructor ()
285
+ ->onlyMethods (['getModuleResource ' ])
286
+ ->setConstructorArgs ([
287
+ 'filePermissions ' => $ this ->filePermissions ,
288
+ 'deploymentConfigWriter ' => $ this ->configWriter ,
289
+ 'deploymentConfigReader ' => $ this ->configReader ,
290
+ 'deploymentConfig ' => $ this ->config ,
291
+ 'moduleList ' => $ this ->moduleList ,
292
+ 'moduleLoader ' => $ this ->moduleLoader ,
293
+ 'adminAccountFactory ' => $ this ->adminFactory ,
294
+ 'log ' => $ this ->logger ,
295
+ 'connectionFactory ' => $ connectionFactory ,
296
+ 'maintenanceMode ' => $ this ->maintenanceMode ,
297
+ 'filesystem ' => $ this ->filesystem ,
298
+ 'objectManagerProvider ' => $ objectManagerProvider ,
299
+ 'context ' => $ this ->contextMock ,
300
+ 'setupConfigModel ' => $ this ->configModel ,
301
+ 'cleanupFiles ' => $ this ->cleanupFiles ,
302
+ 'dbValidator ' => $ this ->dbValidator ,
303
+ 'setupFactory ' => $ this ->setupFactory ,
304
+ 'dataSetupFactory ' => $ this ->dataSetupFactory ,
305
+ 'sampleDataState ' => $ this ->sampleDataState ,
306
+ 'componentRegistrar ' => $ this ->componentRegistrar ,
307
+ 'phpReadinessCheck ' => $ this ->phpReadinessCheck ,
308
+ ])
309
+ ->getMock ();
310
+
311
+ return $ installer ;
308
312
}
309
313
310
314
/**
@@ -315,6 +319,14 @@ private function createObject($connectionFactory = false, $objectManagerProvider
315
319
*/
316
320
public function testInstall (array $ request , array $ logMessages )
317
321
{
322
+ $ this ->moduleList ->method ('getOne ' )
323
+ ->willReturnMap (
324
+ [
325
+ ['Foo_One ' , ['setup_version ' => '2.0.0 ' ]],
326
+ ['Bar_Two ' , ['setup_version ' => null ]]
327
+ ]
328
+ );
329
+
318
330
$ this ->config ->expects ($ this ->atLeastOnce ())
319
331
->method ('get ' )
320
332
->willReturnMap (
@@ -344,6 +356,16 @@ public function testInstall(array $request, array $logMessages)
344
356
$ resource = $ this ->createMock (ResourceConnection::class);
345
357
$ this ->contextMock ->expects ($ this ->any ())->method ('getResources ' )->willReturn ($ resource );
346
358
$ resource ->expects ($ this ->any ())->method ('getConnection ' )->willReturn ($ connection );
359
+
360
+ $ moduleResource = $ this ->getMockBuilder (ModuleResource::class)
361
+ ->enableOriginalConstructor ()
362
+ ->onlyMethods (['getDbVersion ' , 'getDataVersion ' ])
363
+ ->setConstructorArgs (['context ' => $ this ->contextMock ])
364
+ ->getMock ();
365
+ $ moduleResource ->method ('getDbVersion ' )->willReturnOnConsecutiveCalls (false , '2.1.0 ' );
366
+ $ moduleResource ->method ('getDataVersion ' )->willReturn (false );
367
+ $ this ->object ->method ('getModuleResource ' )->willReturn ($ moduleResource );
368
+
347
369
$ dataSetup = $ this ->createMock (DataSetup::class);
348
370
$ dataSetup ->expects ($ this ->any ())->method ('getConnection ' )->willReturn ($ connection );
349
371
$ cacheManager = $ this ->createMock (Manager::class);
@@ -581,6 +603,7 @@ public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploym
581
603
['modules/Magento_User ' , null , '1 ' ]
582
604
]
583
605
);
606
+ $ this ->moduleList ->method ('getOne ' )->willReturn (['setup_version ' => '2.0.0 ' ]);
584
607
$ allModules = ['Foo_One ' => [], 'Bar_Two ' => []];
585
608
586
609
$ this ->declarationInstallerMock ->expects (static ::once ())->method ('installSchema ' );
@@ -603,6 +626,7 @@ public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploym
603
626
$ resource ->expects (static ::any ())->method ('getConnection ' )->willReturn ($ connection );
604
627
605
628
$ this ->contextMock ->expects (static ::exactly (2 ))->method ('getResources ' )->willReturn ($ resource );
629
+ $ this ->setModuleResource ();
606
630
607
631
$ dataSetup = $ this ->createMock (DataSetup::class);
608
632
$ dataSetup ->expects (static ::never ())->method ('getConnection ' );
@@ -752,6 +776,7 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
752
776
]
753
777
);
754
778
$ allModules = ['Foo_One ' => [], 'Bar_Two ' => []];
779
+ $ this ->moduleList ->method ('getOne ' )->willReturn (['setup_version ' => '2.0.0 ' ]);
755
780
756
781
$ this ->declarationInstallerMock ->expects (static ::once ())->method ('installSchema ' );
757
782
$ this ->moduleLoader ->expects (static ::any ())->method ('load ' )->willReturn ($ allModules );
@@ -771,6 +796,8 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
771
796
$ resource = $ this ->createMock (ResourceConnection::class);
772
797
$ this ->contextMock ->expects (static ::any ())->method ('getResources ' )->willReturn ($ resource );
773
798
$ resource ->expects (static ::any ())->method ('getConnection ' )->willReturn ($ connection );
799
+ $ this ->setModuleResource ();
800
+
774
801
$ dataSetup = $ this ->createMock (DataSetup::class);
775
802
$ dataSetup ->expects (static ::any ())->method ('getConnection ' )->willReturn ($ connection );
776
803
$ cacheManager = $ this ->createMock (Manager::class);
@@ -939,6 +966,7 @@ public function testInstallWithInvalidRemoteStorageConfigurationWithEarlyExcepti
939
966
]
940
967
);
941
968
$ allModules = ['Foo_One ' => [], 'Bar_Two ' => []];
969
+ $ this ->moduleList ->method ('getOne ' )->willReturn (['setup_version ' => '2.0.0 ' ]);
942
970
943
971
$ this ->declarationInstallerMock
944
972
->expects (static ::once ())
@@ -1054,6 +1082,8 @@ public function installWithInvalidRemoteStorageConfigurationWithEarlyExceptionDa
1054
1082
*/
1055
1083
public function testInstallDataFixtures (bool $ keepCache , array $ expectedToEnableCacheTypes ): void
1056
1084
{
1085
+ $ this ->moduleList ->method ('getOne ' )->willReturn (['setup_version ' => '2.0.0 ' ]);
1086
+
1057
1087
$ cacheManagerMock = $ this ->createMock (Manager::class);
1058
1088
//simulate disabled layout cache type
1059
1089
$ cacheManagerMock ->expects ($ this ->atLeastOnce ())
@@ -1108,6 +1138,7 @@ public function testInstallDataFixtures(bool $keepCache, array $expectedToEnable
1108
1138
$ this ->contextMock ->expects ($ this ->once ())
1109
1139
->method ('getResources ' )
1110
1140
->willReturn ($ resource );
1141
+ $ this ->setModuleResource ();
1111
1142
1112
1143
$ dataSetup = $ this ->createMock (DataSetup::class);
1113
1144
$ dataSetup ->expects ($ this ->once ())
@@ -1367,6 +1398,17 @@ private function prepareForUpdateModulesTests()
1367
1398
1368
1399
return $ newObject ;
1369
1400
}
1401
+
1402
+ /**
1403
+ * Sets a new ModuleResource object to the installer
1404
+ *
1405
+ * @return void
1406
+ */
1407
+ private function setModuleResource (): void
1408
+ {
1409
+ $ moduleResource = new ModuleResource ($ this ->contextMock );
1410
+ $ this ->object ->method ('getModuleResource ' )->willReturn ($ moduleResource );
1411
+ }
1370
1412
}
1371
1413
}
1372
1414
0 commit comments