Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MySql/AuditDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private function resolveCanonicalAuditColumns()
{
if (empty($this->config['audit_columns']))
{
$this->auditColumnsMetadata = new TableColumnsMetadata();
$this->auditColumnsMetadata = [];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
//----------------------------------------------------------------------------------------------------------------------
namespace SetBased\Audit\Test\MySql\AbcFramework;
namespace SetBased\Audit\Test\MySql\AbcFramework\AuditCommand;

use SetBased\Audit\MySql\Command\AuditCommand;
use SetBased\Audit\Test\MySql\AuditTestCase;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
//----------------------------------------------------------------------------------------------------------------------
namespace SetBased\Audit\Test\MySql\LockTable;
namespace SetBased\Audit\Test\MySql\AuditCommand\LockTable;

use SetBased\Stratum\MySql\StaticDataLayer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
//----------------------------------------------------------------------------------------------------------------------
namespace SetBased\Audit\Test\MySql\LockTable;
namespace SetBased\Audit\Test\MySql\AuditCommand\LockTable;

use SetBased\Stratum\MySql\StaticDataLayer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
//----------------------------------------------------------------------------------------------------------------------
namespace SetBased\Audit\Test\MySql\LockTable;
namespace SetBased\Audit\Test\MySql\AuditCommand\LockTable;

use SetBased\Stratum\MySql\StaticDataLayer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
//----------------------------------------------------------------------------------------------------------------------
namespace SetBased\Audit\Test\MySql\LockTable;
namespace SetBased\Audit\Test\MySql\AuditCommand\LockTable;

use SetBased\Audit\MySql\Command\AuditCommand;
use SetBased\Audit\Test\MySql\AuditTestCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/usr/bin/env php
<?php
//----------------------------------------------------------------------------------------------------------------------

use SetBased\Affirm\ErrorHandler;
use SetBased\Stratum\MySql\StaticDataLayer;

//----------------------------------------------------------------------------------------------------------------------
$files = [__DIR__.'/../vendor/autoload.php',
__DIR__.'/../../vendor/autoload.php',
__DIR__.'/../../../vendor/autoload.php',
__DIR__.'/../../../../vendor/autoload.php'];
__DIR__.'/../../../../vendor/autoload.php',
__DIR__.'/../../../../../vendor/autoload.php'];

foreach ($files as $file)
{
Expand Down
90 changes: 90 additions & 0 deletions test/MySql/DiffCommand/CharacterSetName/CharacterSetNameTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
//----------------------------------------------------------------------------------------------------------------------
namespace SetBased\Audit\Test\MySql\DiffCommand\CharacterSetName;

use SetBased\Audit\MySql\AuditDataLayer;
use SetBased\Audit\MySql\Command\AuditCommand;
use SetBased\Audit\MySql\Command\DiffCommand;
use SetBased\Audit\Test\MySql\AuditTestCase;
use SetBased\Stratum\MySql\StaticDataLayer;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

//----------------------------------------------------------------------------------------------------------------------
/**
* Tests for running diff with a new table column in data table.
*/
class DiffCharacterSetNameTest extends AuditTestCase
{
//--------------------------------------------------------------------------------------------------------------------
/**
* {@inheritdoc}
*/
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();

StaticDataLayer::disconnect();
StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);

StaticDataLayer::multiQuery(file_get_contents(__DIR__.'/config/setup.sql'));
}

//--------------------------------------------------------------------------------------------------------------------
public function test01()
{
// Run audit.
$this->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);
}

//--------------------------------------------------------------------------------------------------------------------
}

//----------------------------------------------------------------------------------------------------------------------
23 changes: 23 additions & 0 deletions test/MySql/DiffCommand/CharacterSetName/config/audit.json
Original file line number Diff line number Diff line change
@@ -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": [

]
}
19 changes: 19 additions & 0 deletions test/MySql/DiffCommand/CharacterSetName/config/audit_metadata.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `TABLE1` MODIFY c4 VARCHAR(20) CHARACTER SET ascii;
6 changes: 6 additions & 0 deletions test/MySql/DiffCommand/CharacterSetName/config/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE `TABLE1` (
c1 tinyint,
c2 smallint,
c4 varchar(20)
);

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
//----------------------------------------------------------------------------------------------------------------------
namespace SetBased\Audit\Test\MySql\DiffCommand\DiffTypeConfigAudit;

use SetBased\Audit\MySql\AuditDataLayer;
use SetBased\Audit\MySql\Command\AuditCommand;
use SetBased\Audit\MySql\Command\DiffCommand;
use SetBased\Audit\Test\MySql\AuditTestCase;
use SetBased\Stratum\MySql\StaticDataLayer;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

//----------------------------------------------------------------------------------------------------------------------
/**
* Tests for running diff with a new table column in audit table.
*/
class DiffTypeConfigAuditTest extends AuditTestCase
{
//--------------------------------------------------------------------------------------------------------------------
/**
* {@inheritdoc}
*/
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();

StaticDataLayer::disconnect();
StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);

StaticDataLayer::multiQuery(file_get_contents(__DIR__.'/config/setup.sql'));
}

//--------------------------------------------------------------------------------------------------------------------
public function test01()
{
// Run audit.
$this->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);
}

//--------------------------------------------------------------------------------------------------------------------
}

//----------------------------------------------------------------------------------------------------------------------
23 changes: 23 additions & 0 deletions test/MySql/DiffCommand/DiffTypeConfigAudit/config/audit.json
Original file line number Diff line number Diff line change
@@ -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": [

]
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `TABLE1` MODIFY c4 VARCHAR(20) CHARACTER SET utf8;
6 changes: 6 additions & 0 deletions test/MySql/DiffCommand/DiffTypeConfigAudit/config/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE `TABLE1` (
c1 tinyint,
c2 smallint,
c4 int
);

Loading