This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,126 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Developer\Console\Command;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* Test for Install command.
*/
class SetupInstallTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var ComponentRegistrar
*/
private $componentRegistrar;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->cliCommand = $objectManager->get(CliCommand::class);
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->componentRegistrar = $objectManager->create(
ComponentRegistrar::class
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
* @moduleName Magento_TestSetupDeclarationModule9
* @throws \Exception
*/
public function testInstallWithConverting()
{
$modules = [
'Magento_TestSetupDeclarationModule8',
'Magento_TestSetupDeclarationModule9',
];
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'InstallSchema.php',
'Setup'
);
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'UpgradeSchema.php',
'Setup'
);
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'module.xml',
'etc'
);
}
$this->cliCommand->install($modules, ['convert-old-scripts' => true]);
foreach ($modules as $moduleName) {
$modulePath = $this->componentRegistrar->getPath('module', $moduleName);
$schemaFileName = $modulePath
. DIRECTORY_SEPARATOR
. \Magento\Framework\Module\Dir::MODULE_ETC_DIR
. DIRECTORY_SEPARATOR
. 'db_schema.xml';
$generatedSchema = $this->getSchemaDocument($schemaFileName);
$expectedSchemaFileName = dirname(__DIR__, 2)
. DIRECTORY_SEPARATOR
. implode(
DIRECTORY_SEPARATOR,
[
'_files',
'SetupInstall',
str_replace('Magento_', '', $moduleName),
'db_schema.xml'
]
);
$expectedSchema = $this->getSchemaDocument($expectedSchemaFileName);
$this->assertEquals($expectedSchema->saveXML(), $generatedSchema->saveXML());
}
}
/**
* Convert file content in the DOM document.
*
* @param $schemaFileName
* @return \DOMDocument
*/
private function getSchemaDocument($schemaFileName): \DOMDocument
{
$schemaDocument = new \DOMDocument();
$schemaDocument->preserveWhiteSpace = false;
$schemaDocument->formatOutput = true;
$schemaDocument->loadXML(file_get_contents($schemaFileName));
return $schemaDocument;
}
}
@@ -0,0 +1,173 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Developer\Console\Command;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* Test for Upgrade command.
*/
class SetupUpgradeTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var ComponentRegistrar
*/
private $componentRegistrar;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->cliCommand = $objectManager->get(CliCommand::class);
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->componentRegistrar = $objectManager->create(
ComponentRegistrar::class
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
* @moduleName Magento_TestSetupDeclarationModule9
* @throws \Exception
*/
public function testUpgradeWithConverting()
{
$modules = [
'Magento_TestSetupDeclarationModule8',
'Magento_TestSetupDeclarationModule9',
];
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'InstallSchema.php',
'Setup'
);
}
$this->cliCommand->install($modules, ['convert-old-scripts' => true]);
foreach ($modules as $moduleName) {
$this->assertInstallScriptChanges($moduleName);
}
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'UpgradeSchema.php',
'Setup'
);
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'module.xml',
'etc'
);
}
$this->cliCommand->upgrade(['convert-old-scripts' => true]);
foreach ($modules as $moduleName) {
$this->assertUpgradeScriptChanges($moduleName);
}
}
/**
* Convert file content in the DOM document.
*
* @param string $schemaFileName
* @return \DOMDocument
*/
private function getSchemaDocument(string $schemaFileName): \DOMDocument
{
$schemaDocument = new \DOMDocument();
$schemaDocument->preserveWhiteSpace = false;
$schemaDocument->formatOutput = true;
$schemaDocument->loadXML(file_get_contents($schemaFileName));
return $schemaDocument;
}
/**
* @param string $moduleName
*/
private function assertInstallScriptChanges(string $moduleName): void
{
$generatedSchema = $this->getGeneratedSchema($moduleName);
$expectedSchema = $this->getSchemaDocument($this->getSchemaFixturePath($moduleName, 'install'));
$this->assertEquals($expectedSchema->saveXML(), $generatedSchema->saveXML());
}
/**
* @param string $moduleName
*/
private function assertUpgradeScriptChanges(string $moduleName): void
{
$generatedSchema = $this->getGeneratedSchema($moduleName);
$expectedSchema = $this->getSchemaDocument($this->getSchemaFixturePath($moduleName, 'upgrade'));
$this->assertEquals($expectedSchema->saveXML(), $generatedSchema->saveXML());
}
/**
* @param string $moduleName
* @return \DOMDocument
*/
private function getGeneratedSchema(string $moduleName): \DOMDocument
{
$modulePath = $this->componentRegistrar->getPath('module', $moduleName);
$schemaFileName = $modulePath
. DIRECTORY_SEPARATOR
. \Magento\Framework\Module\Dir::MODULE_ETC_DIR
. DIRECTORY_SEPARATOR
. 'db_schema.xml';
return $this->getSchemaDocument($schemaFileName);
}
/**
* @param string $moduleName
* @param string $suffix
* @return string
*/
private function getSchemaFixturePath(string $moduleName, string $suffix): string
{
$schemaFixturePath = dirname(__DIR__, 2)
. DIRECTORY_SEPARATOR
. implode(
DIRECTORY_SEPARATOR,
[
'_files',
'SetupUpgrade',
str_replace('Magento_', '', $moduleName),
'db_schema_' . $suffix . '.xml'
]
);
return $schemaFixturePath;
}
}
@@ -0,0 +1,134 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Developer\Console\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Magento\TestFramework\TestCase\SetupTestCase;
use Magento\Framework\Console\Cli;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
/**
* The purpose of this test is to verify the declaration:generate:whitelist command.
*/
class TablesWhitelistGenerateCommandTest extends SetupTestCase
{
/**
* @var CommandTester
*/
private $tester;
/**
* @var \Magento\Developer\Console\Command\TablesWhitelistGenerateCommand
*/
private $command;
/**
* @var \Magento\Framework\Component\ComponentRegistrar
*/
private $componentRegistrar;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* {@inheritdoc}
*/
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->command = $this->objectManager->create(
\Magento\Developer\Console\Command\TablesWhitelistGenerateCommand::class
);
$this->componentRegistrar = $this->objectManager->create(
\Magento\Framework\Component\ComponentRegistrar::class
);
$this->cliCommand = $this->objectManager->get(CliCommand::class);
$this->tester = new CommandTester($this->command);
$this->moduleManager = $this->objectManager->get(TestModuleManager::class);
}
/**
* Execute generate command for whitelist.
*
* @moduleName Magento_TestSetupDeclarationModule1
* @moduleName Magento_TestSetupDeclarationModule8
* @moduleName Magento_TestSetupDeclarationModule10
* @throws \Exception
*/
public function testExecute()
{
$modules = [
'Magento_TestSetupDeclarationModule1',
'Magento_TestSetupDeclarationModule8',
'Magento_TestSetupDeclarationModule10',
];
$this->cliCommand->install($modules);
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'whitelist_upgrade',
'db_schema.xml',
'etc'
);
}
foreach ($modules as $moduleName) {
$this->checkWhitelistFile($moduleName);
}
}
/**
* @param string $moduleName
*/
private function checkWhitelistFile(string $moduleName)
{
$modulePath = $this->componentRegistrar->getPath('module', $moduleName);
$whiteListFileName = $modulePath
. DIRECTORY_SEPARATOR
. \Magento\Framework\Module\Dir::MODULE_ETC_DIR
. DIRECTORY_SEPARATOR
. \Magento\Framework\Setup\Declaration\Schema\Diff\Diff::GENERATED_WHITELIST_FILE_NAME;
//run bin/magento declaration:generate:whitelist Magento_TestSetupDeclarationModule1 command.
$this->tester->execute(['--module-name' => $moduleName], ['interactive' => false]);
$this->assertSame(Cli::RETURN_SUCCESS, $this->tester->getStatusCode());
$this->assertFileExists($whiteListFileName);
$this->assertEmpty($this->tester->getDisplay());
$whitelistFileContent = file_get_contents($whiteListFileName);
$expectedWhitelistContent = rtrim(file_get_contents(
dirname(__DIR__, 2)
. DIRECTORY_SEPARATOR
. implode(
DIRECTORY_SEPARATOR,
[
'_files',
'WhitelistGenerate',
str_replace('Magento_', '', $moduleName),
'db_schema_whitelist.json'
]
)
), "\n");
$this->assertEquals($expectedWhitelistContent, $whitelistFileContent);
}
}
@@ -0,0 +1,114 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="module8_test_main_table" resource="default" engine="innodb" comment="Main Test Table for Module8">
<column xsi:type="int" name="module8_email_contact_id" padding="10" unsigned="true" nullable="false"
identity="true" comment="Email Contact ID"/>
<column xsi:type="int" name="module8_contact_group_id" padding="10" unsigned="true" nullable="false"
identity="false" comment="Contact Group ID"/>
<column xsi:type="smallint" name="module8_is_guest" padding="5" unsigned="true" nullable="true"
identity="false" comment="Is Guest"/>
<column xsi:type="varchar" name="module8_contact_id" nullable="true" length="15" comment="Contact ID"/>
<column xsi:type="varchar" name="module8_content" nullable="false" length="15" comment="Content"/>
<column xsi:type="int" name="module8_update_column" padding="11" unsigned="false" nullable="false"
identity="false" comment="Module_8 Update Column"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_email_contact_id"/>
</constraint>
<constraint xsi:type="unique" referenceId="MODULE8_INSTALL_UNIQUE_INDEX_2">
<column name="module8_email_contact_id"/>
<column name="module8_is_guest"/>
</constraint>
<constraint xsi:type="unique" referenceId="MODULE8_INSTALL_UNIQUE_INDEX_TEMP" disabled="true">
<column name="module8_contact_group_id"/>
</constraint>
<index referenceId="MODULE8_INSTALL_INDEX_1" indexType="btree">
<column name="module8_email_contact_id"/>
</index>
<index referenceId="MODULE8_INSTALL_INDEX_3" indexType="btree">
<column name="module8_is_guest"/>
</index>
<index referenceId="MODULE8_INSTALL_INDEX_4" indexType="btree">
<column name="module8_contact_id"/>
</index>
<index referenceId="MODULE8_INSTALL_INDEX_TEMP" indexType="btree" disabled="true">
<column name="module8_content"/>
</index>
</table>
<table name="module8_test_second_table" resource="default" engine="innodb" comment="Second Test Table for Module8">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="true"
comment="Entity ID"/>
<column xsi:type="int" name="module8_contact_id" padding="11" unsigned="false" nullable="true"
identity="false" comment="Contact ID"/>
<column xsi:type="varchar" name="module8_address" nullable="false" length="15" comment="Address"/>
<column xsi:type="smallint" name="module8_counter_with_multiline_comment" padding="5" unsigned="true"
nullable="true" identity="false" default="0"
comment="Empty&#10; Counter&#10; Multiline&#10; Comment"/>
<column xsi:type="varchar" name="module8_second_address" nullable="true" length="15" comment="Second Address"/>
<column xsi:type="varchar" name="module8_temp_column" nullable="true" length="15"
comment="Temp column for remove" disabled="true"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ENTITY_ID_TEST_MAIN_TABLE_EMAIL_CONTACT_ID"
table="module8_test_second_table" column="module8_entity_id"
referenceTable="module8_test_main_table" referenceColumn="module8_email_contact_id"
onDelete="NO ACTION"/>
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_CONTACT_ID"
table="module8_test_second_table" column="module8_address" referenceTable="module8_test_main_table"
referenceColumn="module8_contact_id" onDelete="NO ACTION"/>
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_MODULE8_CONTENT_TEMP"
table="module8_test_second_table" column="module8_address" referenceTable="module8_test_main_table"
referenceColumn="module8_content" onDelete="NO ACTION" disabled="true"/>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_1" indexType="btree">
<column name="module8_entity_id"/>
</index>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_2" indexType="btree">
<column name="module8_address"/>
</index>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_3_TEMP" indexType="btree">
<column name="module8_second_address"/>
</index>
</table>
<table name="module8_test_update_table" resource="default" engine="innodb" comment="Update Test Table for Module8">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="false"
comment="Entity ID"/>
<column xsi:type="int" name="module8_entity_row_id" padding="10" unsigned="true" nullable="false"
identity="false" comment="Module8_entity_row_id"/>
<column xsi:type="smallint" name="module8_is_guest" padding="5" unsigned="true" nullable="true"
identity="false" comment="Is Guest"/>
<column xsi:type="smallint" name="module8_guest_browser_id" padding="5" unsigned="true" nullable="true"
identity="false" comment="Guest Browser ID"/>
<column xsi:type="smallint" name="module8_column_for_remove" padding="5" unsigned="true" nullable="true"
identity="false" comment="For remove"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="MODULE8_UPDATE_FK_MODULE8_IS_GUEST"
table="module8_test_update_table" column="module8_is_guest" referenceTable="module8_test_main_table"
referenceColumn="module8_is_guest" onDelete="CASCADE"/>
<constraint xsi:type="foreign" referenceId="MODULE8_UPDATE_FK_TEMP" table="module8_test_update_table"
column="module8_column_for_remove" referenceTable="module8_test_main_table"
referenceColumn="module8_is_guest" onDelete="CASCADE"/>
<constraint xsi:type="unique" referenceId="MODULE8_UPDATE_UNIQUE_INDEX_TEMP">
<column name="module8_entity_id"/>
<column name="module8_is_guest"/>
</constraint>
<index referenceId="MODULE8_UPDATE_IS_GUEST_INDEX" indexType="btree">
<column name="module8_is_guest"/>
</index>
<index referenceId="MODULE8_UPDATE_TEMP_INDEX" indexType="btree">
<column name="module8_column_for_remove"/>
<column name="module8_guest_browser_id"/>
</index>
</table>
<table name="module8_test_temp_table" resource="default" engine="innodb" comment="module8_test_temp_table">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="true"
comment="Entity ID"/>
<column xsi:type="int" name="module8_counter" padding="10" unsigned="true" nullable="true" identity="false"
default="100" comment="Counter"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
</table>
</schema>
@@ -0,0 +1,68 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="module9_test_main_table" resource="default" engine="innodb" comment="Main Test Table for Module9">
<column xsi:type="int" name="module9_email_contact_id" padding="10" unsigned="true" nullable="false"
identity="true" comment="Entity ID"/>
<column xsi:type="smallint" name="module9_is_guest" padding="5" unsigned="true" nullable="true"
identity="false" comment="Is Guest"/>
<column xsi:type="int" name="module9_guest_id" padding="10" unsigned="true" nullable="true" identity="false"
comment="Guest ID"/>
<column xsi:type="date" name="module9_created_at" comment="Created At"/>
<column xsi:type="int" name="module9_update_column" padding="11" unsigned="false" nullable="false"
identity="false" comment="Module_9 Update Column"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module9_email_contact_id"/>
</constraint>
<constraint xsi:type="unique" referenceId="MODULE9_INSTALL_UNIQUE_INDEX_1">
<column name="module9_email_contact_id"/>
<column name="module9_guest_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="MODULE9_UPDATE_FK_MODULE9_IS_GUEST" table="module9_test_main_table"
column="module9_is_guest" referenceTable="module8_test_main_table"
referenceColumn="module8_is_guest" onDelete="CASCADE"/>
</table>
<table name="module8_test_main_table" resource="default">
<column xsi:type="int" name="module9_update_column" padding="11" unsigned="false" nullable="false"
identity="false" comment="Module_9 Update Column"/>
</table>
<table name="module8_test_update_table" resource="default">
<column name="module8_column_for_remove" disabled="true"/>
<constraint xsi:type="foreign" referenceId="MODULE8_UPDATE_FK_TEMP" disabled="true"/>
<index referenceId="MODULE9_UPDATE_MODULE8_GUEST_BROWSER_ID" indexType="btree">
<column name="module8_guest_browser_id"/>
</index>
<index referenceId="MODULE8_UPDATE_UNIQUE_INDEX_TEMP" disabled="true"/>
</table>
<table name="module8_test_second_table" resource="default">
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_CONTACT_ID"
disabled="true"/>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_3_TEMP" disabled="true"/>
</table>
<table name="module8_test_temp_table" disabled="true" resource="default"/>
<table name="module9_test_update_replica_table" resource="default" engine="innodb"
comment="Module9 Test Update Replica Table">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="true"
comment="Module8 Entity Id"/>
<column xsi:type="int" name="module8_contact_id" padding="11" unsigned="false" nullable="true"
identity="false" comment="Module8 Contact Id"/>
<column xsi:type="varchar" name="module8_address" nullable="false" length="15" comment="Module8 Address"/>
<column xsi:type="smallint" name="module8_counter_with_multiline_comment" padding="5" unsigned="true"
nullable="true" identity="false" default="0" comment="Module8 Counter With Multiline Comment"/>
<column xsi:type="varchar" name="module8_second_address" nullable="true" length="15"
comment="Module8 Second Address"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="FK_8914AF398964FAFB4ED2E382866ABBF4"
table="module9_test_update_replica_table" column="module8_entity_id"
referenceTable="module8_test_main_table" referenceColumn="module8_email_contact_id"
onDelete="NO ACTION"/>
<index referenceId="MODULE9_TEST_UPDATE_REPLICA_TABLE_MODULE8_ENTITY_ID" indexType="btree">
<column name="module8_entity_id"/>
</index>
<index referenceId="MODULE9_TEST_UPDATE_REPLICA_TABLE_MODULE8_ADDRESS" indexType="btree">
<column name="module8_address"/>
</index>
</table>
</schema>
@@ -0,0 +1,81 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="module8_test_main_table" resource="default" engine="innodb" comment="Main Test Table for Module8">
<column xsi:type="int" name="module8_email_contact_id" padding="10" unsigned="true" nullable="false"
identity="true" comment="Email Contact ID"/>
<column xsi:type="int" name="module8_contact_group_id" padding="10" unsigned="true" nullable="false"
identity="false" comment="Contact Group ID"/>
<column xsi:type="smallint" name="module8_is_guest" padding="5" unsigned="true" nullable="true"
identity="false" comment="Is Guest"/>
<column xsi:type="varchar" name="module8_contact_id" nullable="true" length="15" comment="Contact ID"/>
<column xsi:type="varchar" name="module8_content" nullable="false" length="15" comment="Content"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_email_contact_id"/>
</constraint>
<constraint xsi:type="unique" referenceId="MODULE8_INSTALL_UNIQUE_INDEX_2">
<column name="module8_email_contact_id"/>
<column name="module8_is_guest"/>
</constraint>
<constraint xsi:type="unique" referenceId="MODULE8_INSTALL_UNIQUE_INDEX_TEMP">
<column name="module8_contact_group_id"/>
</constraint>
<index referenceId="MODULE8_INSTALL_INDEX_1" indexType="btree">
<column name="module8_email_contact_id"/>
</index>
<index referenceId="MODULE8_INSTALL_INDEX_3" indexType="btree">
<column name="module8_is_guest"/>
</index>
<index referenceId="MODULE8_INSTALL_INDEX_4" indexType="btree">
<column name="module8_contact_id"/>
</index>
<index referenceId="MODULE8_INSTALL_INDEX_TEMP" indexType="btree">
<column name="module8_content"/>
</index>
</table>
<table name="module8_test_second_table" resource="default" engine="innodb" comment="Second Test Table for Module8">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="true"
comment="Entity ID"/>
<column xsi:type="int" name="module8_contact_id" padding="11" unsigned="false" nullable="true"
identity="false" comment="Contact ID"/>
<column xsi:type="varchar" name="module8_address" nullable="false" length="15" comment="Address"/>
<column xsi:type="smallint" name="module8_counter_with_multiline_comment" padding="5" unsigned="true"
nullable="true" identity="false" default="0"
comment="Empty&#10; Counter&#10; Multiline&#10; Comment"/>
<column xsi:type="varchar" name="module8_second_address" nullable="true" length="15" comment="Second Address"/>
<column xsi:type="varchar" name="module8_temp_column" nullable="true" length="15"
comment="Temp column for remove"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ENTITY_ID_TEST_MAIN_TABLE_EMAIL_CONTACT_ID"
table="module8_test_second_table" column="module8_entity_id"
referenceTable="module8_test_main_table" referenceColumn="module8_email_contact_id"
onDelete="NO ACTION"/>
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_CONTACT_ID"
table="module8_test_second_table" column="module8_address" referenceTable="module8_test_main_table"
referenceColumn="module8_contact_id" onDelete="NO ACTION"/>
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_MODULE8_CONTENT_TEMP"
table="module8_test_second_table" column="module8_address" referenceTable="module8_test_main_table"
referenceColumn="module8_content" onDelete="NO ACTION"/>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_1" indexType="btree">
<column name="module8_entity_id"/>
</index>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_2" indexType="btree">
<column name="module8_address"/>
</index>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_3_TEMP" indexType="btree">
<column name="module8_second_address"/>
</index>
</table>
<table name="module8_test_install_temp_table" resource="default" engine="innodb"
comment="module8_test_install_temp_table">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="true"
comment="Entity ID"/>
<column xsi:type="int" name="module8_counter" padding="10" unsigned="true" nullable="true" identity="false"
default="100" comment="Counter"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
</table>
</schema>
@@ -0,0 +1,124 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="module8_test_main_table" resource="default" engine="innodb" comment="Main Test Table for Module8">
<column xsi:type="int" name="module8_email_contact_id" padding="10" unsigned="true" nullable="false"
identity="true" comment="Email Contact ID"/>
<column xsi:type="int" name="module8_contact_group_id" padding="10" unsigned="true" nullable="false"
identity="false" comment="Contact Group ID"/>
<column xsi:type="smallint" name="module8_is_guest" padding="5" unsigned="true" nullable="true"
identity="false" comment="Is Guest"/>
<column xsi:type="varchar" name="module8_contact_id" nullable="true" length="15" comment="Contact ID"/>
<column xsi:type="varchar" name="module8_content" nullable="false" length="15" comment="Content"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_email_contact_id"/>
</constraint>
<constraint xsi:type="unique" referenceId="MODULE8_INSTALL_UNIQUE_INDEX_2">
<column name="module8_email_contact_id"/>
<column name="module8_is_guest"/>
</constraint>
<constraint xsi:type="unique" referenceId="MODULE8_INSTALL_UNIQUE_INDEX_TEMP" disabled="true">
<column name="module8_contact_group_id"/>
</constraint>
<index referenceId="MODULE8_INSTALL_INDEX_1" indexType="btree">
<column name="module8_email_contact_id"/>
</index>
<index referenceId="MODULE8_INSTALL_INDEX_3" indexType="btree">
<column name="module8_is_guest"/>
</index>
<index referenceId="MODULE8_INSTALL_INDEX_4" indexType="btree">
<column name="module8_contact_id"/>
</index>
<index referenceId="MODULE8_INSTALL_INDEX_TEMP" indexType="btree" disabled="true">
<column name="module8_content"/>
</index>
<column xsi:type="int" name="module8_update_column" padding="11" unsigned="false" nullable="false"
identity="false" comment="Module_8 Update Column"/>
</table>
<table name="module8_test_second_table" resource="default" engine="innodb" comment="Second Test Table for Module8">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="true"
comment="Entity ID"/>
<column xsi:type="int" name="module8_contact_id" padding="11" unsigned="false" nullable="true"
identity="false" comment="Contact ID"/>
<column xsi:type="varchar" name="module8_address" nullable="false" length="15" comment="Address"/>
<column xsi:type="smallint" name="module8_counter_with_multiline_comment" padding="5" unsigned="true"
nullable="true" identity="false" default="0"
comment="Empty&#10; Counter&#10; Multiline&#10; Comment"/>
<column xsi:type="varchar" name="module8_second_address" nullable="true" length="15" comment="Second Address"/>
<column xsi:type="varchar" name="module8_temp_column" nullable="true" length="15"
comment="Temp column for remove" disabled="true"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ENTITY_ID_TEST_MAIN_TABLE_EMAIL_CONTACT_ID"
table="module8_test_second_table" column="module8_entity_id"
referenceTable="module8_test_main_table" referenceColumn="module8_email_contact_id"
onDelete="NO ACTION"/>
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_CONTACT_ID"
table="module8_test_second_table" column="module8_address" referenceTable="module8_test_main_table"
referenceColumn="module8_contact_id" onDelete="NO ACTION"/>
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_MODULE8_CONTENT_TEMP"
table="module8_test_second_table" column="module8_address" referenceTable="module8_test_main_table"
referenceColumn="module8_content" onDelete="NO ACTION" disabled="true"/>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_1" indexType="btree">
<column name="module8_entity_id"/>
</index>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_2" indexType="btree">
<column name="module8_address"/>
</index>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_3_TEMP" indexType="btree">
<column name="module8_second_address"/>
</index>
</table>
<table name="module8_test_install_temp_table" resource="default" engine="innodb"
comment="module8_test_install_temp_table" disabled="true">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="true"
comment="Entity ID"/>
<column xsi:type="int" name="module8_counter" padding="10" unsigned="true" nullable="true" identity="false"
default="100" comment="Counter"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
</table>
<table name="module8_test_update_table" resource="default" engine="innodb" comment="Update Test Table for Module8">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="false"
comment="Entity ID"/>
<column xsi:type="int" name="module8_entity_row_id" padding="10" unsigned="true" nullable="false"
identity="false" comment="Module8_entity_row_id"/>
<column xsi:type="smallint" name="module8_is_guest" padding="5" unsigned="true" nullable="true"
identity="false" comment="Is Guest"/>
<column xsi:type="smallint" name="module8_guest_browser_id" padding="5" unsigned="true" nullable="true"
identity="false" comment="Guest Browser ID"/>
<column xsi:type="smallint" name="module8_column_for_remove" padding="5" unsigned="true" nullable="true"
identity="false" comment="For remove"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="MODULE8_UPDATE_FK_MODULE8_IS_GUEST"
table="module8_test_update_table" column="module8_is_guest" referenceTable="module8_test_main_table"
referenceColumn="module8_is_guest" onDelete="CASCADE"/>
<constraint xsi:type="foreign" referenceId="MODULE8_UPDATE_FK_TEMP" table="module8_test_update_table"
column="module8_column_for_remove" referenceTable="module8_test_main_table"
referenceColumn="module8_is_guest" onDelete="CASCADE"/>
<constraint xsi:type="unique" referenceId="MODULE8_UPDATE_UNIQUE_INDEX_TEMP">
<column name="module8_entity_id"/>
<column name="module8_is_guest"/>
</constraint>
<index referenceId="MODULE8_UPDATE_IS_GUEST_INDEX" indexType="btree">
<column name="module8_is_guest"/>
</index>
<index referenceId="MODULE8_UPDATE_TEMP_INDEX" indexType="btree">
<column name="module8_column_for_remove"/>
<column name="module8_guest_browser_id"/>
</index>
</table>
<table name="module8_test_temp_table" resource="default" engine="innodb" comment="module8_test_temp_table">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="true"
comment="Entity ID"/>
<column xsi:type="int" name="module8_counter" padding="10" unsigned="true" nullable="true" identity="false"
default="100" comment="Counter"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
</table>
</schema>
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="module9_test_main_table" resource="default" engine="innodb" comment="Main Test Table for Module9">
<column xsi:type="int" name="module9_email_contact_id" padding="10" unsigned="true" nullable="false"
identity="true" comment="Entity ID"/>
<column xsi:type="smallint" name="module9_is_guest" padding="5" unsigned="true" nullable="true"
identity="false" comment="Is Guest"/>
<column xsi:type="int" name="module9_guest_id" padding="10" unsigned="true" nullable="true" identity="false"
comment="Guest ID"/>
<column xsi:type="date" name="module9_created_at" comment="Created At"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module9_email_contact_id"/>
</constraint>
<constraint xsi:type="unique" referenceId="MODULE9_INSTALL_UNIQUE_INDEX_1">
<column name="module9_email_contact_id"/>
<column name="module9_guest_id"/>
</constraint>
</table>
</schema>
@@ -0,0 +1,77 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="module9_test_main_table" resource="default" engine="innodb" comment="Main Test Table for Module9">
<column xsi:type="int" name="module9_email_contact_id" padding="10" unsigned="true" nullable="false"
identity="true" comment="Entity ID"/>
<column xsi:type="smallint" name="module9_is_guest" padding="5" unsigned="true" nullable="true"
identity="false" comment="Is Guest"/>
<column xsi:type="int" name="module9_guest_id" padding="10" unsigned="true" nullable="true" identity="false"
comment="Guest ID"/>
<column xsi:type="date" name="module9_created_at" comment="Created At"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module9_email_contact_id"/>
</constraint>
<constraint xsi:type="unique" referenceId="MODULE9_INSTALL_UNIQUE_INDEX_1">
<column name="module9_email_contact_id"/>
<column name="module9_guest_id"/>
</constraint>
<column xsi:type="int" name="module9_update_column" padding="11" unsigned="false" nullable="false"
identity="false" comment="Module_9 Update Column"/>
<constraint xsi:type="foreign" referenceId="MODULE9_UPDATE_FK_MODULE9_IS_GUEST" table="module9_test_main_table"
column="module9_is_guest" referenceTable="module8_test_main_table"
referenceColumn="module8_is_guest" onDelete="CASCADE"/>
</table>
<table name="module8_test_main_table" resource="default">
<column xsi:type="int" name="module9_update_column" padding="11" unsigned="false" nullable="false"
identity="false" comment="Module_9 Update Column"/>
</table>
<table name="module8_test_update_table" resource="default">
<column name="module8_column_for_remove" disabled="true"/>
<constraint xsi:type="foreign" referenceId="MODULE8_UPDATE_FK_TEMP" disabled="true"/>
<index referenceId="MODULE9_UPDATE_MODULE8_GUEST_BROWSER_ID" indexType="btree">
<column name="module8_guest_browser_id"/>
</index>
<index referenceId="MODULE8_UPDATE_UNIQUE_INDEX_TEMP" disabled="true"/>
</table>
<table name="module8_test_second_table" resource="default">
<constraint xsi:type="foreign" referenceId="MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_CONTACT_ID"
disabled="true"/>
<index referenceId="MODULE8_INSTALL_SECOND_TABLE_INDEX_3_TEMP" disabled="true"/>
</table>
<table name="module8_test_temp_table" disabled="true" resource="default"/>
<table name="module9_test_update_replica_table" resource="default" engine="innodb"
comment="Module9 Test Update Replica Table">
<column xsi:type="int" name="module8_entity_id" padding="10" unsigned="true" nullable="false" identity="true"
comment="Module8 Entity Id"/>
<column xsi:type="int" name="module8_contact_id" padding="11" unsigned="false" nullable="true"
identity="false" comment="Module8 Contact Id"/>
<column xsi:type="varchar" name="module8_address" nullable="false" length="15" comment="Module8 Address"/>
<column xsi:type="smallint" name="module8_counter_with_multiline_comment" padding="5" unsigned="true"
nullable="true" identity="false" default="0" comment="Module8 Counter With Multiline Comment"/>
<column xsi:type="varchar" name="module8_second_address" nullable="true" length="15"
comment="Module8 Second Address"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="module8_entity_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="FK_F205D8789B56A8E75BBFC0C68C041E98"
table="module9_test_update_replica_table" column="module8_address"
referenceTable="module8_test_main_table" referenceColumn="module8_content" onDelete="NO ACTION"/>
<constraint xsi:type="foreign" referenceId="FK_C7075560727757663A51EC925F4032C9"
table="module9_test_update_replica_table" column="module8_address"
referenceTable="module8_test_main_table" referenceColumn="module8_contact_id" onDelete="NO ACTION"/>
<constraint xsi:type="foreign" referenceId="FK_8914AF398964FAFB4ED2E382866ABBF4"
table="module9_test_update_replica_table" column="module8_entity_id"
referenceTable="module8_test_main_table" referenceColumn="module8_email_contact_id"
onDelete="NO ACTION"/>
<index referenceId="MODULE9_TEST_UPDATE_REPLICA_TABLE_MODULE8_ENTITY_ID" indexType="btree">
<column name="module8_entity_id"/>
</index>
<index referenceId="MODULE9_TEST_UPDATE_REPLICA_TABLE_MODULE8_ADDRESS" indexType="btree">
<column name="module8_address"/>
</index>
<index referenceId="MODULE9_TEST_UPDATE_REPLICA_TABLE_MODULE8_SECOND_ADDRESS" indexType="btree">
<column name="module8_second_address"/>
</index>
</table>
</schema>
@@ -0,0 +1,80 @@
{
"reference_table": {
"column": {
"tinyint_ref": true,
"tinyint_without_padding": true,
"bigint_without_padding": true,
"integer_without_padding": true,
"smallint_with_big_padding": true,
"smallint_without_default": true,
"int_without_unsigned": true,
"int_unsigned": true,
"bigint_default_nullable": true,
"bigint_not_default_not_nullable": true,
"smallint_without_padding": true
},
"constraint": {
"tinyint_primary": true,
"PRIMARY": true
}
},
"auto_increment_test": {
"column": {
"int_auto_increment_with_nullable": true,
"int_disabled_auto_increment": true
},
"constraint": {
"AUTO_INCREMENT_TEST_INT_AUTO_INCREMENT_WITH_NULLABLE": true
}
},
"test_table": {
"column": {
"smallint": true,
"tinyint": true,
"bigint": true,
"float": true,
"double": true,
"decimal": true,
"date": true,
"timestamp": true,
"datetime": true,
"longtext": true,
"mediumtext": true,
"varchar": true,
"mediumblob": true,
"blob": true,
"boolean": true,
"varbinary_rename": true
},
"index": {
"TEST_TABLE_TINYINT_BIGINT": true
},
"constraint": {
"TEST_TABLE_SMALLINT_BIGINT": true,
"TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF": true
}
},
"store": {
"column": {
"store_owner_id": true,
"store_owner": true
},
"constraint": {
"STORE_STORE_OWNER_ID_STORE_OWNER_OWNER_ID": true
}
},
"store_owner": {
"column": {
"owner_id": true,
"label": true
},
"constraint": {
"": true
}
},
"some_table": {
"column": {
"some_column": true
}
}
}
@@ -0,0 +1,18 @@
{
"test_table": {
"column": {
"tinyint": true,
"customint": true
},
"index": {
"TEST_TABLE_TINYINT_REFERENCE": true,
"TEST_TABLE_CUSTOMINT_REFERENCE": true,
"TEST_TABLE_CUSTOMINT_BIGINT": true
},
"constraint": {
"TEST_TABLE_INDEX": true,
"TEST_TABLE_CUSTOMINT_INDEX": true,
"TEST_TABLE_CUSTOMINT_REFERENCE_TABLE_TINYINT_REF": true
}
}
}
@@ -0,0 +1,20 @@
{
"reference_test": {
"column": {
"entity_id": true,
"product_id": true
},
"index": {
"REFERENCE_TEST_ENTITY_ID": true
},
"constraint": {
"REFERENCE_TEST_ENTITY_ID_PRODUCT_ID": true,
"REFERENCE_TEST_ENTITY_ID_TEST_TABLE_SMALLINT": true
}
},
"auto_increment_test": {
"column": {
"int_counter": true
}
}
}
@@ -0,0 +1,265 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\Module\DbVersionInfo;
use Magento\Framework\Module\ModuleResource;
use Magento\Framework\Setup\Declaration\Schema\Db\DbSchemaReaderInterface;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TableData;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* The purpose of this test is to check whether whole declarative installation is work
* in mixed mode
*/
class BCMultiModuleTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var DbVersionInfo
*/
private $dbVersionInfo;
/**
* @var TableData
*/
private $tableData;
/**
* @var ModuleResource
*/
private $moduleResource;
/**
* @var DbSchemaReaderInterface
*/
private $dbSchemaReader;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->cliCommand = $objectManager->get(CliCommand::class);
$this->dbVersionInfo = $objectManager->get(DbVersionInfo::class);
$this->tableData = $objectManager->get(TableData::class);
$this->moduleResource = $objectManager->get(ModuleResource::class);
$this->dbSchemaReader = $objectManager->get(DbSchemaReaderInterface::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule6
* @moduleName Magento_TestSetupDeclarationModule7
*/
public function testFirstCleanInstall()
{
$this->cliCommand->install([
'Magento_TestSetupDeclarationModule6',
'Magento_TestSetupDeclarationModule7'
]);
//Check if declaration is applied
$indexes = $this->dbSchemaReader->readIndexes('test_table', 'default');
self::assertCount(1, $indexes);
self::assertArrayHasKey('TEST_TABLE_TINYINT_BIGINT', $indexes);
//Check UpgradeSchema old format, that modify declaration
$columns = $this->dbSchemaReader->readColumns('test_table', 'default');
$floatColumn = $columns['float'];
self::assertEquals(29, $floatColumn['default']);
}
private function doUsToUsRevision()
{
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule7',
'us_to_us',
'UpgradeSchema.php',
'Setup'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule7',
'us_to_us',
'module.xml',
'etc'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule7',
'us_to_us',
'UpgradeData.php',
'Setup'
);
}
private function doUsToDsRevision()
{
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule7',
'swap_with_declaration',
'db_schema.xml',
'etc'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule7',
'swap_with_declaration',
'SomePatch.php',
'Setup/Patch/Data'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule7',
'swap_with_declaration',
'SomeSkippedPatch.php',
'Setup/Patch/Data'
);
}
/**
* Assert that data and schema of 2 modules are installed successfully
*/
private function assertUsToUsUpgrade()
{
$usToUsTables = $this->dbSchemaReader->readTables('default');
self::assertContains('custom_table', $usToUsTables);
self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule7'));
self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule7'));
self::assertEquals(
[6,12],
$this->tableData->describeTableData('reference_table', 'bigint_without_padding')
);
}
/**
* Assert that data and schema of 2 modules are installed successfully
*/
private function assertUsToDsUpgrade()
{
//Check UpgradeSchema old format, that modify declaration
$columns = $this->dbSchemaReader->readColumns('test_table', 'default');
$floatColumn = $columns['float'];
//Check whether declaration will be applied
self::assertEquals(35, $floatColumn['default']);
self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule7'));
self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule7'));
self::assertEquals(
[6,12],
$this->tableData->describeTableData('reference_table', 'bigint_without_padding')
);
self::assertEquals(
['_ref'],
$this->tableData->describeTableData('test_table', 'varchar')
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule6
* @moduleName Magento_TestSetupDeclarationModule7
*/
public function testDSFirstRelease()
{
$this->cliCommand->install([
'Magento_TestSetupDeclarationModule6',
'Magento_TestSetupDeclarationModule7'
]);
//Check no change upgrade with US
$this->cliCommand->upgrade();
$this->doUsToUsRevision();
//Check US to US upgrade
$this->cliCommand->upgrade();
$this->assertUsToUsUpgrade();
$this->doUsToDsRevision();
//Check US to declarative schema upgrade
$this->cliCommand->upgrade();
$this->assertUsToDsUpgrade();
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule7',
'wl_remove_table',
'db_schema_whitelist.json',
'etc'
);
//Check removal case, when we need to remove table with declaration and table was created in old scripts
$this->cliCommand->upgrade();
$tables = $this->dbSchemaReader->readTables('default');
self::assertNotContains('custom_table', $tables);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProvider firstCleanInstallOneModuleDataProvider
* @param string $dbPrefix
* @param string $tableName
* @param string $indexName
* @param string $constraintName
* @param string $foreignKeyName
* @throws \Exception
*/
public function testFirstCleanInstallOneModule(
string $dbPrefix,
string $tableName,
string $indexName,
string $constraintName,
string $foreignKeyName
) {
$this->cliCommand->install(
[
'Magento_TestSetupDeclarationModule1'
],
[
'db-prefix' => $dbPrefix,
]
);
$indexes = $this->dbSchemaReader
->readIndexes($tableName, 'default');
self::assertCount(1, $indexes);
self::assertArrayHasKey($indexName, $indexes);
$constraints = $this->dbSchemaReader
->readConstraints($tableName, 'default');
self::assertCount(1, $constraints);
self::assertArrayHasKey($constraintName, $constraints);
$foreignKeys = $this->dbSchemaReader
->readReferences($tableName, 'default');
self::assertCount(1, $foreignKeys);
self::assertArrayHasKey($foreignKeyName, $foreignKeys);
}
/**
* @return array
*/
public function firstCleanInstallOneModuleDataProvider()
{
return [
'Installation without db prefix' => [
'dbPrefix' => '',
'tableName' => 'test_table',
'indexName' => 'TEST_TABLE_TINYINT_BIGINT',
'constraintName' => 'TEST_TABLE_SMALLINT_BIGINT',
'foreignKeyName' => 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF',
],
'Installation with db prefix' => [
'dbPrefix' => 'spec_',
'tableName' => 'spec_test_table',
'indexName' => 'SPEC_TEST_TABLE_TINYINT_BIGINT',
'constraintName' => 'SPEC_TEST_TABLE_SMALLINT_BIGINT',
'foreignKeyName' => 'SPEC_TEST_TABLE_TINYINT_SPEC_REFERENCE_TABLE_TINYINT_REF',
]
];
}
}
@@ -0,0 +1,172 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\Module\DbVersionInfo;
use Magento\Framework\Module\ModuleList;
use Magento\Framework\Module\ModuleResource;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TableData;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* The purpose of this test is to check whether patch changes in Magento are backward compatible
*/
class BCPatchTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var DbVersionInfo
*/
private $dbVersionInfo;
/**
* @var TableData
*/
private $tableData;
/**
* @var ModuleResource
*/
private $moduleResource;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->cliCommand = $objectManager->get(CliCommand::class);
$this->dbVersionInfo = $objectManager->get(DbVersionInfo::class);
$this->tableData = $objectManager->get(TableData::class);
$this->moduleResource = $objectManager->get(ModuleResource::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule5
*/
public function testSuccessfullInstall()
{
$this->cliCommand->install(['Magento_TestSetupDeclarationModule5']);
self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
}
/**
* @moduleName Magento_TestSetupDeclarationModule5
*/
public function testDataMixedMode()
{
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule5',
'old-scripts',
'UpgradeData.php',
'Setup'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule5',
'patches',
'SomePatch.php',
'Setup/Patch/Data'
);
$this->cliCommand->install(['Magento_TestSetupDeclarationModule5']);
self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
self::assertEquals(
[6,12],
$this->tableData->describeTableData('reference_table', 'some_integer')
);
self::assertEquals(
['_ref'],
$this->tableData->describeTableData('test_table', 'varchar')
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule5
*/
public function testSkippedPatch()
{
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule5',
'patches',
'SomePatch.php',
'Setup/Patch/Data'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule5',
'patches',
'SomeSkippedPatch.php',
'Setup/Patch/Data'
);
$this->cliCommand->install(['Magento_TestSetupDeclarationModule5']);
self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
self::assertEquals(
['_ref'],
$this->tableData->describeTableData('test_table', 'varchar')
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule5
*/
public function testDataInstallationWithoutVersion()
{
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule5',
'module-without-version',
'module.xml',
'etc'
);
$this->cliCommand->install(['Magento_TestSetupDeclarationModule5']);
self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
$this->moduleResource->setDataVersion('Magento_TestSetupDeclarationModule5', '1.0.2');
$this->moduleResource->setDataVersion('Magento_TestSetupDeclarationModule5', '1.0.2');
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule5',
'old-scripts',
'UpgradeData.php',
'Setup'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule5',
'patches',
'SomePatch.php',
'Setup/Patch/Data'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule5',
'patches',
'SomeSkippedPatch.php',
'Setup/Patch/Data'
);
$this->cliCommand->upgrade();
self::assertTrue($this->dbVersionInfo->isDataUpToDate('Magento_TestSetupDeclarationModule5'));
self::assertTrue($this->dbVersionInfo->isSchemaUpToDate('Magento_TestSetupDeclarationModule5'));
//Old scripts should be skipped because we do not have version
self::assertEquals(
[],
$this->tableData->describeTableData('reference_table', 'some_integer')
);
self::assertEquals(
['_ref'],
$this->tableData->describeTableData('test_table', 'varchar')
);
}
}
@@ -0,0 +1,239 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\Module\ModuleResource;
use Magento\Framework\Setup\Patch\PatchHistory;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TableData;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
use Magento\TestSetupDeclarationModule3\Setup\Patch\Data\IncrementalSomeIntegerPatch;
use Magento\TestSetupDeclarationModule3\Setup\Patch\Data\ReferenceIncrementalSomeIntegerPatch;
use Magento\TestSetupDeclarationModule3\Setup\Patch\Data\ZFirstPatch;
/**
* The purpose of this test is validating schema reader operations.
*/
class DataPatchInstallationTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommad;
/**
* @var ModuleResource
*/
private $moduleResource;
/**
* @var PatchHistory
*/
private $patchList;
/**
* @var TableData
*/
private $tableData;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->cliCommad = $objectManager->get(CliCommand::class);
$this->moduleResource = $objectManager->get(ModuleResource::class);
$this->patchList = $objectManager->get(PatchHistory::class);
$this->tableData = $objectManager->get(TableData::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule3
*/
public function testDataPatchesInstallation()
{
$this->cliCommad->install(
['Magento_TestSetupDeclarationModule3']
);
self::assertEquals(
'0.0.1',
$this->moduleResource->getDataVersion('Magento_TestSetupDeclarationModule3')
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule3',
'first_patch_revision',
'module.xml',
'etc'
);
$this->movePatches();
ModuleResource::flush();
$this->cliCommad->upgrade();
self::assertEquals(
'0.0.3',
$this->moduleResource->getDataVersion('Magento_TestSetupDeclarationModule3')
);
self::assertTrue($this->patchList->isApplied(IncrementalSomeIntegerPatch::class));
self::assertTrue($this->patchList->isApplied(ReferenceIncrementalSomeIntegerPatch::class));
self::assertTrue($this->patchList->isApplied(ZFirstPatch::class));
$tableData = $this->tableData->describeTableData('test_table');
self::assertEquals($this->getTestTableData(), $tableData);
}
/**
* @moduleName Magento_TestSetupDeclarationModule3
*/
public function testCyclomaticDependency()
{
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule3',
'cyclomatic_and_bic_revision',
'module.xml',
'etc'
);
$this->movePatches();
/**
* Test whether installation give the same result as upgrade
*/
$this->cliCommad->install(
['Magento_TestSetupDeclarationModule3']
);
$tableData = $this->tableData->describeTableData('test_table');
self::assertEquals($this->getTestTableData(), $tableData);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule3',
'cyclomatic_and_bic_revision',
'BicPatch.php',
'Setup/Patch/Data'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule3',
'cyclomatic_and_bic_revision',
'RefBicPatch.php',
'Setup/Patch/Data'
);
$this->cliCommad->upgrade();
}
/**
* Move patches
*/
private function movePatches()
{
//Install with patches
$this->moduleManager->addRevision(
'Magento_TestSetupDeclarationModule3',
'patches_revision',
'Setup/Patch/Data'
);
//Upgrade with UpgradeData
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule3',
'first_patch_revision',
'UpgradeData.php',
'Setup'
);
//Upgrade with UpgradeData
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule3',
'first_patch_revision',
'module.xml',
'etc'
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule3
*/
public function testPatchesRevert()
{
$this->movePatches();
$this->cliCommad->install(['Magento_TestSetupDeclarationModule3']);
$this->cliCommad->uninstallModule('Magento_TestSetupDeclarationModule3');
$testTableData = $this->tableData->describeTableData('test_table');
$patchListTableData = $this->tableData->describeTableData('patch_list');
self::assertEmpty($patchListTableData);
self::assertEmpty($testTableData);
$refTableData = $this->tableData->describeTableData('reference_table');
self::assertEquals($this->getRefTableData(), $refTableData);
}
/**
* @return array
*/
private function getTestTableData()
{
return [
[
'smallint' => '1',
'tinyint' => null,
'varchar' => 'Ololo123',
'varbinary' => '33288',
],
[
'smallint' => '2',
'tinyint' => null,
'varchar' => 'Ololo123_ref',
'varbinary' => '33288',
],
[
'smallint' => '3',
'tinyint' => null,
'varchar' => 'changed__very_secret_string',
'varbinary' => '0',
],
];
}
/**
* Retrieve reference table data
*
* @return array
*/
private function getRefTableData()
{
return [
[
'tinyint_ref' => '2',
'some_integer' => '2',
'for_patch_testing' => null,
],
[
'tinyint_ref' => '3',
'some_integer' => '3',
'for_patch_testing' => null,
],
[
'tinyint_ref' => '4',
'some_integer' => '5',
'for_patch_testing' => null,
],
[
'tinyint_ref' => '5',
'some_integer' => '6',
'for_patch_testing' => null,
],
[
'tinyint_ref' => '6',
'some_integer' => '12',
'for_patch_testing' => null,
],
];
}
}
@@ -0,0 +1,492 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Setup\Declaration\Schema\Diff\SchemaDiff;
use Magento\Framework\Setup\Declaration\Schema\SchemaConfigInterface;
use Magento\Framework\Setup\Declaration\Schema\Sharding;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\DescribeTable;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* The purpose of this test is verifying declarative installation works.
*/
class DeclarativeInstallerTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var SchemaDiff
*/
private $schemaDiff;
/**
* @var SchemaConfigInterface
*/
private $schemaConfig;
/**
* @var ResourceConnection
*/
private $resourceConnection;
/**
* @var DescribeTable
*/
private $describeTable;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->cliCommand = $objectManager->get(CliCommand::class);
$this->describeTable = $objectManager->get(DescribeTable::class);
$this->schemaDiff = $objectManager->get(SchemaDiff::class);
$this->schemaConfig = $objectManager->get(SchemaConfigInterface::class);
$this->resourceConnection = $objectManager->get(ResourceConnection::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/installation.php
*/
public function testInstallation()
{
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1']
);
$diff = $this->schemaDiff->diff(
$this->schemaConfig->getDeclarationConfig(),
$this->schemaConfig->getDbConfig()
);
//Second time installation should not find anything as we do not change anything
self::assertNull($diff->getAll());
$this->compareStructures();
}
/**
* Compare structure of DB and declared structure.
*/
private function compareStructures()
{
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
foreach ($this->getTrimmedData() as $tableName => $sql) {
$this->assertArrayHasKey($tableName, $shardData);
/**
* MySQL 8.0 and above does not provide information about the ON DELETE instruction
* if ON DELETE NO ACTION
*/
if (preg_match('#ON DELETE\s+NO ACTION#i', $shardData[$tableName] === 1)) {
preg_replace('#ON DELETE\s+NO ACTION#i', '', $sql);
self::assertEquals($sql, $shardData[$tableName]);
}
}
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/column_modification.php
* @throws \Exception
*/
public function testInstallationWithColumnsModification()
{
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1']
);
//Move InstallSchema file and tried to install
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'column_modifications',
'db_schema.xml',
'etc'
);
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1']
);
$diff = $this->schemaDiff->diff(
$this->schemaConfig->getDeclarationConfig(),
$this->schemaConfig->getDbConfig()
);
self::assertNull($diff->getAll());
$this->compareStructures();
}
/**
* Updates revision for db_schema and db_schema_whitelist files
*
* @param string $revisionName
*/
private function updateDbSchemaRevision($revisionName)
{
//Move InstallSchema file and tried to install
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
$revisionName,
'db_schema.xml',
'etc'
);
//Move InstallSchema file and tried to install
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
$revisionName,
'db_schema_whitelist.json',
'etc'
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/column_removal.php
* @throws \Exception
*/
public function testInstallationWithColumnsRemoval()
{
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1']
);
$this->updateDbSchemaRevision('column_removals');
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1']
);
$diff = $this->schemaDiff->diff(
$this->schemaConfig->getDeclarationConfig(),
$this->schemaConfig->getDbConfig()
);
self::assertNull($diff->getAll());
$this->compareStructures();
}
/**
* As sometimes we want to ignore spaces and other special characters,
* we need to trim data before compare it
*
* @return array
*/
private function getTrimmedData()
{
$data = [];
foreach ($this->getData() as $key => $createTable) {
$data[$key] = preg_replace('/(\s)\n/', '$1', $createTable);
}
return $data;
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/constraint_modification.php
* @throws \Exception
*/
public function testInstallationWithConstraintsModification()
{
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1']
);
$this->updateDbSchemaRevision('constraint_modifications');
$this->cliCommand->upgrade();
$diff = $this->schemaDiff->diff(
$this->schemaConfig->getDeclarationConfig(),
$this->schemaConfig->getDbConfig()
);
self::assertNull($diff->getAll());
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
$this->assertTableCreationStatements($this->getTrimmedData(), $shardData);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/table_removal.php
* @throws \Exception
*/
public function testInstallationWithDroppingTables()
{
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1']
);
//Move db_schema.xml file and tried to install
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'drop_table',
'db_schema.xml',
'etc'
);
$this->cliCommand->upgrade();
$diff = $this->schemaDiff->diff(
$this->schemaConfig->getDeclarationConfig(),
$this->schemaConfig->getDbConfig()
);
self::assertNull($diff->getAll());
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
$this->assertTableCreationStatements($this->getData(), $shardData);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @moduleName Magento_TestSetupDeclarationModule3
*/
public function testInstallationWithDroppingTablesFromSecondaryModule()
{
$modules = [
'Magento_TestSetupDeclarationModule1',
'Magento_TestSetupDeclarationModule3',
];
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule3',
'drop_table_with_external_dependency',
'db_schema.xml',
'etc'
);
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'without_setup_version',
'module.xml',
'etc'
);
}
try {
$this->cliCommand->install($modules);
} catch (\Exception $e) {
$installException = $e->getPrevious();
self::assertSame(1, $installException->getCode());
self::assertStringContainsString(
'The reference table named "reference_table" is disabled',
$installException->getMessage()
);
}
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/rollback.php
* @throws \Exception
*/
public function testInstallWithCodeBaseRollback()
{
//Move db_schema.xml file and tried to install
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'before_rollback',
'db_schema.xml',
'etc'
);
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1']
);
if ($this->isUsingAuroraDb()) {
$this->markTestSkipped('Test skipped in AWS Aurora');
}
$beforeRollback = $this->describeTable->describeShard('default');
self::assertEquals($this->getTrimmedData()['before'], $beforeRollback);
//Move db_schema.xml file and tried to install
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'after_rollback',
'db_schema.xml',
'etc'
);
$this->cliCommand->upgrade();
$afterRollback = $this->describeTable->describeShard('default');
self::assertEquals($this->getData()['after'], $afterRollback);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/declarative_installer/table_rename.php
* @throws \Exception
*/
public function testTableRename()
{
$dataToMigrate = ['some_column' => 'Some Value'];
//Move db_schema.xml file and tried to install
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'table_rename',
'db_schema.xml',
'etc'
);
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1']
);
$before = $this->describeTable->describeShard('default');
$adapter = $this->resourceConnection->getConnection('default');
$adapter->insert(
$this->resourceConnection->getTableName('some_table'),
$dataToMigrate
);
$this->isUsingAuroraDb() ?
$this->assertStringContainsString($before['some_table'], $this->getTrimmedData()['before']) :
$this->assertEquals($this->getData()['before'], $before['some_table']);
//Move db_schema.xml file and tried to install
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'table_rename_after',
'db_schema.xml',
'etc'
);
$this->cliCommand->upgrade();
$after = $this->describeTable->describeShard('default');
$this->isUsingAuroraDb() ?
$this->assertStringContainsString($after['some_table_renamed'], $this->getTrimmedData()['after']) :
$this->assertEquals($this->getData()['after'], $after['some_table_renamed']);
$select = $adapter->select()
->from($this->resourceConnection->getTableName('some_table_renamed'));
self::assertEquals([$dataToMigrate], $adapter->fetchAll($select));
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
* @throws \Exception
*/
public function testForeignKeyReferenceId()
{
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule8']
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule8',
'unpatterned_fk_name',
'db_schema.xml',
'etc'
);
$this->cliCommand->upgrade();
$tableStatements = $this->describeTable->describeShard('default');
$tableSql = $tableStatements['dependent'];
$this->assertMatchesRegularExpression('/CONSTRAINT\s`DEPENDENT_PAGE_ID_ON_TEST_TABLE_PAGE_ID`/', $tableSql);
$this->assertMatchesRegularExpression(
'/CONSTRAINT\s`DEPENDENT_SCOPE_ID_ON_TEST_SCOPE_TABLE_SCOPE_ID`/',
$tableSql
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @moduleName Magento_TestSetupDeclarationModule8
* @throws \Exception
*/
public function testDisableIndexByExternalModule()
{
$this->cliCommand->install(
['Magento_TestSetupDeclarationModule1', 'Magento_TestSetupDeclarationModule8']
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'index_to_disable',
'db_schema.xml',
'etc'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule8',
'disable_index_by_external_module',
'db_schema.xml',
'etc'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule8',
'disable_index_by_external_module',
'db_schema_whitelist.json',
'etc'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule8',
'disable_index_by_external_module',
'module.xml',
'etc'
);
$this->cliCommand->upgrade();
$tableStatements = $this->describeTable->describeShard('default');
$tableSql = $tableStatements['test_table'];
$this->assertDoesNotMatchRegularExpression(
'/KEY\s+`TEST_TABLE_VARCHAR`\s+\(`varchar`\)/',
$tableSql,
'Index is not being disabled by external module'
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
* @moduleName Magento_TestSetupDeclarationModule9
* @dataProviderFromFile Magento/TestSetupDeclarationModule9/fixture/declarative_installer/disabling_tables.php
* @throws \Exception
*/
public function testInstallationWithDisablingTables()
{
$modules = [
'Magento_TestSetupDeclarationModule8',
'Magento_TestSetupDeclarationModule9',
];
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'disabling_tables',
'db_schema.xml',
'etc'
);
}
$this->cliCommand->install($modules);
$diff = $this->schemaDiff->diff(
$this->schemaConfig->getDeclarationConfig(),
$this->schemaConfig->getDbConfig()
);
self::assertNull($diff->getAll());
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
$this->assertTableCreationStatements($this->getData(), $shardData);
}
/**
* Assert table creation statements
*
* @param array $expectedData
* @param array $actualData
*/
private function assertTableCreationStatements(array $expectedData, array $actualData): void
{
if (!$this->isUsingAuroraDb()) {
$this->assertEquals($expectedData, $actualData);
} else {
ksort($expectedData);
ksort($actualData);
$this->assertSameSize($expectedData, $actualData);
foreach ($expectedData as $key => $value) {
$this->assertStringContainsString($actualData[$key], $value);
}
}
}
}
@@ -0,0 +1,86 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\Setup\Declaration\Schema\Dto\Columns\Timestamp;
use Magento\Framework\Setup\Declaration\Schema\Dto\Constraints\Internal;
use Magento\Framework\Setup\Declaration\Schema\Dto\Constraints\Reference;
use Magento\Framework\Setup\Declaration\Schema\SchemaConfig;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* @magentoAppIsolation enabled
* The purpose of this test is verifying initial InstallSchema, InstallData scripts.
*/
class DeclarativeSchemaBuilderTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var SchemaConfig
*/
private $schemaConfig;
/**
* @var CliCommand
*/
private $cliCommad;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->schemaConfig = $objectManager->create(SchemaConfig::class);
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->cliCommad = $objectManager->get(CliCommand::class);
}
/**
* Tests primary key constraint conversion from XML and renamed functionality.
*
* @moduleName Magento_TestSetupDeclarationModule1
*/
public function testSchemaBuilder()
{
$this->cliCommad->install(
['Magento_TestSetupDeclarationModule1']
);
$dbSchema = $this->schemaConfig->getDeclarationConfig();
$schemaTables = $dbSchema->getTables();
self::assertArrayHasKey('reference_table', $dbSchema->getTables());
self::assertArrayHasKey('test_table', $dbSchema->getTables());
//Test primary key and renaming
$referenceTable = $schemaTables['reference_table'];
/**
* @var Internal $primaryKey
*/
$primaryKey = $referenceTable->getPrimaryConstraint();
$columns = $primaryKey->getColumns();
self::assertEquals('tinyint_ref', reset($columns)->getName());
//Test column
$testTable = $schemaTables['test_table'];
/**
* @var Timestamp $timestampColumn
*/
$timestampColumn = $testTable->getColumnByName('timestamp');
self::assertEquals('CURRENT_TIMESTAMP', $timestampColumn->getOnUpdate());
//Test disabled
self::assertArrayNotHasKey('varbinary_rename', $testTable->getColumns());
//Test foreign key
/**
* @var Reference $foreignKey
*/
$foreignKey = $testTable->getConstraintByName('TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF');
self::assertEquals('NO ACTION', $foreignKey->getOnDelete());
self::assertEquals('tinyint_ref', $foreignKey->getReferenceColumn()->getName());
}
}
@@ -0,0 +1,182 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\Setup\Declaration\Schema\Diff\DiffFactory;
use Magento\Framework\Setup\Declaration\Schema\Diff\SchemaDiff;
use Magento\Framework\Setup\Declaration\Schema\SchemaConfigInterface;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* The purpose of this test is verifying initial InstallSchema, InstallData scripts.
*/
class DiffOldSchemaTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommad;
/**
* @var SchemaDiff
*/
private $schemaDiff;
/**
* @var DiffFactory
*/
private $changeRegistryFactory;
/**
* @var SchemaConfigInterface
*/
private $schemaConfig;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->cliCommad = $objectManager->get(CliCommand::class);
$this->schemaConfig = $objectManager->get(SchemaConfigInterface::class);
$this->schemaDiff = $objectManager->get(SchemaDiff::class);
$this->changeRegistryFactory = $objectManager->get(DiffFactory::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
*/
public function testOldDiff()
{
//Move db_schema.xml
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'old_diff_before',
'db_schema.xml',
'etc'
);
//Move InstallSchema file and tried to install
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'old_diff',
'InstallSchema.php',
'Setup'
);
$this->cliCommad->install(['Magento_TestSetupDeclarationModule1']);
//Move db_schema.xml
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'old_diff',
'db_schema.xml',
'etc'
);
$declarativeSchema = $this->schemaConfig->getDeclarationConfig();
$generatedSchema = $this->schemaConfig->getDbConfig();
$diff = $this->schemaDiff->diff($declarativeSchema, $generatedSchema);
$allChanges = $diff->getAll();
self::assertCount(1, $allChanges);
self::assertEquals(
$this->getBigIntKeyXmlSensitiveData(),
reset($allChanges)['modify_column'][0]->getNew()->getDiffSensitiveParams()
);
self::assertEquals(
$this->getBigIntKeyDbSensitiveData(),
reset($allChanges)['modify_column'][0]->getOld()->getDiffSensitiveParams()
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @param string $dbPrefix
* @throws \Exception
* @dataProvider oldSchemaUpgradeDataProvider
*/
public function testOldSchemaUpgrade(string $dbPrefix)
{
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'old_diff_before',
'db_schema.xml',
'etc'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'base_update',
'InstallSchema.php',
'Setup'
);
$this->cliCommad->install(
['Magento_TestSetupDeclarationModule1'],
['db-prefix' => $dbPrefix]
);
//Move db_schema.xml
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'base_update',
'db_schema.xml',
'etc'
);
$declarativeSchema = $this->schemaConfig->getDeclarationConfig();
$generatedSchema = $this->schemaConfig->getDbConfig();
$diff = $this->schemaDiff->diff($declarativeSchema, $generatedSchema);
self::assertEmpty($diff->getAll());
}
/**
* @return array
*/
public function oldSchemaUpgradeDataProvider(): array
{
return [
'Without db prefix' => [
'dbPrefix' => '',
],
'With db prefix' => [
'dbPrefix' => 'spec_',
],
];
}
/**
* @return array
*/
private function getBigIntKeyDbSensitiveData()
{
return [
'type' => 'bigint',
'nullable' => true,
'padding' => null,
'unsigned' => false,
'identity' => false,
'default' => 0,
'comment' => 'Bigint'
];
}
/**
* @return array
*/
private function getBigIntKeyXmlSensitiveData()
{
return [
'type' => 'bigint',
'nullable' => true,
'padding' => null,
'unsigned' => false,
'identity' => false,
'default' => 1,
'comment' => 'Bigint',
];
}
}
@@ -0,0 +1,72 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\Setup\Declaration\Schema\DryRunLogger;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* The purpose of this test is verifying declarative installation works.
*/
class DryRunTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommad;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->cliCommad = $objectManager->get(CliCommand::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/dry_run_log.php
*/
public function testDryRunOnCleanDatabase()
{
$logFileName = TESTS_TEMP_DIR . '/var/log/' . DryRunLogger::FILE_NAME;
$this->cliCommad->install(
['Magento_TestSetupDeclarationModule1'],
['dry-run' => true]
);
self::assertFileExists($logFileName);
$data = file_get_contents($logFileName);
self::assertEquals($this->getData()[0], $data);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/dry_run_log_on_upgrade.php
*/
public function testDryRunOnUpgrade()
{
$logFileName = TESTS_TEMP_DIR . '/var/log/' . DryRunLogger::FILE_NAME;
$this->cliCommad->install(['Magento_TestSetupDeclarationModule1']);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
'column_modifications',
'db_schema.xml',
'etc'
);
$this->cliCommad->upgrade(['dry-run' => true]);
self::assertFileExists($logFileName);
$data = file_get_contents($logFileName);
self::assertEquals($this->getData()[0], $data);
}
}
@@ -0,0 +1,150 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Setup\Declaration\Schema\Db\DbSchemaReaderInterface;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* The purpose of this test is verifying safe declarative installation works.
*/
class SafeInstallerTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var ResourceConnection
*/
private $resourceConnection;
/**
* @var DbSchemaReaderInterface
*/
private $dbSchemaReader;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->cliCommand = $objectManager->get(CliCommand::class);
$this->resourceConnection = $objectManager->get(ResourceConnection::class);
$this->dbSchemaReader = $objectManager->get(DbSchemaReaderInterface::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule4
* @dataProviderFromFile Magento/TestSetupDeclarationModule4/fixture/safe_data_provider.php
*/
public function testInstallation()
{
$testTableData = $this->getData();
$row = reset($testTableData);
$this->cliCommand->install(['Magento_TestSetupDeclarationModule4']);
$adapter = $this->resourceConnection->getConnection();
$testTableName = $this->resourceConnection->getTableName('test_table');
$adapter->insertArray(
$this->resourceConnection->getTableName('test_table'),
array_keys($row),
$this->getData()
);
//Move new db_schema.xml
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule4',
'remove_title_column',
'db_schema.xml',
'etc'
);
$this->cliCommand->upgrade(
[
'safe-mode' => true,
]
);
//Move new db_schema.xml with restored title field
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule4',
'restore_title_column',
'db_schema.xml',
'etc'
);
$this->cliCommand->upgrade(
[
'data-restore' => true,
]
);
$testTableSelect = $adapter->select()->from($testTableName);
self::assertEquals($testTableData, $adapter->fetchAll($testTableSelect));
}
/**
* Tests that not whitelisted elements should not be removed from DB to avoid backwards-incompatible change.
*
* @moduleName Magento_TestSetupDeclarationModule6
*/
public function testDestructiveOperationBehaviour()
{
$this->cliCommand->install(['Magento_TestSetupDeclarationModule6']);
$this->assertForeignKeyPresence('test_table', 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF');
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule6',
'remove_fk_declaration',
'db_schema.xml',
'etc'
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule6',
'remove_fk_declaration',
'db_schema_whitelist.json',
'etc'
);
$this->cliCommand->upgrade();
$this->assertForeignKeyPresence('test_table', 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF');
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule6',
'restore_fk_declaration_to_wl',
'db_schema_whitelist.json',
'etc'
);
$this->cliCommand->upgrade();
$this->assertForeignKeyPresence('test_table', 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF', false);
}
/**
* Asserts foreign key presence.
*
* @param string $tableName
* @param string $foreignKeyName
* @param bool $isPresent
* @return void
*/
private function assertForeignKeyPresence(string $tableName, string $foreignKeyName, bool $isPresent = true): void
{
$foreignKeys = $this->dbSchemaReader
->readReferences($this->resourceConnection->getTableName($tableName), 'default');
if ($isPresent) {
$this->assertArrayHasKey($foreignKeyName, $foreignKeys);
} else {
$this->assertArrayNotHasKey($foreignKeyName, $foreignKeys);
}
}
}
@@ -0,0 +1,86 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\Setup\Declaration\Schema\Declaration\ReaderComposite;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* The purpose of this test is validating schema reader operations.
*/
class SchemaReaderTest extends SetupTestCase
{
/**
* @var \Magento\Framework\Setup\Declaration\Schema\FileSystem\XmlReader
*/
private $reader;
/**
* @var TestModuleManager
*/
private $moduleManager;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->reader = $objectManager->get(ReaderComposite::class);
$this->moduleManager = $objectManager->get(TestModuleManager::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/valid_xml_revision_1.php
*/
public function testSuccessfullRead()
{
$schema = $this->reader->read('all');
unset($schema['table']['patch_list']);
self::assertEquals($this->getData(), $schema);
}
/**
* Helper method. Decrease number of params
*
* @param string $revisionName
* @return void
*/
private function updateRevisionTo($revisionName)
{
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule1',
$revisionName,
TestModuleManager::DECLARATIVE_FILE_NAME,
'etc'
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
*/
public function testFailOnInvalidColumnDeclaration()
{
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessageMatches('/The attribute \'scale\' is not allowed./');
$this->updateRevisionTo('fail_on_column_declaration');
$this->reader->read('all');
}
/**
* @moduleName Magento_TestSetupDeclarationModule1
* @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/foreign_key_interpreter_result.php
*/
public function testForeignKeyInterpreter()
{
$this->updateRevisionTo('foreign_key_interpreter');
$schema = $this->reader->read('all');
unset($schema['table']['patch_list']);
self::assertEquals($this->getData(), $schema);
}
}
@@ -0,0 +1,124 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ResourceConnection;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\DescribeTable;
use Magento\TestFramework\Deploy\ShardingConfig;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
use Magento\TestFramework\Deploy\TestModuleManager;
/**
* The purpose of this test is verifying declarative installation works with different shard.
*/
class ShardingTest extends SetupTestCase
{
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var DescribeTable
*/
private $describeTable;
/**
* @var ResourceConnection
*/
private $resourceConnection;
/**
* @var DeploymentConfig
*/
private $deploymentConfig;
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var ShardingConfig
*/
private $shardingConfig;
protected function setUp(): void
{
$objectManager= Bootstrap::getObjectManager();
$this->cliCommand = $objectManager->get(CliCommand::class);
$this->resourceConnection = $objectManager->get(ResourceConnection::class);
$this->deploymentConfig = $objectManager->get(DeploymentConfig::class);
$this->describeTable = $objectManager->get(DescribeTable::class);
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->shardingConfig = $objectManager->get(ShardingConfig::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule2
* @dataProviderFromFile Magento/TestSetupDeclarationModule2/fixture/shards.php
*/
public function testInstall()
{
$this->shardingConfig->applyConfiguration();
$this->cliCommand->install(['Magento_TestSetupDeclarationModule2']);
$this->deploymentConfig->resetData();
$default = $this->describeTable->describeShard('default');
$shard1 = $this->describeTable->describeShard('shard_one');
$shard2 = $this->describeTable->describeShard('shard_two');
//Check if tables were installed on different shards
self::assertCount(2, $default);
self::assertCount(1, $shard1);
self::assertCount(1, $shard2);
$this->assertTableCreationStatements($this->getData(), array_replace($default, $shard1, $shard2));
}
/**
* @moduleName Magento_TestSetupDeclarationModule2
* @dataProviderFromFile Magento/TestSetupDeclarationModule2/fixture/shards.php
*/
public function testUpgrade()
{
$this->shardingConfig->applyConfiguration();
$this->cliCommand->install(['Magento_TestSetupDeclarationModule2']);
$this->deploymentConfig->resetData();
$this->cliCommand->upgrade();
$default = $this->describeTable->describeShard('default');
$shard1 = $this->describeTable->describeShard('shard_one');
$shard2 = $this->describeTable->describeShard('shard_two');
//Check if tables were installed on different shards
self::assertCount(2, $default);
self::assertCount(1, $shard1);
self::assertCount(1, $shard2);
$this->assertTableCreationStatements($this->getData(), array_replace($default, $shard1, $shard2));
}
/**
* Assert table creation statements
*
* @param array $expectedData
* @param array $actualData
*/
private function assertTableCreationStatements(array $expectedData, array $actualData): void
{
if (!$this->isUsingAuroraDb()) {
$this->assertEquals($expectedData, $actualData);
} else {
ksort($expectedData);
ksort($actualData);
$this->assertSameSize($expectedData, $actualData);
foreach ($expectedData as $key => $value) {
$this->assertStringContainsString($actualData[$key], $value);
}
}
}
}
@@ -0,0 +1,132 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Setup\Declaration\Schema\SchemaConfig;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* The purpose of this test is verifying initial InstallSchema, InstallData scripts.
*/
class ValidationRulesTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var SchemaConfig
*/
private $schemaConfig;
/**
* @var CliCommand
*/
private $cliCommad;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->schemaConfig = $objectManager->create(SchemaConfig::class);
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->cliCommad = $objectManager->get(CliCommand::class);
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
*/
public function testFailOnInvalidPrimaryKey()
{
$this->expectException(LocalizedException::class);
$this->expectExceptionMessageMatches(
'/Primary key can`t be applied on table "test_table". All columns should be not nullable/'
);
$this->cliCommad->install(
['Magento_TestSetupDeclarationModule8']
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule8',
'invalid_primary_key',
'db_schema.xml',
'etc'
);
$this->schemaConfig->getDeclarationConfig();
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
*/
public function testFailOnIncosistentReferenceDefinition()
{
$this->expectException(LocalizedException::class);
$this->expectExceptionMessageMatches(
'/Column definition "page_id_on" and reference column definition "page_id"'
. ' are different in tables "dependent" and "test_table"/'
);
$this->cliCommad->install(
['Magento_TestSetupDeclarationModule8']
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule8',
'incosistence_reference_definition',
'db_schema.xml',
'etc'
);
$this->schemaConfig->getDeclarationConfig();
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
*/
public function testFailOnInconsistentReferenceTypeDefinition()
{
$this->expectException(LocalizedException::class);
$this->expectExceptionMessageMatches(
'/Column definition "page_id_on" and reference column definition "page_id"'
. ' are different in tables "dependent" and "test_table"/'
);
$this->cliCommad->install(
['Magento_TestSetupDeclarationModule8']
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule8',
'inconsistent_reference_type_definition',
'db_schema.xml',
'etc'
);
$this->schemaConfig->getDeclarationConfig();
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
*/
public function testFailOnInvalidAutoIncrementField()
{
$this->expectException(LocalizedException::class);
$this->expectExceptionMessageMatches('/Auto Increment column do not have index. Column - "page_id"/');
$this->cliCommad->install(
['Magento_TestSetupDeclarationModule8']
);
$this->moduleManager->updateRevision(
'Magento_TestSetupDeclarationModule8',
'invalid_auto_increment',
'db_schema.xml',
'etc'
);
$this->schemaConfig->getDeclarationConfig();
}
}