Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare type class when comparing columns. #3456

Merged
merged 1 commit into from
Jun 17, 2019
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
7 changes: 6 additions & 1 deletion lib/Doctrine/DBAL/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use function array_unique;
use function assert;
use function count;
use function get_class;
use function strtolower;

/**
Expand Down Expand Up @@ -421,7 +422,11 @@ public function diffColumn(Column $column1, Column $column2)

$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]) {
continue;
}
Expand Down
31 changes: 31 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\TestCase;
use function array_keys;
use function get_class;

class ComparatorTest extends TestCase
{
Expand Down Expand Up @@ -193,6 +194,36 @@ public function testCompareChangedColumnsChangeType() : void
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
{
$column1 = new Column('charfield1', Type::getType('string'));
Expand Down