Skip to content

Commit 3c146cb

Browse files
committed
B2B-1785: Cannot enable remote storage with install command when modules are not enabled
1 parent 32b0399 commit 3c146cb

File tree

1 file changed

+175
-2
lines changed

1 file changed

+175
-2
lines changed

setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php

Lines changed: 175 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Framework\Config\File\ConfigFilePool;
2323
use Magento\Framework\DB\Adapter\AdapterInterface;
2424
use Magento\Framework\DB\Ddl\Table;
25+
use Magento\Framework\Exception\RuntimeException;
2526
use Magento\Framework\Filesystem;
2627
use Magento\Framework\Filesystem\Directory\WriteInterface;
2728
use Magento\Framework\Filesystem\DriverPool;
@@ -358,6 +359,8 @@ public function testInstall(array $request, array $logMessages)
358359
->disableOriginalConstructor()
359360
->getMock();
360361

362+
$this->configWriter->expects(static::never())->method('checkIfWritable');
363+
361364
$this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup);
362365
$this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup);
363366
$this->objectManager->expects($this->any())
@@ -424,13 +427,16 @@ public function testInstall(array $request, array $logMessages)
424427
}
425428

426429
/**
427-
* Test installation with invalid remote storage configuration raises ValidationException
430+
* Test installation with invalid remote storage configuration raises ValidationException via validation
431+
* and reverts configuration back to local file driver
428432
*
433+
* @param bool $isDeploymentConfigWritable
434+
* @dataProvider installWithInvalidRemoteStorageConfigurationDataProvider
429435
* @throws \Magento\Framework\Exception\FileSystemException
430436
* @throws \Magento\Framework\Exception\LocalizedException
431437
* @throws \Magento\Framework\Exception\RuntimeException
432438
*/
433-
public function testInstallWithInvalidRemoteStorageConfiguration()
439+
public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploymentConfigWritable)
434440
{
435441
$request = $this->request;
436442

@@ -507,6 +513,36 @@ public function testInstallWithInvalidRemoteStorageConfiguration()
507513

508514
$this->expectException(ValidationException::class);
509515

516+
$this->configWriter
517+
->expects(static::once())
518+
->method('checkIfWritable')
519+
->willReturn($isDeploymentConfigWritable);
520+
521+
$remoteStorageReversionArguments = [
522+
[
523+
ConfigFilePool::APP_ENV => [
524+
'remote_storage' => [
525+
'driver' => 'file'
526+
]
527+
]
528+
],
529+
true
530+
];
531+
532+
if ($isDeploymentConfigWritable) { // assert remote storage reversion is attempted
533+
$this->configWriter
534+
->expects(static::at(2))
535+
->method('saveConfig')
536+
->with(...$remoteStorageReversionArguments);
537+
} else { // assert remote storage reversion is never attempted
538+
$this->configWriter
539+
->expects(static::any())
540+
->method('saveConfig')
541+
->willReturnCallback(function (array $data, $override) use ($remoteStorageReversionArguments) {
542+
$this->assertNotEquals($remoteStorageReversionArguments, [$data, $override]);
543+
});
544+
}
545+
510546
$this->setupFactory->expects(static::once())->method('create')->with($resource)->willReturn($setup);
511547

512548
$this->objectManager->expects(static::any())
@@ -560,6 +596,132 @@ public function testInstallWithInvalidRemoteStorageConfiguration()
560596
$this->object->install($request);
561597
}
562598

599+
/**
600+
* Test installation with invalid remote storage configuration is able to be caught earlier than
601+
* the queued validation step if necessary, and that configuration is reverted back to local file driver.
602+
*
603+
* @throws \Magento\Framework\Exception\FileSystemException
604+
* @throws \Magento\Framework\Exception\LocalizedException
605+
* @throws \Magento\Framework\Exception\RuntimeException
606+
*/
607+
public function testInstallWithInvalidRemoteStorageConfigurationWithEarlyRuntimeException()
608+
{
609+
$request = $this->request;
610+
611+
$logMessages = [
612+
['Starting Magento installation:'],
613+
['File permissions check...'],
614+
['Required extensions check...'],
615+
['Enabling Maintenance Mode...'],
616+
['Installing deployment configuration...'],
617+
['Installing database schema:'],
618+
['Schema creation/updates:'],
619+
];
620+
621+
$this->config->expects(static::atLeastOnce())
622+
->method('get')
623+
->willReturnMap(
624+
[
625+
[ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true],
626+
[ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true],
627+
['modules/Magento_User', null, '1']
628+
]
629+
);
630+
$allModules = ['Foo_One' => [], 'Bar_Two' => []];
631+
632+
$this->declarationInstallerMock
633+
->expects(static::once())
634+
->method('installSchema')
635+
->willThrowException(new RuntimeException(__('Remote driver is not available.')));
636+
637+
$this->expectException(RuntimeException::class);
638+
639+
$this->moduleLoader->expects(static::exactly(2))->method('load')->willReturn($allModules);
640+
$setup = $this->createMock(Setup::class);
641+
$table = $this->createMock(Table::class);
642+
$connection = $this->getMockBuilder(AdapterInterface::class)
643+
->setMethods(['getSchemaListener', 'newTable', 'getTables'])
644+
->getMockForAbstractClass();
645+
$connection->expects(static::any())->method('getSchemaListener')->willReturn($this->schemaListenerMock);
646+
$connection->expects(static::once())->method('getTables')->willReturn([]);
647+
$setup->expects(static::any())->method('getConnection')->willReturn($connection);
648+
$table->expects(static::any())->method('addColumn')->willReturn($table);
649+
$table->expects(static::any())->method('setComment')->willReturn($table);
650+
$table->expects(static::any())->method('addIndex')->willReturn($table);
651+
$connection->expects(static::any())->method('newTable')->willReturn($table);
652+
653+
$resource = $this->createMock(ResourceConnection::class);
654+
$this->contextMock->expects(static::once())->method('getResources')->willReturn($resource);
655+
656+
$dataSetup = $this->createMock(DataSetup::class);
657+
$dataSetup->expects(static::never())->method('getConnection');
658+
659+
$cacheManager = $this->createMock(Manager::class);
660+
$cacheManager->expects(static::never())->method('getAvailableTypes');
661+
662+
$registry = $this->createMock(Registry::class);
663+
664+
$remoteStorageValidatorMock = $this->getMockBuilder(RemoteStorageValidator::class)
665+
->disableOriginalConstructor()
666+
->getMock();
667+
668+
$remoteStorageValidatorMock
669+
->expects(static::never())
670+
->method('validate');
671+
672+
$this->configWriter
673+
->expects(static::once())
674+
->method('checkIfWritable')
675+
->willReturn(true);
676+
677+
$remoteStorageReversionArguments = [
678+
[
679+
ConfigFilePool::APP_ENV => [
680+
'remote_storage' => [
681+
'driver' => 'file'
682+
]
683+
]
684+
],
685+
true
686+
];
687+
688+
$this->configWriter
689+
->expects(static::at(2))
690+
->method('saveConfig')
691+
->with(...$remoteStorageReversionArguments);
692+
693+
$this->setupFactory->expects(static::once())->method('create')->with($resource)->willReturn($setup);
694+
695+
$this->objectManager->expects(static::any())
696+
->method('get')
697+
->willReturnMap([
698+
[DeclarationInstaller::class, $this->declarationInstallerMock],
699+
[Registry::class, $registry],
700+
]);
701+
702+
$this->sampleDataState->expects(static::never())->method('hasError');
703+
704+
$this->phpReadinessCheck->expects(static::once())->method('checkPhpExtensions')->willReturn(
705+
['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]
706+
);
707+
708+
$this->filePermissions->expects(static::exactly(2))
709+
->method('getMissingWritablePathsForInstallation')
710+
->willReturn([]);
711+
712+
call_user_func_array(
713+
[
714+
$this->logger->expects(static::exactly(count($logMessages)))->method('log'),
715+
'withConsecutive'
716+
],
717+
$logMessages
718+
);
719+
720+
$this->logger->expects(static::never())->method('logSuccess');
721+
722+
$this->object->install($request);
723+
}
724+
563725
/**
564726
* @return array
565727
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -664,6 +826,17 @@ public function installDataProvider()
664826
];
665827
}
666828

829+
/**
830+
* @return array
831+
*/
832+
public function installWithInvalidRemoteStorageConfigurationDataProvider()
833+
{
834+
return [
835+
[true],
836+
[false]
837+
];
838+
}
839+
667840
/**
668841
* Test for InstallDataFixtures
669842
*

0 commit comments

Comments
 (0)