Skip to content

Commit

Permalink
Merge pull request #1645 from magento-honey-badgers/declarative_schem…
Browse files Browse the repository at this point in the history
…a_test

[Honey Badgers] Declarative schema: new test framework
  • Loading branch information
cpartica authored Nov 2, 2017
2 parents 316426a + 95c8366 commit 8462688
Show file tree
Hide file tree
Showing 31 changed files with 3,415 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Encapsulates application installation, initialization and uninstall
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class Application
{
Expand Down Expand Up @@ -129,6 +130,11 @@ class Application
*/
private $loadTestExtensionAttributes;

/**
* @var bool
*/
protected $dumpDb = true;

/**
* Constructor
*
Expand Down Expand Up @@ -483,7 +489,7 @@ public function install()
);

// right after a clean installation, store DB dump for future reuse in tests or running the test suite again
if (!$db->isDbDumpExists()) {
if (!$db->isDbDumpExists() && $this->dumpDb) {
$this->getDbInstance()->storeDbDump();
}
}
Expand Down
3 changes: 3 additions & 0 deletions dev/tests/setup-integration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*.xml
/var/
/etc/*.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\TestSetupModule1\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

/**
* @codeCoverageIgnore
*/
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;

$installer->startSetup();

/**
* Create table 'setup_table1'
*/
$table = $installer->getConnection()->newTable(
$installer->getTable('setup_tests_table1')
)->addColumn(
'column_with_type_boolean',
\Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN,
null,
['nullable' => false, 'default' => 0],
'Column with type boolean'
)->addColumn(
'column_with_type_smallint',
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
null,
['unsigned' => true, 'nullable' => false, 'default' => '0'],
'Column with type smallint'
)->addColumn(
'column_with_type_integer',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['unsigned' => true, 'identity' => true, 'nullable' => false, 'primary' => true],
'Column with type integer'
)->addColumn(
'column_with_type_bigint',
\Magento\Framework\DB\Ddl\Table::TYPE_BIGINT,
null,
['unsigned' => true, 'nullable' => false, 'primary' => true],
'Column with type bigint'
)->addColumn(
'column_with_type_float',
\Magento\Framework\DB\Ddl\Table::TYPE_FLOAT,
null,
['nullable' => true, 'default' => null],
'Column with type float'
)->addColumn(
'column_with_type_numeric',
\Magento\Framework\DB\Ddl\Table::TYPE_NUMERIC,
'12,4',
['unsigned' => true, 'nullable' => true],
'Column with type numeric'
)->addColumn(
'column_with_type_decimal',
\Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
'12,4',
['unsigned' => true, 'nullable' => true],
'Column with type decimal'
)->addColumn(
'column_with_type_datetime',
\Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
null,
['nullable' => true, 'default' => null],
'Column with type datetime'
)->addColumn(
'column_with_type_timestamp_update',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
null,
['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_UPDATE],
'Column with type timestamp update'
)->addColumn(
'column_with_type_date',
\Magento\Framework\DB\Ddl\Table::TYPE_DATE,
null,
['nullable' => true, 'default' => null],
'Column with type date'
)->addColumn(
'column_with_type_text',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'64k',
[],
'Column with type text'
)->addColumn(
'column_with_type_blob',
\Magento\Framework\DB\Ddl\Table::TYPE_BLOB,
32,
[],
'Column with type blob'
)->addColumn(
'column_with_type_verbinary',
\Magento\Framework\DB\Ddl\Table::TYPE_VARBINARY,
'2m',
[],
'Column with type varbinary'
)->addIndex(
$installer->getIdxName(
'setup_tests_table1',
['column_with_type_text'],
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
),
['column_with_type_text'],
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT]
)->addIndex(
$installer->getIdxName(
'setup_tests_table1',
'column_with_type_integer',
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX
),
'column_with_type_integer',
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
);

$installer->getConnection()->createTable($table);

$relatedTable = $installer->getConnection()->newTable(
$installer->getTable('setup_tests_table1_related')
)->addColumn(
'column_with_type_timestamp_init_update',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
null,
['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
'Column with type timestamp init update'
)->addColumn(
'column_with_type_timestamp_init',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
null,
['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
'Column with type timestamp init'
)->addColumn(
'column_with_relation',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['unsigned' => true, 'nullable' => false],
'Column with type integer and relation'
)->addForeignKey(
$installer->getFkName(
'setup_table1_related',
'column_with_relation',
'setup_tests_table1',
'column_with_type_integer'
),
'column_with_relation',
$installer->getTable('setup_tests_table1'),
'column_with_type_integer',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)->setComment(
'Related Table'
);
$installer->getConnection()->createTable($relatedTable);
$installer->endSetup();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_TestSetupModule1" setup_version="0.0.1"/>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestSetupModule1') === null) {
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestSetupModule1', __DIR__);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestSetupModule2\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();

$setup->getConnection()->insertForce(
$setup->getTable('setup_tests_entity_table'),
[
'website_id' => 1,
'email_field' => 'entity@example.com',
'created_at' => '2017-10-30 09:41:25',
'updated_at' => '2017-10-30 09:45:05',
'created_in' => 'Default Store View',
'firstname' => 'John',
'lastname' => 'Doe',
'dob' => '1973-12-15',
'default_billing_address_id' => 1,
'default_shipping_address_id' => 1
]
);
$setup->getConnection()->insertForce(
$setup->getTable('setup_tests_address_entity'),
[
'parent_id' => 1,
'created_at' => '2017-10-30 09:45:05',
'updated_at' => '2017-10-30 09:45:05',
'is_active' => 1,
'city' => 'city',
'company' => 'Magento',
'country_id' => 'US',
'firstname' => 'John',
'lastname' => 'Doe',
'postcode' => '90210',
'region' => 'Alabama',
'region_id' => 1,
'street' => 'street1',
'telephone' => 12345678,
]
);

$setup->endSetup();
}
}
Loading

0 comments on commit 8462688

Please sign in to comment.