Skip to content

Commit 8462688

Browse files
authored
Merge pull request #1645 from magento-honey-badgers/declarative_schema_test
[Honey Badgers] Declarative schema: new test framework
2 parents 316426a + 95c8366 commit 8462688

File tree

31 files changed

+3415
-1
lines changed

31 files changed

+3415
-1
lines changed

dev/tests/integration/framework/Magento/TestFramework/Application.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Encapsulates application installation, initialization and uninstall
1717
*
1818
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19+
* @SuppressWarnings(PHPMD.TooManyFields)
1920
*/
2021
class Application
2122
{
@@ -129,6 +130,11 @@ class Application
129130
*/
130131
private $loadTestExtensionAttributes;
131132

133+
/**
134+
* @var bool
135+
*/
136+
protected $dumpDb = true;
137+
132138
/**
133139
* Constructor
134140
*
@@ -483,7 +489,7 @@ public function install()
483489
);
484490

485491
// right after a clean installation, store DB dump for future reuse in tests or running the test suite again
486-
if (!$db->isDbDumpExists()) {
492+
if (!$db->isDbDumpExists() && $this->dumpDb) {
487493
$this->getDbInstance()->storeDbDump();
488494
}
489495
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*.xml
2+
/var/
3+
/etc/*.php
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\TestSetupModule1\Setup;
8+
9+
use Magento\Framework\Setup\InstallSchemaInterface;
10+
use Magento\Framework\Setup\ModuleContextInterface;
11+
use Magento\Framework\Setup\SchemaSetupInterface;
12+
13+
/**
14+
* @codeCoverageIgnore
15+
*/
16+
class InstallSchema implements InstallSchemaInterface
17+
{
18+
/**
19+
* {@inheritdoc}
20+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
21+
*/
22+
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
23+
{
24+
$installer = $setup;
25+
26+
$installer->startSetup();
27+
28+
/**
29+
* Create table 'setup_table1'
30+
*/
31+
$table = $installer->getConnection()->newTable(
32+
$installer->getTable('setup_tests_table1')
33+
)->addColumn(
34+
'column_with_type_boolean',
35+
\Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN,
36+
null,
37+
['nullable' => false, 'default' => 0],
38+
'Column with type boolean'
39+
)->addColumn(
40+
'column_with_type_smallint',
41+
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
42+
null,
43+
['unsigned' => true, 'nullable' => false, 'default' => '0'],
44+
'Column with type smallint'
45+
)->addColumn(
46+
'column_with_type_integer',
47+
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
48+
null,
49+
['unsigned' => true, 'identity' => true, 'nullable' => false, 'primary' => true],
50+
'Column with type integer'
51+
)->addColumn(
52+
'column_with_type_bigint',
53+
\Magento\Framework\DB\Ddl\Table::TYPE_BIGINT,
54+
null,
55+
['unsigned' => true, 'nullable' => false, 'primary' => true],
56+
'Column with type bigint'
57+
)->addColumn(
58+
'column_with_type_float',
59+
\Magento\Framework\DB\Ddl\Table::TYPE_FLOAT,
60+
null,
61+
['nullable' => true, 'default' => null],
62+
'Column with type float'
63+
)->addColumn(
64+
'column_with_type_numeric',
65+
\Magento\Framework\DB\Ddl\Table::TYPE_NUMERIC,
66+
'12,4',
67+
['unsigned' => true, 'nullable' => true],
68+
'Column with type numeric'
69+
)->addColumn(
70+
'column_with_type_decimal',
71+
\Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
72+
'12,4',
73+
['unsigned' => true, 'nullable' => true],
74+
'Column with type decimal'
75+
)->addColumn(
76+
'column_with_type_datetime',
77+
\Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
78+
null,
79+
['nullable' => true, 'default' => null],
80+
'Column with type datetime'
81+
)->addColumn(
82+
'column_with_type_timestamp_update',
83+
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
84+
null,
85+
['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_UPDATE],
86+
'Column with type timestamp update'
87+
)->addColumn(
88+
'column_with_type_date',
89+
\Magento\Framework\DB\Ddl\Table::TYPE_DATE,
90+
null,
91+
['nullable' => true, 'default' => null],
92+
'Column with type date'
93+
)->addColumn(
94+
'column_with_type_text',
95+
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
96+
'64k',
97+
[],
98+
'Column with type text'
99+
)->addColumn(
100+
'column_with_type_blob',
101+
\Magento\Framework\DB\Ddl\Table::TYPE_BLOB,
102+
32,
103+
[],
104+
'Column with type blob'
105+
)->addColumn(
106+
'column_with_type_verbinary',
107+
\Magento\Framework\DB\Ddl\Table::TYPE_VARBINARY,
108+
'2m',
109+
[],
110+
'Column with type varbinary'
111+
)->addIndex(
112+
$installer->getIdxName(
113+
'setup_tests_table1',
114+
['column_with_type_text'],
115+
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
116+
),
117+
['column_with_type_text'],
118+
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT]
119+
)->addIndex(
120+
$installer->getIdxName(
121+
'setup_tests_table1',
122+
'column_with_type_integer',
123+
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX
124+
),
125+
'column_with_type_integer',
126+
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
127+
);
128+
129+
$installer->getConnection()->createTable($table);
130+
131+
$relatedTable = $installer->getConnection()->newTable(
132+
$installer->getTable('setup_tests_table1_related')
133+
)->addColumn(
134+
'column_with_type_timestamp_init_update',
135+
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
136+
null,
137+
['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
138+
'Column with type timestamp init update'
139+
)->addColumn(
140+
'column_with_type_timestamp_init',
141+
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
142+
null,
143+
['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
144+
'Column with type timestamp init'
145+
)->addColumn(
146+
'column_with_relation',
147+
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
148+
null,
149+
['unsigned' => true, 'nullable' => false],
150+
'Column with type integer and relation'
151+
)->addForeignKey(
152+
$installer->getFkName(
153+
'setup_table1_related',
154+
'column_with_relation',
155+
'setup_tests_table1',
156+
'column_with_type_integer'
157+
),
158+
'column_with_relation',
159+
$installer->getTable('setup_tests_table1'),
160+
'column_with_type_integer',
161+
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
162+
)->setComment(
163+
'Related Table'
164+
);
165+
$installer->getConnection()->createTable($relatedTable);
166+
$installer->endSetup();
167+
}
168+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_TestSetupModule1" setup_version="0.0.1"/>
10+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
$registrar = new ComponentRegistrar();
10+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestSetupModule1') === null) {
11+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestSetupModule1', __DIR__);
12+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\TestSetupModule2\Setup;
7+
8+
use Magento\Framework\Setup\InstallDataInterface;
9+
use Magento\Framework\Setup\ModuleContextInterface;
10+
use Magento\Framework\Setup\ModuleDataSetupInterface;
11+
12+
/**
13+
* @codeCoverageIgnore
14+
*/
15+
class InstallData implements InstallDataInterface
16+
{
17+
/**
18+
* {@inheritdoc}
19+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
20+
*/
21+
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
22+
{
23+
$setup->startSetup();
24+
25+
$setup->getConnection()->insertForce(
26+
$setup->getTable('setup_tests_entity_table'),
27+
[
28+
'website_id' => 1,
29+
'email_field' => '[email protected]',
30+
'created_at' => '2017-10-30 09:41:25',
31+
'updated_at' => '2017-10-30 09:45:05',
32+
'created_in' => 'Default Store View',
33+
'firstname' => 'John',
34+
'lastname' => 'Doe',
35+
'dob' => '1973-12-15',
36+
'default_billing_address_id' => 1,
37+
'default_shipping_address_id' => 1
38+
]
39+
);
40+
$setup->getConnection()->insertForce(
41+
$setup->getTable('setup_tests_address_entity'),
42+
[
43+
'parent_id' => 1,
44+
'created_at' => '2017-10-30 09:45:05',
45+
'updated_at' => '2017-10-30 09:45:05',
46+
'is_active' => 1,
47+
'city' => 'city',
48+
'company' => 'Magento',
49+
'country_id' => 'US',
50+
'firstname' => 'John',
51+
'lastname' => 'Doe',
52+
'postcode' => '90210',
53+
'region' => 'Alabama',
54+
'region_id' => 1,
55+
'street' => 'street1',
56+
'telephone' => 12345678,
57+
]
58+
);
59+
60+
$setup->endSetup();
61+
}
62+
}

0 commit comments

Comments
 (0)