Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
DeclarativeInstallerTest Class Reference
Inheritance diagram for DeclarativeInstallerTest:
SetupTestCase MutableDataInterface

Public Member Functions

 setUp ()
 
 testInstallation ()
 
 testInstallationWithColumnsModification ()
 
 testInstallationWithColumnsRemoval ()
 
 testInstallationWithConstraintsModification ()
 
 testInstallationWithDroppingTables ()
 
 testInstallWithCodeBaseRollback ()
 
 testTableRename ()
 
 testForeignKeyReferenceId ()
 
 testDisableIndexByExternalModule ()
 
- Public Member Functions inherited from SetupTestCase
 setData (array $data)
 
 flushData ()
 
 getData ()
 

Detailed Description

The purpose of this test is verifying declarative installation works.

Definition at line 22 of file DeclarativeInstallerTest.php.

Member Function Documentation

◆ setUp()

setUp ( )

Definition at line 54 of file DeclarativeInstallerTest.php.

55  {
57  $this->moduleManager = $objectManager->get(TestModuleManager::class);
58  $this->cliCommad = $objectManager->get(CliCommand::class);
59  $this->describeTable = $objectManager->get(DescribeTable::class);
60  $this->schemaDiff = $objectManager->get(SchemaDiff::class);
61  $this->schemaConfig = $objectManager->get(SchemaConfigInterface::class);
62  $this->resourceConnection = $objectManager->get(ResourceConnection::class);
63  }
$objectManager
Definition: bootstrap.php:17

◆ testDisableIndexByExternalModule()

testDisableIndexByExternalModule ( )

@moduleName Magento_TestSetupDeclarationModule1 @moduleName Magento_TestSetupDeclarationModule8

Definition at line 341 of file DeclarativeInstallerTest.php.

