Skip to content

Commit 0152fbf

Browse files
authored
Merge pull request #3456 from garret-gunter/master
Compare type class when comparing columns.
2 parents f9e00b6 + ccde56f commit 0152fbf

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/Doctrine/DBAL/Schema/Comparator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use function array_unique;
1313
use function assert;
1414
use function count;
15+
use function get_class;
1516
use function strtolower;
1617

1718
/**
@@ -421,7 +422,11 @@ public function diffColumn(Column $column1, Column $column2)
421422

422423
$changedProperties = [];
423424

424-
foreach (['type', 'notnull', 'unsigned', 'autoincrement'] as $property) {
425+
if (get_class($properties1['type']) !== get_class($properties2['type'])) {
426+
$changedProperties[] = 'type';
427+
}
428+
429+
foreach (['notnull', 'unsigned', 'autoincrement'] as $property) {
425430
if ($properties1[$property] === $properties2[$property]) {
426431
continue;
427432
}

tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\DBAL\Types\Type;
1717
use PHPUnit\Framework\TestCase;
1818
use function array_keys;
19+
use function get_class;
1920

2021
class ComparatorTest extends TestCase
2122
{
@@ -193,6 +194,36 @@ public function testCompareChangedColumnsChangeType() : void
193194
self::assertEquals([], $c->diffColumn($column1, $column1));
194195
}
195196

197+
public function testCompareColumnsMultipleTypeInstances() : void
198+
{
199+
$integerType1 = Type::getType('integer');
200+
Type::overrideType('integer', get_class($integerType1));
201+
$integerType2 = Type::getType('integer');
202+
203+
$column1 = new Column('integerfield1', $integerType1);
204+
$column2 = new Column('integerfield1', $integerType2);
205+
206+
$c = new Comparator();
207+
self::assertEquals([], $c->diffColumn($column1, $column2));
208+
}
209+
210+
public function testCompareColumnsOverriddenType() : void
211+
{
212+
$oldStringInstance = Type::getType('string');
213+
$integerType = Type::getType('integer');
214+
215+
Type::overrideType('string', get_class($integerType));
216+
$overriddenStringType = Type::getType('string');
217+
218+
Type::overrideType('string', get_class($oldStringInstance));
219+
220+
$column1 = new Column('integerfield1', $integerType);
221+
$column2 = new Column('integerfield1', $overriddenStringType);
222+
223+
$c = new Comparator();
224+
self::assertEquals([], $c->diffColumn($column1, $column2));
225+
}
226+
196227
public function testCompareChangedColumnsChangeCustomSchemaOption() : void
197228
{
198229
$column1 = new Column('charfield1', Type::getType('string'));

0 commit comments

Comments
 (0)