Skip to content

Commit 5534fc7

Browse files
committed
B2B-1785: Cannot enable remote storage with install command when modules are not enabled
1 parent 8953ec1 commit 5534fc7

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

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

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Magento\Framework\Setup\Patch\PatchApplierFactory;
3737
use Magento\Framework\Setup\SampleData\State;
3838
use Magento\Framework\Setup\SchemaListener;
39+
use Magento\Framework\Validation\ValidationException;
3940
use Magento\Setup\Controller\ResponseTypeInterface;
4041
use Magento\Setup\Model\AdminAccount;
4142
use Magento\Setup\Model\AdminAccountFactory;
@@ -422,6 +423,143 @@ public function testInstall(array $request, array $logMessages)
422423
$this->object->install($request);
423424
}
424425

426+
/**
427+
* Test installation with invalid remote storage configuration raises ValidationException
428+
*
429+
* @throws \Magento\Framework\Exception\FileSystemException
430+
* @throws \Magento\Framework\Exception\LocalizedException
431+
* @throws \Magento\Framework\Exception\RuntimeException
432+
*/
433+
public function testInstallWithInvalidRemoteStorageConfiguration()
434+
{
435+
$request = $this->request;
436+
437+
$logMessages = [
438+
['Starting Magento installation:'],
439+
['File permissions check...'],
440+
['Required extensions check...'],
441+
['Enabling Maintenance Mode...'],
442+
['Installing deployment configuration...'],
443+
['Installing database schema:'],
444+
['Schema creation/updates:'],
445+
['Module \'Foo_One\':'],
446+
['Module \'Bar_Two\':'],
447+
['Schema post-updates:'],
448+
['Module \'Foo_One\':'],
449+
['Module \'Bar_Two\':'],
450+
['Installing search configuration...'],
451+
['Validating remote file storage configuration...'],
452+
];
453+
454+
$this->config->expects(static::atLeastOnce())
455+
->method('get')
456+
->willReturnMap(
457+
[
458+
[ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true],
459+
[ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true],
460+
['modules/Magento_User', null, '1']
461+
]
462+
);
463+
$allModules = ['Foo_One' => [], 'Bar_Two' => []];
464+
465+
$this->declarationInstallerMock->expects(static::once())->method('installSchema');
466+
$this->moduleLoader->expects(static::exactly(2))->method('load')->willReturn($allModules);
467+
$setup = $this->createMock(Setup::class);
468+
$table = $this->createMock(Table::class);
469+
$connection = $this->getMockBuilder(AdapterInterface::class)
470+
->setMethods(['getSchemaListener', 'newTable', 'getTables'])
471+
->getMockForAbstractClass();
472+
$connection->expects(static::any())->method('getSchemaListener')->willReturn($this->schemaListenerMock);
473+
$connection->expects(static::once())->method('getTables')->willReturn([]);
474+
$setup->expects(static::any())->method('getConnection')->willReturn($connection);
475+
$table->expects(static::any())->method('addColumn')->willReturn($table);
476+
$table->expects(static::any())->method('setComment')->willReturn($table);
477+
$table->expects(static::any())->method('addIndex')->willReturn($table);
478+
$connection->expects(static::any())->method('newTable')->willReturn($table);
479+
480+
$resource = $this->createMock(ResourceConnection::class);
481+
$resource->expects(static::any())->method('getConnection')->willReturn($connection);
482+
483+
$this->contextMock->expects(static::exactly(2))->method('getResources')->willReturn($resource);
484+
485+
$dataSetup = $this->createMock(DataSetup::class);
486+
$dataSetup->expects(static::never())->method('getConnection');
487+
488+
$cacheManager = $this->createMock(Manager::class);
489+
$cacheManager->expects(static::never())->method('getAvailableTypes');
490+
491+
$appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
492+
->disableOriginalConstructor()
493+
->disableArgumentCloning()
494+
->getMock();
495+
$registry = $this->createMock(Registry::class);
496+
$searchConfigMock = $this->getMockBuilder(SearchConfig::class)->disableOriginalConstructor()->getMock();
497+
498+
$remoteFileStorageValidatorMock = $this->getMockBuilder(RemoteFileStorageValidator::class)
499+
->disableOriginalConstructor()
500+
->getMock();
501+
502+
$remoteFileStorageValidatorMock
503+
->expects(static::once())
504+
->method('validate')
505+
->with($request, $this->config)
506+
->willReturn(['Invalid Remote File Storage!']);
507+
508+
$this->expectException(ValidationException::class);
509+
510+
$this->setupFactory->expects(static::once())->method('create')->with($resource)->willReturn($setup);
511+
512+
$this->objectManager->expects(static::any())
513+
->method('create')
514+
->willReturnMap([
515+
[Manager::class, [], $cacheManager],
516+
[\Magento\Framework\App\State::class, [], $appState],
517+
[
518+
PatchApplierFactory::class,
519+
['objectManager' => $this->objectManager],
520+
$this->patchApplierFactoryMock
521+
],
522+
]);
523+
$this->patchApplierMock->expects(static::exactly(2))->method('applySchemaPatch')->willReturnMap(
524+
[
525+
['Bar_Two'],
526+
['Foo_One'],
527+
]
528+
);
529+
$this->objectManager->expects(static::any())
530+
->method('get')
531+
->willReturnMap([
532+
[\Magento\Framework\App\State::class, $appState],
533+
[Manager::class, $cacheManager],
534+
[DeclarationInstaller::class, $this->declarationInstallerMock],
535+
[Registry::class, $registry],
536+
[SearchConfig::class, $searchConfigMock],
537+
[RemoteFileStorageValidator::class, $remoteFileStorageValidatorMock],
538+
]);
539+
540+
$this->sampleDataState->expects(static::never())->method('hasError');
541+
542+
$this->phpReadinessCheck->expects(static::once())->method('checkPhpExtensions')->willReturn(
543+
['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]
544+
);
545+
546+
$this->filePermissions->expects(static::exactly(2))
547+
->method('getMissingWritablePathsForInstallation')
548+
->willReturn([]);
549+
550+
call_user_func_array(
551+
[
552+
$this->logger->expects(static::exactly(count($logMessages)))->method('log'),
553+
'withConsecutive'
554+
],
555+
$logMessages
556+
);
557+
558+
$this->logger->expects(static::never())->method('logSuccess');
559+
560+
$this->object->install($request);
561+
}
562+
425563
/**
426564
* @return array
427565
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)

0 commit comments

Comments
 (0)