diff --git a/src/MySql/AuditDiff.php b/src/MySql/AuditDiff.php index 5c5f958..aed3794 100755 --- a/src/MySql/AuditDiff.php +++ b/src/MySql/AuditDiff.php @@ -293,7 +293,7 @@ private function resolveCanonicalAuditColumns() { if (empty($this->config['audit_columns'])) { - $this->auditColumnsMetadata = new TableColumnsMetadata(); + $this->auditColumnsMetadata = []; } else { diff --git a/test/MySql/AbcFramework/AbcFrameworkTest.php b/test/MySql/AuditCommand/AbcFramework/AbcFrameworkTest.php old mode 100644 new mode 100755 similarity index 99% rename from test/MySql/AbcFramework/AbcFrameworkTest.php rename to test/MySql/AuditCommand/AbcFramework/AbcFrameworkTest.php index 760a33b..e3452f0 --- a/test/MySql/AbcFramework/AbcFrameworkTest.php +++ b/test/MySql/AuditCommand/AbcFramework/AbcFrameworkTest.php @@ -1,6 +1,6 @@ runAudit(); + + // Create new column. + StaticDataLayer::multiQuery(file_get_contents(__DIR__.'/config/change_charset.sql')); + + $this->runDiff(); + } + + //-------------------------------------------------------------------------------------------------------------------- + private function runDiff() + { + $application = new Application(); + $application->add(new DiffCommand()); + + /** @var DiffCommand $command */ + $command = $application->find('diff'); + $command->setRewriteConfigFile(false); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName(), + 'config file' => __DIR__.'/config/audit.json']); + + $output = $commandTester->getDisplay(); + $this->assertContains('| c4 | varchar(20) | varchar(20) | int(11) |', $output, 'acquire'); + $this->assertContains('| | [utf8] [utf8_general_ci] | [ascii] [ascii_general_ci] | |', $output, 'acquire'); + + // Reconnect to MySQL. + StaticDataLayer::disconnect(); + StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + AuditDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + } + + //-------------------------------------------------------------------------------------------------------------------- + private function runAudit() + { + $application = new Application(); + $application->add(new AuditCommand()); + + /** @var AuditCommand $command */ + $command = $application->find('audit'); + $command->setRewriteConfigFile(true); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName(), + 'config file' => __DIR__.'/config/audit.json']); + + // Reconnect to MySQL. + StaticDataLayer::disconnect(); + StaticDataLayer::connect('localhost', 'test', 'test', self::$auditSchema); + AuditDataLayer::connect('localhost', 'test', 'test', self::$auditSchema); + } + + //-------------------------------------------------------------------------------------------------------------------- +} + +//---------------------------------------------------------------------------------------------------------------------- diff --git a/test/MySql/DiffCommand/CharacterSetName/config/audit.json b/test/MySql/DiffCommand/CharacterSetName/config/audit.json new file mode 100755 index 0000000..759435b --- /dev/null +++ b/test/MySql/DiffCommand/CharacterSetName/config/audit.json @@ -0,0 +1,23 @@ +{ + "database": { + "host": "localhost", + "user": "test", + "password": "test", + "data_schema": "test_data", + "audit_schema": "test_audit" + }, + "metadata": "audit_metadata.json", + "tables": { + "TABLE1": { + "audit": true, + "skip": null, + "alias": "t1" + } + }, + "audit_columns": [ + + ], + "additional_sql": [ + + ] +} \ No newline at end of file diff --git a/test/MySql/DiffCommand/CharacterSetName/config/audit_metadata.json b/test/MySql/DiffCommand/CharacterSetName/config/audit_metadata.json new file mode 100755 index 0000000..1b7cc90 --- /dev/null +++ b/test/MySql/DiffCommand/CharacterSetName/config/audit_metadata.json @@ -0,0 +1,19 @@ +{ + "TABLE1": [ + { + "column_name": "c1", + "column_type": "tinyint(4)", + "is_nullable": "YES" + }, + { + "column_name": "c2", + "column_type": "smallint(6)", + "is_nullable": "YES" + }, + { + "column_name": "c4", + "column_type": "int(11)", + "is_nullable": "YES" + } + ] +} \ No newline at end of file diff --git a/test/MySql/DiffCommand/CharacterSetName/config/change_charset.sql b/test/MySql/DiffCommand/CharacterSetName/config/change_charset.sql new file mode 100755 index 0000000..082fe07 --- /dev/null +++ b/test/MySql/DiffCommand/CharacterSetName/config/change_charset.sql @@ -0,0 +1 @@ +ALTER TABLE `TABLE1` MODIFY c4 VARCHAR(20) CHARACTER SET ascii; \ No newline at end of file diff --git a/test/MySql/DiffCommand/CharacterSetName/config/setup.sql b/test/MySql/DiffCommand/CharacterSetName/config/setup.sql new file mode 100755 index 0000000..83d66af --- /dev/null +++ b/test/MySql/DiffCommand/CharacterSetName/config/setup.sql @@ -0,0 +1,6 @@ +CREATE TABLE `TABLE1` ( + c1 tinyint, + c2 smallint, + c4 varchar(20) +); + diff --git a/test/MySql/DiffCommand/DiffTypeConfigAudit/DiffTypeConfigAuditTest.php b/test/MySql/DiffCommand/DiffTypeConfigAudit/DiffTypeConfigAuditTest.php new file mode 100755 index 0000000..0fce190 --- /dev/null +++ b/test/MySql/DiffCommand/DiffTypeConfigAudit/DiffTypeConfigAuditTest.php @@ -0,0 +1,90 @@ +runAudit(); + + // Create new column. + StaticDataLayer::multiQuery(file_get_contents(__DIR__.'/config/change_column_type.sql')); + + $this->runDiff(); + } + + //-------------------------------------------------------------------------------------------------------------------- + private function runDiff() + { + $application = new Application(); + $application->add(new DiffCommand()); + + /** @var DiffCommand $command */ + $command = $application->find('diff'); + $command->setRewriteConfigFile(false); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName(), + 'config file' => __DIR__.'/config/audit.json']); + + $output = $commandTester->getDisplay(); + $this->assertContains('| c4 | int(11) | varchar(20) | int(11) |', $output, 'acquire'); + $this->assertContains('| | | [utf8] [utf8_general_ci] | |', $output, 'acquire'); + + // Reconnect to MySQL. + StaticDataLayer::disconnect(); + StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + AuditDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + } + + //-------------------------------------------------------------------------------------------------------------------- + private function runAudit() + { + $application = new Application(); + $application->add(new AuditCommand()); + + /** @var AuditCommand $command */ + $command = $application->find('audit'); + $command->setRewriteConfigFile(false); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName(), + 'config file' => __DIR__.'/config/audit.json']); + + // Reconnect to MySQL. + StaticDataLayer::disconnect(); + StaticDataLayer::connect('localhost', 'test', 'test', self::$auditSchema); + AuditDataLayer::connect('localhost', 'test', 'test', self::$auditSchema); + } + + //-------------------------------------------------------------------------------------------------------------------- +} + +//---------------------------------------------------------------------------------------------------------------------- diff --git a/test/MySql/DiffCommand/DiffTypeConfigAudit/config/audit.json b/test/MySql/DiffCommand/DiffTypeConfigAudit/config/audit.json new file mode 100755 index 0000000..759435b --- /dev/null +++ b/test/MySql/DiffCommand/DiffTypeConfigAudit/config/audit.json @@ -0,0 +1,23 @@ +{ + "database": { + "host": "localhost", + "user": "test", + "password": "test", + "data_schema": "test_data", + "audit_schema": "test_audit" + }, + "metadata": "audit_metadata.json", + "tables": { + "TABLE1": { + "audit": true, + "skip": null, + "alias": "t1" + } + }, + "audit_columns": [ + + ], + "additional_sql": [ + + ] +} \ No newline at end of file diff --git a/test/MySql/DiffCommand/DiffTypeConfigAudit/config/audit_metadata.json b/test/MySql/DiffCommand/DiffTypeConfigAudit/config/audit_metadata.json new file mode 100755 index 0000000..1b7cc90 --- /dev/null +++ b/test/MySql/DiffCommand/DiffTypeConfigAudit/config/audit_metadata.json @@ -0,0 +1,19 @@ +{ + "TABLE1": [ + { + "column_name": "c1", + "column_type": "tinyint(4)", + "is_nullable": "YES" + }, + { + "column_name": "c2", + "column_type": "smallint(6)", + "is_nullable": "YES" + }, + { + "column_name": "c4", + "column_type": "int(11)", + "is_nullable": "YES" + } + ] +} \ No newline at end of file diff --git a/test/MySql/DiffCommand/DiffTypeConfigAudit/config/change_column_type.sql b/test/MySql/DiffCommand/DiffTypeConfigAudit/config/change_column_type.sql new file mode 100755 index 0000000..9cab570 --- /dev/null +++ b/test/MySql/DiffCommand/DiffTypeConfigAudit/config/change_column_type.sql @@ -0,0 +1 @@ +ALTER TABLE `TABLE1` MODIFY c4 VARCHAR(20) CHARACTER SET utf8; \ No newline at end of file diff --git a/test/MySql/DiffCommand/DiffTypeConfigAudit/config/setup.sql b/test/MySql/DiffCommand/DiffTypeConfigAudit/config/setup.sql new file mode 100755 index 0000000..efdd272 --- /dev/null +++ b/test/MySql/DiffCommand/DiffTypeConfigAudit/config/setup.sql @@ -0,0 +1,6 @@ +CREATE TABLE `TABLE1` ( + c1 tinyint, + c2 smallint, + c4 int +); + diff --git a/test/MySql/DiffCommand/NewColumnAuditTable/NewColumnAuditTableTest.php b/test/MySql/DiffCommand/NewColumnAuditTable/NewColumnAuditTableTest.php new file mode 100755 index 0000000..9100382 --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnAuditTable/NewColumnAuditTableTest.php @@ -0,0 +1,89 @@ +runAudit(); + + // Create new column. + StaticDataLayer::multiQuery(file_get_contents(__DIR__.'/config/create_new_column.sql')); + + $this->runDiff(); + } + + //-------------------------------------------------------------------------------------------------------------------- + private function runDiff() + { + $application = new Application(); + $application->add(new DiffCommand()); + + /** @var DiffCommand $command */ + $command = $application->find('diff'); + $command->setRewriteConfigFile(false); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName(), + 'config file' => __DIR__.'/config/audit.json']); + + $output = $commandTester->getDisplay(); + $this->assertContains('| c3 | mediumint(9) | | |', $output, 'acquire'); + + // Reconnect to MySQL. + StaticDataLayer::disconnect(); + StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + AuditDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + } + + //-------------------------------------------------------------------------------------------------------------------- + private function runAudit() + { + $application = new Application(); + $application->add(new AuditCommand()); + + /** @var AuditCommand $command */ + $command = $application->find('audit'); + $command->setRewriteConfigFile(true); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName(), + 'config file' => __DIR__.'/config/audit.json']); + + // Reconnect to MySQL. + StaticDataLayer::disconnect(); + StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + AuditDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + } + + //-------------------------------------------------------------------------------------------------------------------- +} + +//---------------------------------------------------------------------------------------------------------------------- diff --git a/test/MySql/DiffCommand/NewColumnAuditTable/config/audit.json b/test/MySql/DiffCommand/NewColumnAuditTable/config/audit.json new file mode 100755 index 0000000..759435b --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnAuditTable/config/audit.json @@ -0,0 +1,23 @@ +{ + "database": { + "host": "localhost", + "user": "test", + "password": "test", + "data_schema": "test_data", + "audit_schema": "test_audit" + }, + "metadata": "audit_metadata.json", + "tables": { + "TABLE1": { + "audit": true, + "skip": null, + "alias": "t1" + } + }, + "audit_columns": [ + + ], + "additional_sql": [ + + ] +} \ No newline at end of file diff --git a/test/MySql/DiffCommand/NewColumnAuditTable/config/audit_metadata.json b/test/MySql/DiffCommand/NewColumnAuditTable/config/audit_metadata.json new file mode 100755 index 0000000..1b7cc90 --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnAuditTable/config/audit_metadata.json @@ -0,0 +1,19 @@ +{ + "TABLE1": [ + { + "column_name": "c1", + "column_type": "tinyint(4)", + "is_nullable": "YES" + }, + { + "column_name": "c2", + "column_type": "smallint(6)", + "is_nullable": "YES" + }, + { + "column_name": "c4", + "column_type": "int(11)", + "is_nullable": "YES" + } + ] +} \ No newline at end of file diff --git a/test/MySql/DiffCommand/NewColumnAuditTable/config/create_new_column.sql b/test/MySql/DiffCommand/NewColumnAuditTable/config/create_new_column.sql new file mode 100755 index 0000000..61142b8 --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnAuditTable/config/create_new_column.sql @@ -0,0 +1 @@ +alter table `TABLE1` add column `c3` mediumint after `c2`; \ No newline at end of file diff --git a/test/MySql/DiffCommand/NewColumnAuditTable/config/setup.sql b/test/MySql/DiffCommand/NewColumnAuditTable/config/setup.sql new file mode 100755 index 0000000..efdd272 --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnAuditTable/config/setup.sql @@ -0,0 +1,6 @@ +CREATE TABLE `TABLE1` ( + c1 tinyint, + c2 smallint, + c4 int +); + diff --git a/test/MySql/DiffCommand/NewColumnDataTable/NewColumnDataTableTest.php b/test/MySql/DiffCommand/NewColumnDataTable/NewColumnDataTableTest.php new file mode 100755 index 0000000..085a813 --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnDataTable/NewColumnDataTableTest.php @@ -0,0 +1,89 @@ +runAudit(); + + // Create new column. + StaticDataLayer::multiQuery(file_get_contents(__DIR__.'/config/create_new_column.sql')); + + $this->runDiff(); + } + + //-------------------------------------------------------------------------------------------------------------------- + private function runDiff() + { + $application = new Application(); + $application->add(new DiffCommand()); + + /** @var DiffCommand $command */ + $command = $application->find('diff'); + $command->setRewriteConfigFile(false); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName(), + 'config file' => __DIR__.'/config/audit.json']); + + $output = $commandTester->getDisplay(); + $this->assertContains('| c3 | | mediumint(9) | |', $output, 'acquire'); + + // Reconnect to MySQL. + StaticDataLayer::disconnect(); + StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + AuditDataLayer::connect('localhost', 'test', 'test', self::$dataSchema); + } + + //-------------------------------------------------------------------------------------------------------------------- + private function runAudit() + { + $application = new Application(); + $application->add(new AuditCommand()); + + /** @var AuditCommand $command */ + $command = $application->find('audit'); + $command->setRewriteConfigFile(true); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName(), + 'config file' => __DIR__.'/config/audit.json']); + + // Reconnect to MySQL. + StaticDataLayer::disconnect(); + StaticDataLayer::connect('localhost', 'test', 'test', self::$auditSchema); + AuditDataLayer::connect('localhost', 'test', 'test', self::$auditSchema); + } + + //-------------------------------------------------------------------------------------------------------------------- +} + +//---------------------------------------------------------------------------------------------------------------------- diff --git a/test/MySql/DiffCommand/NewColumnDataTable/config/audit.json b/test/MySql/DiffCommand/NewColumnDataTable/config/audit.json new file mode 100644 index 0000000..759435b --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnDataTable/config/audit.json @@ -0,0 +1,23 @@ +{ + "database": { + "host": "localhost", + "user": "test", + "password": "test", + "data_schema": "test_data", + "audit_schema": "test_audit" + }, + "metadata": "audit_metadata.json", + "tables": { + "TABLE1": { + "audit": true, + "skip": null, + "alias": "t1" + } + }, + "audit_columns": [ + + ], + "additional_sql": [ + + ] +} \ No newline at end of file diff --git a/test/MySql/DiffCommand/NewColumnDataTable/config/audit_metadata.json b/test/MySql/DiffCommand/NewColumnDataTable/config/audit_metadata.json new file mode 100644 index 0000000..1b7cc90 --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnDataTable/config/audit_metadata.json @@ -0,0 +1,19 @@ +{ + "TABLE1": [ + { + "column_name": "c1", + "column_type": "tinyint(4)", + "is_nullable": "YES" + }, + { + "column_name": "c2", + "column_type": "smallint(6)", + "is_nullable": "YES" + }, + { + "column_name": "c4", + "column_type": "int(11)", + "is_nullable": "YES" + } + ] +} \ No newline at end of file diff --git a/test/MySql/DiffCommand/NewColumnDataTable/config/create_new_column.sql b/test/MySql/DiffCommand/NewColumnDataTable/config/create_new_column.sql new file mode 100755 index 0000000..61142b8 --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnDataTable/config/create_new_column.sql @@ -0,0 +1 @@ +alter table `TABLE1` add column `c3` mediumint after `c2`; \ No newline at end of file diff --git a/test/MySql/DiffCommand/NewColumnDataTable/config/setup.sql b/test/MySql/DiffCommand/NewColumnDataTable/config/setup.sql new file mode 100755 index 0000000..efdd272 --- /dev/null +++ b/test/MySql/DiffCommand/NewColumnDataTable/config/setup.sql @@ -0,0 +1,6 @@ +CREATE TABLE `TABLE1` ( + c1 tinyint, + c2 smallint, + c4 int +); +