342  {
343  $this->cliCommad->install(
344  ['Magento_TestSetupDeclarationModule1', 'Magento_TestSetupDeclarationModule8']
345  );
346  $this->moduleManager->updateRevision(
347  'Magento_TestSetupDeclarationModule1',
348  'index_to_disable',
349  'db_schema.xml',
350  'etc'
351  );
352  $this->moduleManager->updateRevision(
353  'Magento_TestSetupDeclarationModule8',
354  'disable_index_by_external_module',
355  'db_schema.xml',
356  'etc'
357  );
358  $this->moduleManager->updateRevision(
359  'Magento_TestSetupDeclarationModule8',
360  'disable_index_by_external_module',
361  'db_schema_whitelist.json',
362  'etc'
363  );
364  $this->moduleManager->updateRevision(
365  'Magento_TestSetupDeclarationModule8',
366  'disable_index_by_external_module',
367  'module.xml',
368  'etc'
369  );
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`\)/',
375  $tableSql,
376  'Index is not being disabled by external module'
377  );
378  }

◆ testForeignKeyReferenceId()

testForeignKeyReferenceId ( )

@moduleName Magento_TestSetupDeclarationModule8

Definition at line 319 of file DeclarativeInstallerTest.php.

320  {
321  $this->cliCommad->install(
322  ['Magento_TestSetupDeclarationModule8']
323  );
324  $this->moduleManager->updateRevision(
325  'Magento_TestSetupDeclarationModule8',
326  'unpatterned_fk_name',
327  'db_schema.xml',
328  'etc'
329  );
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);
335  }

◆ testInstallation()

testInstallation ( )

@moduleName Magento_TestSetupDeclarationModule1 @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/installation.php

Definition at line 69 of file DeclarativeInstallerTest.php.

70  {
71  $this->cliCommad->install(
72  ['Magento_TestSetupDeclarationModule1']
73  );
74 
75  $diff = $this->schemaDiff->diff(
76  $this->schemaConfig->getDeclarationConfig(),
77  $this->schemaConfig->getDbConfig()
78  );
79 
80  //Second time installation should not find anything as we do not change anything
81  self::assertNull($diff->getAll());
82  $this->compareStructures();
83  }

◆ testInstallationWithColumnsModification()

testInstallationWithColumnsModification ( )

@moduleName Magento_TestSetupDeclarationModule1 @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/column_modification.php

Definition at line 108 of file DeclarativeInstallerTest.php.

109  {
110  $this->cliCommad->install(
111  ['Magento_TestSetupDeclarationModule1']
112  );
113 
114  //Move InstallSchema file and tried to install
115  $this->moduleManager->updateRevision(
116  'Magento_TestSetupDeclarationModule1',
117  'column_modifications',
118  'db_schema.xml',
119  'etc'
120  );
121 
122  $this->cliCommad->install(
123  ['Magento_TestSetupDeclarationModule1']
124  );
125 
126  $diff = $this->schemaDiff->diff(
127  $this->schemaConfig->getDeclarationConfig(),
128  $this->schemaConfig->getDbConfig()
129  );
130  self::assertNull($diff->getAll());
131  $this->compareStructures();
132  }

◆ testInstallationWithColumnsRemoval()

testInstallationWithColumnsRemoval ( )

@moduleName Magento_TestSetupDeclarationModule1 @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/column_removal.php

Definition at line 161 of file DeclarativeInstallerTest.php.

162  {
163  $this->cliCommad->install(
164  ['Magento_TestSetupDeclarationModule1']
165  );
166  $this->updateDbSchemaRevision('column_removals');
167  $this->cliCommad->install(
168  ['Magento_TestSetupDeclarationModule1']
169  );
170 
171  $diff = $this->schemaDiff->diff(
172  $this->schemaConfig->getDeclarationConfig(),
173  $this->schemaConfig->getDbConfig()
174  );
175  self::assertNull($diff->getAll());
176  $this->compareStructures();
177  }

◆ testInstallationWithConstraintsModification()

testInstallationWithConstraintsModification ( )

@moduleName Magento_TestSetupDeclarationModule1 @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/constraint_modification.php

Definition at line 199 of file DeclarativeInstallerTest.php.

200  {
201  $this->cliCommad->install(
202  ['Magento_TestSetupDeclarationModule1']
203  );
204  $this->updateDbSchemaRevision('constraint_modifications');
205  $this->cliCommad->upgrade();
206 
207  $diff = $this->schemaDiff->diff(
208  $this->schemaConfig->getDeclarationConfig(),
209  $this->schemaConfig->getDbConfig()
210  );
211  self::assertNull($diff->getAll());
212  $shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
213  self::assertEquals($this->getTrimmedData(), $shardData);
214  }

◆ testInstallationWithDroppingTables()

testInstallationWithDroppingTables ( )

@moduleName Magento_TestSetupDeclarationModule1 @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/table_removal.php

Definition at line 220 of file DeclarativeInstallerTest.php.

221  {
222  $this->cliCommad->install(
223  ['Magento_TestSetupDeclarationModule1']
224  );
225 
226  //Move db_schema.xml file and tried to install
227  $this->moduleManager->updateRevision(
228  'Magento_TestSetupDeclarationModule1',
229  'drop_table',
230  'db_schema.xml',
231  'etc'
232  );
233 
234  $this->cliCommad->upgrade();
235 
236  $diff = $this->schemaDiff->diff(
237  $this->schemaConfig->getDeclarationConfig(),
238  $this->schemaConfig->getDbConfig()
239  );
240  self::assertNull($diff->getAll());
241  $shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
242  self::assertEquals($this->getData(), $shardData);
243  }

◆ testInstallWithCodeBaseRollback()

testInstallWithCodeBaseRollback ( )

@moduleName Magento_TestSetupDeclarationModule1 @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/rollback.php

Definition at line 249 of file DeclarativeInstallerTest.php.

250  {
251  //Move db_schema.xml file and tried to install
252  $this->moduleManager->updateRevision(
253  'Magento_TestSetupDeclarationModule1',
254  'before_rollback',
255  'db_schema.xml',
256  'etc'
257  );
258  $this->cliCommad->install(
259  ['Magento_TestSetupDeclarationModule1']
260  );
261  $beforeRollback = $this->describeTable->describeShard('default');
262  self::assertEquals($this->getTrimmedData()['before'], $beforeRollback);
263  //Move db_schema.xml file and tried to install
264  $this->moduleManager->updateRevision(
265  'Magento_TestSetupDeclarationModule1',
266  'after_rollback',
267  'db_schema.xml',
268  'etc'
269  );
270 
271  $this->cliCommad->upgrade();
272  $afterRollback = $this->describeTable->describeShard('default');
273  self::assertEquals($this->getData()['after'], $afterRollback);
274  }

◆ testTableRename()

testTableRename ( )

@moduleName Magento_TestSetupDeclarationModule1 @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/table_rename.php

Definition at line 280 of file DeclarativeInstallerTest.php.

281  {
282  $dataToMigrate = ['some_column' => 'Some Value'];
283  //Move db_schema.xml file and tried to install
284  $this->moduleManager->updateRevision(
285  'Magento_TestSetupDeclarationModule1',
286  'table_rename',
287  'db_schema.xml',
288  'etc'
289  );
290  $this->cliCommad->install(
291  ['Magento_TestSetupDeclarationModule1']
292  );
293  $before = $this->describeTable->describeShard('default');
294  $adapter = $this->resourceConnection->getConnection('default');
295  $adapter->insert(
296  $this->resourceConnection->getTableName('some_table'),
297  $dataToMigrate
298  );
299  self::assertEquals($this->getData()['before'], $before['some_table']);
300  //Move db_schema.xml file and tried to install
301  $this->moduleManager->updateRevision(
302  'Magento_TestSetupDeclarationModule1',
303  'table_rename_after',
304  'db_schema.xml',
305  'etc'
306  );
307 
308  $this->cliCommad->upgrade();
309  $after = $this->describeTable->describeShard('default');
310  self::assertEquals($this->getData()['after'], $after['some_table_renamed']);
311  $select = $adapter->select()
312  ->from($this->resourceConnection->getTableName('some_table_renamed'));
313  self::assertEquals([$dataToMigrate], $adapter->fetchAll($select));
314  }
$adapter
Definition: webapi_user.php:16

The documentation for this class was generated from the following file: