2929 use Magento \Framework \Model \ResourceModel \Db \Context ;
3030 use Magento \Framework \Module \ModuleList \Loader ;
3131 use Magento \Framework \Module \ModuleListInterface ;
32+ use Magento \Framework \Module \ModuleResource ;
3233 use Magento \Framework \ObjectManagerInterface ;
3334 use Magento \Framework \Registry ;
3435 use Magento \Framework \Setup \FilePermissions ;
@@ -77,7 +78,7 @@ class InstallerTest extends TestCase
7778 ];
7879
7980 /**
80- * @var Installer
81+ * @var Installer|MockObject
8182 */
8283 private $ object ;
8384
@@ -230,9 +231,6 @@ protected function setUp(): void
230231 $ this ->config = $ this ->createMock (DeploymentConfig::class);
231232
232233 $ this ->moduleList = $ this ->getMockForAbstractClass (ModuleListInterface::class);
233- $ this ->moduleList ->expects ($ this ->any ())->method ('getOne ' )->willReturn (
234- ['setup_version ' => '2.0.0 ' ]
235- );
236234 $ this ->moduleList ->expects ($ this ->any ())->method ('getNames ' )->willReturn (
237235 ['Foo_One ' , 'Bar_Two ' ]
238236 );
@@ -282,29 +280,35 @@ private function createObject($connectionFactory = false, $objectManagerProvider
282280 $ objectManagerProvider ->expects ($ this ->any ())->method ('get ' )->willReturn ($ this ->objectManager );
283281 }
284282
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 ;
308312 }
309313
310314 /**
@@ -315,6 +319,14 @@ private function createObject($connectionFactory = false, $objectManagerProvider
315319 */
316320 public function testInstall (array $ request , array $ logMessages )
317321 {
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+
318330 $ this ->config ->expects ($ this ->atLeastOnce ())
319331 ->method ('get ' )
320332 ->willReturnMap (
@@ -344,6 +356,16 @@ public function testInstall(array $request, array $logMessages)
344356 $ resource = $ this ->createMock (ResourceConnection::class);
345357 $ this ->contextMock ->expects ($ this ->any ())->method ('getResources ' )->willReturn ($ resource );
346358 $ 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+
347369 $ dataSetup = $ this ->createMock (DataSetup::class);
348370 $ dataSetup ->expects ($ this ->any ())->method ('getConnection ' )->willReturn ($ connection );
349371 $ cacheManager = $ this ->createMock (Manager::class);
@@ -581,6 +603,7 @@ public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploym
581603 ['modules/Magento_User ' , null , '1 ' ]
582604 ]
583605 );
606+ $ this ->moduleList ->method ('getOne ' )->willReturn (['setup_version ' => '2.0.0 ' ]);
584607 $ allModules = ['Foo_One ' => [], 'Bar_Two ' => []];
585608
586609 $ this ->declarationInstallerMock ->expects (static ::once ())->method ('installSchema ' );
@@ -603,6 +626,7 @@ public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploym
603626 $ resource ->expects (static ::any ())->method ('getConnection ' )->willReturn ($ connection );
604627
605628 $ this ->contextMock ->expects (static ::exactly (2 ))->method ('getResources ' )->willReturn ($ resource );
629+ $ this ->setModuleResource ();
606630
607631 $ dataSetup = $ this ->createMock (DataSetup::class);
608632 $ dataSetup ->expects (static ::never ())->method ('getConnection ' );
@@ -752,6 +776,7 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
752776 ]
753777 );
754778 $ allModules = ['Foo_One ' => [], 'Bar_Two ' => []];
779+ $ this ->moduleList ->method ('getOne ' )->willReturn (['setup_version ' => '2.0.0 ' ]);
755780
756781 $ this ->declarationInstallerMock ->expects (static ::once ())->method ('installSchema ' );
757782 $ this ->moduleLoader ->expects (static ::any ())->method ('load ' )->willReturn ($ allModules );
@@ -771,6 +796,8 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
771796 $ resource = $ this ->createMock (ResourceConnection::class);
772797 $ this ->contextMock ->expects (static ::any ())->method ('getResources ' )->willReturn ($ resource );
773798 $ resource ->expects (static ::any ())->method ('getConnection ' )->willReturn ($ connection );
799+ $ this ->setModuleResource ();
800+
774801 $ dataSetup = $ this ->createMock (DataSetup::class);
775802 $ dataSetup ->expects (static ::any ())->method ('getConnection ' )->willReturn ($ connection );
776803 $ cacheManager = $ this ->createMock (Manager::class);
@@ -939,6 +966,7 @@ public function testInstallWithInvalidRemoteStorageConfigurationWithEarlyExcepti
939966 ]
940967 );
941968 $ allModules = ['Foo_One ' => [], 'Bar_Two ' => []];
969+ $ this ->moduleList ->method ('getOne ' )->willReturn (['setup_version ' => '2.0.0 ' ]);
942970
943971 $ this ->declarationInstallerMock
944972 ->expects (static ::once ())
@@ -1054,6 +1082,8 @@ public function installWithInvalidRemoteStorageConfigurationWithEarlyExceptionDa
10541082 */
10551083 public function testInstallDataFixtures (bool $ keepCache , array $ expectedToEnableCacheTypes ): void
10561084 {
1085+ $ this ->moduleList ->method ('getOne ' )->willReturn (['setup_version ' => '2.0.0 ' ]);
1086+
10571087 $ cacheManagerMock = $ this ->createMock (Manager::class);
10581088 //simulate disabled layout cache type
10591089 $ cacheManagerMock ->expects ($ this ->atLeastOnce ())
@@ -1108,6 +1138,7 @@ public function testInstallDataFixtures(bool $keepCache, array $expectedToEnable
11081138 $ this ->contextMock ->expects ($ this ->once ())
11091139 ->method ('getResources ' )
11101140 ->willReturn ($ resource );
1141+ $ this ->setModuleResource ();
11111142
11121143 $ dataSetup = $ this ->createMock (DataSetup::class);
11131144 $ dataSetup ->expects ($ this ->once ())
@@ -1367,6 +1398,17 @@ private function prepareForUpdateModulesTests()
13671398
13681399 return $ newObject ;
13691400 }
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+ }
13701412 }
13711413}
13721414
0 commit comments