Skip to content

Commit 0bf8327

Browse files
author
Sergii Kovalenko
committed
MAGETWO-87928: Implement infrastructure for safe-rollback feature
--add integration test
1 parent 3c169d1 commit 0bf8327

File tree

6 files changed

+72
-26
lines changed

6 files changed

+72
-26
lines changed

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule4/etc/db_schema.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:setup:Model/Declaration/Schema/etc/schema.xsd">
1010
<table name="test_table" resource="default" comment="Test Table">
11-
<column xsi:type="int" name="page_id" />
12-
<column xsi:type="varchar" name="email" />
11+
<column xsi:type="int" name="page_id" nullable="false" />
12+
<column xsi:type="varchar" name="email" nullable="false" />
1313
<column xsi:type="varchar" name="title" />
1414
<constraint xsi:type="primary" name="PRIMARY">
1515
<column name="page_id" />

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule4/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_TestSetupDeclarationModule4" />
9+
<module name="Magento_TestSetupDeclarationModule4" setup_version="1.0.0" />
1010
</config>

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule4/registration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
use Magento\Framework\Component\ComponentRegistrar;
88

99
$registrar = new ComponentRegistrar();
10-
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestSetupDeclarationModule1') === null) {
11-
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestSetupDeclarationModule1', __DIR__);
10+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestSetupDeclarationModule4') === null) {
11+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestSetupDeclarationModule4', __DIR__);
1212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:setup:Model/Declaration/Schema/etc/schema.xsd">
10+
<table name="test_table" resource="default" comment="Test Table">
11+
<column xsi:type="int" name="page_id" nullable="false" />
12+
<column xsi:type="varchar" name="email" nullable="false" />
13+
<constraint xsi:type="primary" name="PRIMARY">
14+
<column name="page_id" />
15+
<column name="email" />
16+
</constraint>
17+
</table>
18+
</schema>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:setup:Model/Declaration/Schema/etc/schema.xsd">
10+
<table name="test_table" resource="default" comment="Test Table">
11+
<column xsi:type="int" name="page_id" nullable="false" />
12+
<column xsi:type="varchar" name="email" nullable="false" />
13+
<column xsi:type="varchar" name="title" />
14+
<constraint xsi:type="primary" name="PRIMARY">
15+
<column name="page_id" />
16+
<column name="email" />
17+
</constraint>
18+
</table>
19+
</schema>

dev/tests/setup-integration/testsuite/Magento/Setup/SafeInstallerTest.php

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,55 @@ class SafeInstallerTest extends SetupTestCase
3131
*/
3232
private $cliCommad;
3333

34-
/**
35-
* @var SchemaDiff
36-
*/
37-
private $schemaDiff;
38-
39-
/**
40-
* @var SchemaConfigInterface
41-
*/
42-
private $schemaConfig;
43-
4434
/**
4535
* @var ResourceConnection
4636
*/
4737
private $resourceConnection;
4838

49-
/**
50-
* @var DescribeTable
51-
*/
52-
private $describeTable;
5339

5440
public function setUp()
5541
{
5642
$objectManager = Bootstrap::getObjectManager();
5743
$this->moduleManager = $objectManager->get(TestModuleManager::class);
5844
$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);
6245
$this->resourceConnection = $objectManager->get(ResourceConnection::class);
6346
}
6447

6548
/**
66-
* @moduleName Magento_TestSetupDeclarationModule1
67-
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/installation.php
49+
* @moduleName Magento_TestSetupDeclarationModule4
50+
* @dataProviderFromFile Magento/TestSetupDeclarationModule4/fixture/safe_data_provider.php
6851
*/
6952
public function testInstallation()
7053
{
54+
$testTableData = $this->getData();
55+
$row = reset($testTableData);
7156
$this->cliCommad->install(
72-
['Magento_TestSetupDeclarationModule1']
57+
['Magento_TestSetupDeclarationModule4']
7358
);
74-
59+
$adapter = $this->resourceConnection->getConnection();
60+
$testTableName = $this->resourceConnection->getTableName('test_table');
61+
$adapter->insertArray(
62+
$this->resourceConnection->getTableName('test_table'),
63+
array_keys($row),
64+
$this->getData()
65+
);
66+
//Move new db_schema.xml
67+
$this->moduleManager->updateRevision(
68+
'Magento_TestSetupDeclarationModule4',
69+
'remove_title_column',
70+
'db_schema.xml',
71+
'etc'
72+
);
73+
$this->cliCommad->upgrade();
74+
//Move new db_schema.xml with restored title field
75+
$this->moduleManager->updateRevision(
76+
'Magento_TestSetupDeclarationModule4',
77+
'restore_title_column',
78+
'db_schema.xml',
79+
'etc'
80+
);
81+
$this->cliCommad->upgrade();
82+
$testTableSelect = $adapter->select()->from($testTableName);
83+
self::assertEquals($testTableData, $adapter->fetchAll($testTableSelect));
7584
}
7685
}

0 commit comments

Comments
 (0)