27 private $moduleManager;
42 private $schemaConfig;
47 private $resourceConnection;
52 private $describeTable;
57 $this->moduleManager =
$objectManager->get(TestModuleManager::class);
61 $this->schemaConfig =
$objectManager->get(SchemaConfigInterface::class);
62 $this->resourceConnection =
$objectManager->get(ResourceConnection::class);
71 $this->cliCommad->install(
72 [
'Magento_TestSetupDeclarationModule1']
75 $diff = $this->schemaDiff->diff(
76 $this->schemaConfig->getDeclarationConfig(),
77 $this->schemaConfig->getDbConfig()
81 self::assertNull($diff->getAll());
82 $this->compareStructures();
88 private function compareStructures()
91 foreach ($this->getTrimmedData() as
$tableName => $sql) {
92 $this->assertArrayHasKey(
$tableName, $shardData);
97 if (preg_match(
'#ON DELETE\s+NO ACTION#i', $shardData[
$tableName] === 1)) {
98 preg_replace(
'#ON DELETE\s+NO ACTION#i',
'', $sql);
99 self::assertEquals($sql, $shardData[
$tableName]);
110 $this->cliCommad->install(
111 [
'Magento_TestSetupDeclarationModule1']
115 $this->moduleManager->updateRevision(
116 'Magento_TestSetupDeclarationModule1',
117 'column_modifications',
122 $this->cliCommad->install(
123 [
'Magento_TestSetupDeclarationModule1']
126 $diff = $this->schemaDiff->diff(
127 $this->schemaConfig->getDeclarationConfig(),
128 $this->schemaConfig->getDbConfig()
130 self::assertNull($diff->getAll());
131 $this->compareStructures();
139 private function updateDbSchemaRevision($revisionName)
142 $this->moduleManager->updateRevision(
143 'Magento_TestSetupDeclarationModule1',
149 $this->moduleManager->updateRevision(
150 'Magento_TestSetupDeclarationModule1',
152 'db_schema_whitelist.json',
163 $this->cliCommad->install(
164 [
'Magento_TestSetupDeclarationModule1']
166 $this->updateDbSchemaRevision(
'column_removals');
167 $this->cliCommad->install(
168 [
'Magento_TestSetupDeclarationModule1']
171 $diff = $this->schemaDiff->diff(
172 $this->schemaConfig->getDeclarationConfig(),
173 $this->schemaConfig->getDbConfig()
175 self::assertNull($diff->getAll());
176 $this->compareStructures();
185 private function getTrimmedData()
188 foreach ($this->
getData() as $key => $createTable) {
189 $data[$key] = preg_replace(
'/(\s)\n/',
'$1', $createTable);
201 $this->cliCommad->install(
202 [
'Magento_TestSetupDeclarationModule1']
204 $this->updateDbSchemaRevision(
'constraint_modifications');
205 $this->cliCommad->upgrade();
207 $diff = $this->schemaDiff->diff(
208 $this->schemaConfig->getDeclarationConfig(),
209 $this->schemaConfig->getDbConfig()
211 self::assertNull($diff->getAll());
213 self::assertEquals($this->getTrimmedData(), $shardData);
222 $this->cliCommad->install(
223 [
'Magento_TestSetupDeclarationModule1']
227 $this->moduleManager->updateRevision(
228 'Magento_TestSetupDeclarationModule1',
234 $this->cliCommad->upgrade();
236 $diff = $this->schemaDiff->diff(
237 $this->schemaConfig->getDeclarationConfig(),
238 $this->schemaConfig->getDbConfig()
240 self::assertNull($diff->getAll());
242 self::assertEquals($this->
getData(), $shardData);
252 $this->moduleManager->updateRevision(
253 'Magento_TestSetupDeclarationModule1',
258 $this->cliCommad->install(
259 [
'Magento_TestSetupDeclarationModule1']
261 $beforeRollback = $this->describeTable->describeShard(
'default');
262 self::assertEquals($this->getTrimmedData()[
'before'], $beforeRollback);
264 $this->moduleManager->updateRevision(
265 'Magento_TestSetupDeclarationModule1',
271 $this->cliCommad->upgrade();
272 $afterRollback = $this->describeTable->describeShard(
'default');
273 self::assertEquals($this->
getData()[
'after'], $afterRollback);
282 $dataToMigrate = [
'some_column' =>
'Some Value'];
284 $this->moduleManager->updateRevision(
285 'Magento_TestSetupDeclarationModule1',
290 $this->cliCommad->install(
291 [
'Magento_TestSetupDeclarationModule1']
293 $before = $this->describeTable->describeShard(
'default');
294 $adapter = $this->resourceConnection->getConnection(
'default');
296 $this->resourceConnection->getTableName(
'some_table'),
299 self::assertEquals($this->
getData()[
'before'], $before[
'some_table']);
301 $this->moduleManager->updateRevision(
302 'Magento_TestSetupDeclarationModule1',
303 'table_rename_after',
308 $this->cliCommad->upgrade();
309 $after = $this->describeTable->describeShard(
'default');
310 self::assertEquals($this->
getData()[
'after'], $after[
'some_table_renamed']);
312 ->from($this->resourceConnection->getTableName(
'some_table_renamed'));
321 $this->cliCommad->install(
322 [
'Magento_TestSetupDeclarationModule8']
324 $this->moduleManager->updateRevision(
325 'Magento_TestSetupDeclarationModule8',
326 'unpatterned_fk_name',
330 $this->cliCommad->upgrade();
331 $tableStatements = $this->describeTable->describeShard(
'default');
332 $tableSql = $tableStatements[
'dependent'];
333 $this->assertRegExp(
'/CONSTRAINT\s`DEPENDENT_PAGE_ID_ON_TEST_TABLE_PAGE_ID`/', $tableSql);
334 $this->assertRegExp(
'/CONSTRAINT\s`DEPENDENT_SCOPE_ID_ON_TEST_SCOPE_TABLE_SCOPE_ID`/', $tableSql);
343 $this->cliCommad->install(
344 [
'Magento_TestSetupDeclarationModule1',
'Magento_TestSetupDeclarationModule8']
346 $this->moduleManager->updateRevision(
347 'Magento_TestSetupDeclarationModule1',
352 $this->moduleManager->updateRevision(
353 'Magento_TestSetupDeclarationModule8',
354 'disable_index_by_external_module',
358 $this->moduleManager->updateRevision(
359 'Magento_TestSetupDeclarationModule8',
360 'disable_index_by_external_module',
361 'db_schema_whitelist.json',
364 $this->moduleManager->updateRevision(
365 'Magento_TestSetupDeclarationModule8',
366 'disable_index_by_external_module',
370 $this->cliCommad->upgrade();
371 $tableStatements = $this->describeTable->describeShard(
'default');
372 $tableSql = $tableStatements[
'test_table'];
373 $this->assertNotRegExp(
374 '/KEY\s+`TEST_TABLE_VARCHAR`\s+\(`varchar`\)/',
376 'Index is not being disabled by external module'
testInstallationWithDroppingTables()
testInstallationWithConstraintsModification()
testDisableIndexByExternalModule()
testInstallWithCodeBaseRollback()
testForeignKeyReferenceId()
static getObjectManager()
testInstallationWithColumnsModification()
testInstallationWithColumnsRemoval()