|
22 | 22 | use Magento\Framework\Config\File\ConfigFilePool;
|
23 | 23 | use Magento\Framework\DB\Adapter\AdapterInterface;
|
24 | 24 | use Magento\Framework\DB\Ddl\Table;
|
| 25 | + use Magento\Framework\Exception\RuntimeException; |
25 | 26 | use Magento\Framework\Filesystem;
|
26 | 27 | use Magento\Framework\Filesystem\Directory\WriteInterface;
|
27 | 28 | use Magento\Framework\Filesystem\DriverPool;
|
@@ -358,6 +359,8 @@ public function testInstall(array $request, array $logMessages)
|
358 | 359 | ->disableOriginalConstructor()
|
359 | 360 | ->getMock();
|
360 | 361 |
|
| 362 | + $this->configWriter->expects(static::never())->method('checkIfWritable'); |
| 363 | + |
361 | 364 | $this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup);
|
362 | 365 | $this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup);
|
363 | 366 | $this->objectManager->expects($this->any())
|
@@ -424,13 +427,16 @@ public function testInstall(array $request, array $logMessages)
|
424 | 427 | }
|
425 | 428 |
|
426 | 429 | /**
|
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 |
428 | 432 | *
|
| 433 | + * @param bool $isDeploymentConfigWritable |
| 434 | + * @dataProvider installWithInvalidRemoteStorageConfigurationDataProvider |
429 | 435 | * @throws \Magento\Framework\Exception\FileSystemException
|
430 | 436 | * @throws \Magento\Framework\Exception\LocalizedException
|
431 | 437 | * @throws \Magento\Framework\Exception\RuntimeException
|
432 | 438 | */
|
433 |
| - public function testInstallWithInvalidRemoteStorageConfiguration() |
| 439 | + public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploymentConfigWritable) |
434 | 440 | {
|
435 | 441 | $request = $this->request;
|
436 | 442 |
|
@@ -507,6 +513,36 @@ public function testInstallWithInvalidRemoteStorageConfiguration()
|
507 | 513 |
|
508 | 514 | $this->expectException(ValidationException::class);
|
509 | 515 |
|
| 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 | + |
510 | 546 | $this->setupFactory->expects(static::once())->method('create')->with($resource)->willReturn($setup);
|
511 | 547 |
|
512 | 548 | $this->objectManager->expects(static::any())
|
@@ -560,6 +596,132 @@ public function testInstallWithInvalidRemoteStorageConfiguration()
|
560 | 596 | $this->object->install($request);
|
561 | 597 | }
|
562 | 598 |
|
| 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 | + |
563 | 725 | /**
|
564 | 726 | * @return array
|
565 | 727 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
@@ -664,6 +826,17 @@ public function installDataProvider()
|
664 | 826 | ];
|
665 | 827 | }
|
666 | 828 |
|
| 829 | + /** |
| 830 | + * @return array |
| 831 | + */ |
| 832 | + public function installWithInvalidRemoteStorageConfigurationDataProvider() |
| 833 | + { |
| 834 | + return [ |
| 835 | + [true], |
| 836 | + [false] |
| 837 | + ]; |
| 838 | + } |
| 839 | + |
667 | 840 | /**
|
668 | 841 | * Test for InstallDataFixtures
|
669 | 842 | *
|
|
0 commit comments