SafeInstallerTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Setup;
  7. use Magento\Framework\App\ResourceConnection;
  8. use Magento\Framework\Setup\Declaration\Schema\Diff\SchemaDiff;
  9. use Magento\Framework\Setup\Declaration\Schema\SchemaConfigInterface;
  10. use Magento\Framework\Setup\Declaration\Schema\Sharding;
  11. use Magento\TestFramework\Deploy\CliCommand;
  12. use Magento\TestFramework\Deploy\DescribeTable;
  13. use Magento\TestFramework\Deploy\TestModuleManager;
  14. use Magento\TestFramework\Helper\Bootstrap;
  15. use Magento\TestFramework\TestCase\SetupTestCase;
  16. /**
  17. * The purpose of this test is verifying safe declarative installation works.
  18. */
  19. class SafeInstallerTest extends SetupTestCase
  20. {
  21. /**
  22. * @var TestModuleManager
  23. */
  24. private $moduleManager;
  25. /**
  26. * @var CliCommand
  27. */
  28. private $cliCommad;
  29. /**
  30. * @var ResourceConnection
  31. */
  32. private $resourceConnection;
  33. public function setUp()
  34. {
  35. $objectManager = Bootstrap::getObjectManager();
  36. $this->moduleManager = $objectManager->get(TestModuleManager::class);
  37. $this->cliCommad = $objectManager->get(CliCommand::class);
  38. $this->resourceConnection = $objectManager->get(ResourceConnection::class);
  39. }
  40. /**
  41. * @moduleName Magento_TestSetupDeclarationModule4
  42. * @dataProviderFromFile Magento/TestSetupDeclarationModule4/fixture/safe_data_provider.php
  43. */
  44. public function testInstallation()
  45. {
  46. $testTableData = $this->getData();
  47. $row = reset($testTableData);
  48. $this->cliCommad->install(['Magento_TestSetupDeclarationModule4']);
  49. $adapter = $this->resourceConnection->getConnection();
  50. $testTableName = $this->resourceConnection->getTableName('test_table');
  51. $adapter->insertArray(
  52. $this->resourceConnection->getTableName('test_table'),
  53. array_keys($row),
  54. $this->getData()
  55. );
  56. //Move new db_schema.xml
  57. $this->moduleManager->updateRevision(
  58. 'Magento_TestSetupDeclarationModule4',
  59. 'remove_title_column',
  60. 'db_schema.xml',
  61. 'etc'
  62. );
  63. $this->cliCommad->upgrade(
  64. [
  65. 'safe-mode' => true,
  66. ]
  67. );
  68. //Move new db_schema.xml with restored title field
  69. $this->moduleManager->updateRevision(
  70. 'Magento_TestSetupDeclarationModule4',
  71. 'restore_title_column',
  72. 'db_schema.xml',
  73. 'etc'
  74. );
  75. $this->cliCommad->upgrade(
  76. [
  77. 'data-restore' => true,
  78. ]
  79. );
  80. $testTableSelect = $adapter->select()->from($testTableName);
  81. self::assertEquals($testTableData, $adapter->fetchAll($testTableSelect));
  82. }
  83. }