Unverified Commit 0152fbf4 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3456 from garret-gunter/master

Compare type class when comparing columns.
parents f9e00b6b ccde56fe
...@@ -12,6 +12,7 @@ use function array_shift; ...@@ -12,6 +12,7 @@ use function array_shift;
use function array_unique; use function array_unique;
use function assert; use function assert;
use function count; use function count;
use function get_class;
use function strtolower; use function strtolower;
/** /**
...@@ -421,7 +422,11 @@ class Comparator ...@@ -421,7 +422,11 @@ class Comparator
$changedProperties = []; $changedProperties = [];
foreach (['type', 'notnull', 'unsigned', 'autoincrement'] as $property) { if (get_class($properties1['type']) !== get_class($properties2['type'])) {
$changedProperties[] = 'type';
}
foreach (['notnull', 'unsigned', 'autoincrement'] as $property) {
if ($properties1[$property] === $properties2[$property]) { if ($properties1[$property] === $properties2[$property]) {
continue; continue;
} }
......
...@@ -16,6 +16,7 @@ use Doctrine\DBAL\Schema\TableDiff; ...@@ -16,6 +16,7 @@ use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use function array_keys; use function array_keys;
use function get_class;
class ComparatorTest extends TestCase class ComparatorTest extends TestCase
{ {
...@@ -193,6 +194,36 @@ class ComparatorTest extends TestCase ...@@ -193,6 +194,36 @@ class ComparatorTest extends TestCase
self::assertEquals([], $c->diffColumn($column1, $column1)); self::assertEquals([], $c->diffColumn($column1, $column1));
} }
public function testCompareColumnsMultipleTypeInstances() : void
{
$integerType1 = Type::getType('integer');
Type::overrideType('integer', get_class($integerType1));
$integerType2 = Type::getType('integer');
$column1 = new Column('integerfield1', $integerType1);
$column2 = new Column('integerfield1', $integerType2);
$c = new Comparator();
self::assertEquals([], $c->diffColumn($column1, $column2));
}
public function testCompareColumnsOverriddenType() : void
{
$oldStringInstance = Type::getType('string');
$integerType = Type::getType('integer');
Type::overrideType('string', get_class($integerType));
$overriddenStringType = Type::getType('string');
Type::overrideType('string', get_class($oldStringInstance));
$column1 = new Column('integerfield1', $integerType);
$column2 = new Column('integerfield1', $overriddenStringType);
$c = new Comparator();
self::assertEquals([], $c->diffColumn($column1, $column2));
}
public function testCompareChangedColumnsChangeCustomSchemaOption() : void public function testCompareChangedColumnsChangeCustomSchemaOption() : void
{ {
$column1 = new Column('charfield1', Type::getType('string')); $column1 = new Column('charfield1', Type::getType('string'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment