Skip to content

Commit 38239a4

Browse files
committed
B2B-1785: Cannot enable remote storage with install command when modules are not enabled
1 parent 55d1f65 commit 38239a4

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

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

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
use PHPUnit\Framework\TestCase;
5757
use Magento\Setup\Model\SearchConfig;
5858
use Magento\RemoteStorage\Setup\ConfigOptionsList as RemoteStorageValidator;
59+
use ReflectionException;
5960

6061
/**
6162
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -711,6 +712,179 @@ public function installWithInvalidRemoteStorageConfigurationDataProvider()
711712
];
712713
}
713714

715+
/**
716+
* Test that installation with unresolvable remote storage validator object still produces successful install
717+
* in case RemoteStorage module is not available.
718+
*
719+
* @throws \Magento\Framework\Exception\FileSystemException
720+
* @throws \Magento\Framework\Exception\LocalizedException
721+
* @throws \Magento\Framework\Exception\RuntimeException
722+
*/
723+
public function testInstallWithUnresolvableRemoteStorageValidator()
724+
{
725+
$request = $this->request;
726+
727+
// every log message call is expected
728+
$logMessages = $this->installDataProvider()[0]['logMessages'];
729+
730+
$this->config->expects(static::atLeastOnce())
731+
->method('get')
732+
->willReturnMap(
733+
[
734+
[ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true],
735+
[ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true],
736+
['modules/Magento_User', null, '1']
737+
]
738+
);
739+
$allModules = ['Foo_One' => [], 'Bar_Two' => []];
740+
741+
$this->declarationInstallerMock->expects(static::once())->method('installSchema');
742+
$this->moduleLoader->expects(static::any())->method('load')->willReturn($allModules);
743+
$setup = $this->createMock(Setup::class);
744+
$table = $this->createMock(Table::class);
745+
$connection = $this->getMockBuilder(AdapterInterface::class)
746+
->setMethods(['getSchemaListener', 'newTable', 'getTables'])
747+
->getMockForAbstractClass();
748+
$connection->expects(static::any())->method('getSchemaListener')->willReturn($this->schemaListenerMock);
749+
$connection->expects(static::once())->method('getTables')->willReturn([]);
750+
$setup->expects(static::any())->method('getConnection')->willReturn($connection);
751+
$table->expects(static::any())->method('addColumn')->willReturn($table);
752+
$table->expects(static::any())->method('setComment')->willReturn($table);
753+
$table->expects(static::any())->method('addIndex')->willReturn($table);
754+
$connection->expects(static::any())->method('newTable')->willReturn($table);
755+
$resource = $this->createMock(ResourceConnection::class);
756+
$this->contextMock->expects(static::any())->method('getResources')->willReturn($resource);
757+
$resource->expects(static::any())->method('getConnection')->willReturn($connection);
758+
$dataSetup = $this->createMock(DataSetup::class);
759+
$dataSetup->expects(static::any())->method('getConnection')->willReturn($connection);
760+
$cacheManager = $this->createMock(Manager::class);
761+
$cacheManager->expects(static::any())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
762+
$cacheManager->expects(static::exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']);
763+
$cacheManager->expects(static::exactly(3))->method('clean');
764+
$cacheManager->expects(static::exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]);
765+
$appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
766+
->disableOriginalConstructor()
767+
->disableArgumentCloning()
768+
->getMock();
769+
$appState->expects(static::once())
770+
->method('setAreaCode')
771+
->with(Area::AREA_GLOBAL);
772+
$registry = $this->createMock(Registry::class);
773+
$searchConfigMock = $this->getMockBuilder(SearchConfig::class)->disableOriginalConstructor()->getMock();
774+
775+
$remoteStorageValidatorMock = $this->getMockBuilder(RemoteStorageValidator::class)
776+
->disableOriginalConstructor()
777+
->getMock();
778+
779+
$this->configWriter->expects(static::never())->method('checkIfWritable');
780+
781+
$remoteStorageValidatorMock
782+
->expects(static::never())
783+
->method('validate');
784+
785+
$remoteStorageReversionArguments = [
786+
[
787+
ConfigFilePool::APP_ENV => [
788+
'remote_storage' => [
789+
'driver' => 'file'
790+
]
791+
]
792+
],
793+
true
794+
];
795+
796+
// assert remote storage reversion is never attempted
797+
$this->configWriter
798+
->expects(static::any())
799+
->method('saveConfig')
800+
->willReturnCallback(function (array $data, $override) use ($remoteStorageReversionArguments) {
801+
$this->assertNotEquals($remoteStorageReversionArguments, [$data, $override]);
802+
});
803+
804+
$this->setupFactory->expects(static::atLeastOnce())->method('create')->with($resource)->willReturn($setup);
805+
$this->dataSetupFactory->expects(static::atLeastOnce())->method('create')->willReturn($dataSetup);
806+
$this->objectManager->expects(static::any())
807+
->method('create')
808+
->willReturnMap([
809+
[Manager::class, [], $cacheManager],
810+
[\Magento\Framework\App\State::class, [], $appState],
811+
[
812+
PatchApplierFactory::class,
813+
['objectManager' => $this->objectManager],
814+
$this->patchApplierFactoryMock
815+
],
816+
]);
817+
$this->patchApplierMock->expects(static::exactly(2))->method('applySchemaPatch')->willReturnMap(
818+
[
819+
['Bar_Two'],
820+
['Foo_One'],
821+
]
822+
);
823+
$this->patchApplierMock->expects(static::exactly(2))->method('applyDataPatch')->willReturnMap(
824+
[
825+
['Bar_Two'],
826+
['Foo_One'],
827+
]
828+
);
829+
830+
$objectManagerReturnMapSequence = [
831+
0 => [Registry::class, $registry],
832+
1 => [DeclarationInstaller::class, $this->declarationInstallerMock],
833+
3 => [SearchConfig::class, $searchConfigMock],
834+
4 => [
835+
RemoteStorageValidator::class,
836+
new ReflectionException('Class ' . RemoteStorageValidator::class . ' does not exist'),
837+
],
838+
5 => [\Magento\Framework\App\State::class, $appState],
839+
7 => [Registry::class, $registry],
840+
11 => [Manager::class, $cacheManager],
841+
];
842+
843+
foreach ($objectManagerReturnMapSequence as $idx => $map) {
844+
list($getArgument, $mockedObject) = $map;
845+
846+
$expectation = $this->objectManager
847+
->expects(static::at($idx))
848+
->method('get')
849+
->with($getArgument);
850+
851+
if ($mockedObject instanceof \Exception) {
852+
$expectation->willThrowException($mockedObject);
853+
} else {
854+
$expectation->willReturn($mockedObject);
855+
}
856+
}
857+
858+
$this->adminFactory->expects(static::any())->method('create')->willReturn(
859+
$this->createMock(AdminAccount::class)
860+
);
861+
$this->sampleDataState->expects(static::once())->method('hasError')->willReturn(true);
862+
$this->phpReadinessCheck->expects(static::once())->method('checkPhpExtensions')->willReturn(
863+
['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]
864+
);
865+
$this->filePermissions->expects(static::any())
866+
->method('getMissingWritablePathsForInstallation')
867+
->willReturn([]);
868+
$this->filePermissions->expects(static::once())
869+
->method('getMissingWritableDirectoriesForDbUpgrade')
870+
->willReturn([]);
871+
call_user_func_array(
872+
[
873+
$this->logger->expects(static::exactly(count($logMessages)))->method('log'),
874+
'withConsecutive'
875+
],
876+
$logMessages
877+
);
878+
$this->logger->expects(static::exactly(2))
879+
->method('logSuccess')
880+
->withConsecutive(
881+
['Magento installation complete.'],
882+
['Magento Admin URI: /']
883+
);
884+
885+
$this->object->install($request);
886+
}
887+
714888
/**
715889
* Test installation with invalid remote storage configuration is able to be caught earlier than
716890
* the queued validation step if necessary, and that configuration is reverted back to local file driver.

0 commit comments

Comments
 (0)