Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BCMultiModuleTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Setup;
8 
17 
23 {
27  private $moduleManager;
28 
32  private $cliCommand;
33 
37  private $dbVersionInfo;
38 
42  private $tableData;
43 
47  private $moduleResource;
48 
52  private $dbSchemaReader;
53 
54  public function setUp()
55  {
57  $this->moduleManager = $objectManager->get(TestModuleManager::class);
58  $this->cliCommand = $objectManager->get(CliCommand::class);
59  $this->dbVersionInfo = $objectManager->get(DbVersionInfo::class);
60  $this->tableData = $objectManager->get(TableData::class);
61  $this->moduleResource = $objectManager->get(ModuleResource::class);
62  $this->dbSchemaReader = $objectManager->get(DbSchemaReaderInterface::class);
63  }
64 
69  public function testFirstCleanInstall()
70  {
71  $this->cliCommand->install([
72  'Magento_TestSetupDeclarationModule6',
73  'Magento_TestSetupDeclarationModule7'
74  ]);
75  //Check if declaration is applied
76  $indexes = $this->dbSchemaReader->readIndexes('test_table', 'default');
77  self::assertCount(1, $indexes);
78  self::assertArrayHasKey('TEST_TABLE_TINYINT_BIGINT', $indexes);
79  //Check UpgradeSchema old format, that modify declaration
80  $columns = $this->dbSchemaReader->readColumns('test_table', 'default');
81  $floatColumn = $columns['float'];
82  self::assertEquals(29, $floatColumn['default']);
83  }
84 
85  private function doUsToUsRevision()
86  {
87  $this->moduleManager->updateRevision(
88  'Magento_TestSetupDeclarationModule7',
89  'us_to_us',
90  'UpgradeSchema.php',
91  'Setup'
92  );
93  $this->moduleManager->updateRevision(
94  'Magento_TestSetupDeclarationModule7',
95  'us_to_us',
96  'module.xml',
97  'etc'
98  );
99  $this->moduleManager->updateRevision(
100  'Magento_TestSetupDeclarationModule7',
101  'us_to_us',
102  'UpgradeData.php',
103  'Setup'
104  );
105  }
106 
107  private function doUsToDsRevision()
108  {
109  $this->moduleManager->updateRevision(
110  'Magento_TestSetupDeclarationModule7',
111  'swap_with_declaration',
112  'db_schema.xml',
113  'etc'
114  );
115  $this->moduleManager->updateRevision(
116  'Magento_TestSetupDeclarationModule7',
117  'swap_with_declaration',
118  'SomePatch.php',
119  'Setup/Patch/Data'
120  );
121  $this->moduleManager->updateRevision(
122  'Magento_TestSetupDeclarationModule7',
123  'swap_with_declaration',
124  'SomeSkippedPatch.php',
125  'Setup/Patch/Data'
126  );
127  }
128 
132  private function assertUsToUsUpgrade()
133  {
134  $usToUsTables = $this->dbSchemaReader->readTables('default');
135  self::assertContains('custom_table', $usToUsTables);
136  self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule7'));
137  self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule7'));
138  self::assertEquals(
139  [6,12],
140  $this->tableData->describeTableData('reference_table', 'bigint_without_padding')
141  );
142  }
143 
147  private function assertUsToDsUpgrade()
148  {
149  //Check UpgradeSchema old format, that modify declaration
150  $columns = $this->dbSchemaReader->readColumns('test_table', 'default');
151  $floatColumn = $columns['float'];
152  //Check whether declaration will be applied
153  self::assertEquals(35, $floatColumn['default']);
154  self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule7'));
155  self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule7'));
156  self::assertEquals(
157  [6,12],
158  $this->tableData->describeTableData('reference_table', 'bigint_without_padding')
159  );
160  self::assertEquals(
161  ['_ref'],
162  $this->tableData->describeTableData('test_table', 'varchar')
163  );
164  }
165 
170  public function testDSFirstRelease()
171  {
172  $this->cliCommand->install([
173  'Magento_TestSetupDeclarationModule6',
174  'Magento_TestSetupDeclarationModule7'
175  ]);
176  //Check no change upgrade with US
177  $this->cliCommand->upgrade();
178 
179  $this->doUsToUsRevision();
180  //Check US to US upgrade
181  $this->cliCommand->upgrade();
182  $this->assertUsToUsUpgrade();
183 
184  $this->doUsToDsRevision();
185  //Check US to declarative schema upgrade
186  $this->cliCommand->upgrade();
187  $this->assertUsToDsUpgrade();
188 
189  $this->moduleManager->updateRevision(
190  'Magento_TestSetupDeclarationModule7',
191  'wl_remove_table',
192  'db_schema_whitelist.json',
193  'etc'
194  );
195  //Check removal case, when we need to remove table with declaration and table was created in old scripts
196  $this->cliCommand->upgrade();
197  $tables = $this->dbSchemaReader->readTables('default');
198  self::assertNotContains('custom_table', $tables);
199  }
200 
212  string $dbPrefix,
213  string $tableName,
214  string $indexName,
215  string $constraintName,
216  string $foreignKeyName
217  ) {
218  $this->cliCommand->install(
219  [
220  'Magento_TestSetupDeclarationModule1'
221  ],
222  [
223  'db-prefix' => $dbPrefix,
224  ]
225  );
226 
227  $indexes = $this->dbSchemaReader
228  ->readIndexes($tableName, 'default');
229  self::assertCount(1, $indexes);
230  self::assertArrayHasKey($indexName, $indexes);
231 
232  $constraints = $this->dbSchemaReader
233  ->readConstraints($tableName, 'default');
234  self::assertCount(1, $constraints);
235  self::assertArrayHasKey($constraintName, $constraints);
236 
237  $foreignKeys = $this->dbSchemaReader
238  ->readReferences($tableName, 'default');
239  self::assertCount(1, $foreignKeys);
240  self::assertArrayHasKey($foreignKeyName, $foreignKeys);
241  }
242 
247  {
248  return [
249  'Installation without db prefix' => [
250  'dbPrefix' => '',
251  'tableName' => 'test_table',
252  'indexName' => 'TEST_TABLE_TINYINT_BIGINT',
253  'constraintName' => 'TEST_TABLE_SMALLINT_BIGINT',
254  'foreignKeyName' => 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF',
255  ],
256  'Installation with db prefix' => [
257  'dbPrefix' => 'spec_',
258  'tableName' => 'spec_test_table',
259  'indexName' => 'SPEC_TEST_TABLE_TINYINT_BIGINT',
260  'constraintName' => 'SPEC_TEST_TABLE_SMALLINT_BIGINT',
261  'foreignKeyName' => 'SPEC_TEST_TABLE_TINYINT_SPEC_REFERENCE_TABLE_TINYINT_REF',
262  ]
263  ];
264  }
265 }
$tableName
Definition: trigger.php:13
$objectManager
Definition: bootstrap.php:17
testFirstCleanInstallOneModule(string $dbPrefix, string $tableName, string $indexName, string $constraintName, string $foreignKeyName)
$columns
Definition: default.phtml:15