BCPatchTest.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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\Module\DbVersionInfo;
  8. use Magento\Framework\Module\ModuleList;
  9. use Magento\Framework\Module\ModuleResource;
  10. use Magento\TestFramework\Deploy\CliCommand;
  11. use Magento\TestFramework\Deploy\TableData;
  12. use Magento\TestFramework\Deploy\TestModuleManager;
  13. use Magento\TestFramework\Helper\Bootstrap;
  14. use Magento\TestFramework\TestCase\SetupTestCase;
  15. /**
  16. * The purpose of this test is to check whether patch changes in Magento are backward compatible
  17. */
  18. class BCPatchTest extends SetupTestCase
  19. {
  20. /**
  21. * @var TestModuleManager
  22. */
  23. private $moduleManager;
  24. /**
  25. * @var CliCommand
  26. */
  27. private $cliCommand;
  28. /**
  29. * @var DbVersionInfo
  30. */
  31. private $dbVersionInfo;
  32. /**
  33. * @var TableData
  34. */
  35. private $tableData;
  36. /**
  37. * @var ModuleResource
  38. */
  39. private $moduleResource;
  40. public function setUp()
  41. {
  42. $objectManager = Bootstrap::getObjectManager();
  43. $this->moduleManager = $objectManager->get(TestModuleManager::class);
  44. $this->cliCommand = $objectManager->get(CliCommand::class);
  45. $this->dbVersionInfo = $objectManager->get(DbVersionInfo::class);
  46. $this->tableData = $objectManager->get(TableData::class);
  47. $this->moduleResource = $objectManager->get(ModuleResource::class);
  48. }
  49. /**
  50. * @moduleName Magento_TestSetupDeclarationModule5
  51. */
  52. public function testSuccessfullInstall()
  53. {
  54. $this->cliCommand->install(['Magento_TestSetupDeclarationModule5']);
  55. self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
  56. self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
  57. }
  58. /**
  59. * @moduleName Magento_TestSetupDeclarationModule5
  60. */
  61. public function testDataMixedMode()
  62. {
  63. $this->moduleManager->updateRevision(
  64. 'Magento_TestSetupDeclarationModule5',
  65. 'old-scripts',
  66. 'UpgradeData.php',
  67. 'Setup'
  68. );
  69. $this->moduleManager->updateRevision(
  70. 'Magento_TestSetupDeclarationModule5',
  71. 'patches',
  72. 'SomePatch.php',
  73. 'Setup/Patch/Data'
  74. );
  75. $this->cliCommand->install(['Magento_TestSetupDeclarationModule5']);
  76. self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
  77. self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
  78. self::assertEquals(
  79. [6,12],
  80. $this->tableData->describeTableData('reference_table', 'some_integer')
  81. );
  82. self::assertEquals(
  83. ['_ref'],
  84. $this->tableData->describeTableData('test_table', 'varchar')
  85. );
  86. }
  87. /**
  88. * @moduleName Magento_TestSetupDeclarationModule5
  89. */
  90. public function testSkippedPatch()
  91. {
  92. $this->moduleManager->updateRevision(
  93. 'Magento_TestSetupDeclarationModule5',
  94. 'patches',
  95. 'SomePatch.php',
  96. 'Setup/Patch/Data'
  97. );
  98. $this->moduleManager->updateRevision(
  99. 'Magento_TestSetupDeclarationModule5',
  100. 'patches',
  101. 'SomeSkippedPatch.php',
  102. 'Setup/Patch/Data'
  103. );
  104. $this->cliCommand->install(['Magento_TestSetupDeclarationModule5']);
  105. self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
  106. self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
  107. self::assertEquals(
  108. ['_ref'],
  109. $this->tableData->describeTableData('test_table', 'varchar')
  110. );
  111. }
  112. /**
  113. * @moduleName Magento_TestSetupDeclarationModule5
  114. */
  115. public function testDataInstallationWithoutVersion()
  116. {
  117. $this->moduleManager->updateRevision(
  118. 'Magento_TestSetupDeclarationModule5',
  119. 'module-without-version',
  120. 'module.xml',
  121. 'etc'
  122. );
  123. $this->cliCommand->install(['Magento_TestSetupDeclarationModule5']);
  124. self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
  125. self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
  126. $this->moduleResource->setDataVersion('Magento_TestSetupDeclarationModule5', '1.0.2');
  127. $this->moduleResource->setDataVersion('Magento_TestSetupDeclarationModule5', '1.0.2');
  128. $this->moduleManager->updateRevision(
  129. 'Magento_TestSetupDeclarationModule5',
  130. 'old-scripts',
  131. 'UpgradeData.php',
  132. 'Setup'
  133. );
  134. $this->moduleManager->updateRevision(
  135. 'Magento_TestSetupDeclarationModule5',
  136. 'patches',
  137. 'SomePatch.php',
  138. 'Setup/Patch/Data'
  139. );
  140. $this->moduleManager->updateRevision(
  141. 'Magento_TestSetupDeclarationModule5',
  142. 'patches',
  143. 'SomeSkippedPatch.php',
  144. 'Setup/Patch/Data'
  145. );
  146. $this->cliCommand->upgrade();
  147. self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
  148. self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
  149. //Old scripts should be skipped because we do not have version
  150. self::assertEquals(
  151. [],
  152. $this->tableData->describeTableData('reference_table', 'some_integer')
  153. );
  154. self::assertEquals(
  155. ['_ref'],
  156. $this->tableData->describeTableData('test_table', 'varchar')
  157. );
  158. }
  159. }