Skip to content

Commit

Permalink
doctrine#2930 Added diff length for TextType
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Boiko committed Dec 12, 2017
1 parent a4d7acd commit cc272db
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Doctrine/DBAL/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ public function diffColumn(Column $column1, Column $column2)
$changedProperties[] = 'default';
}

if (($properties1['type'] instanceof Types\StringType && ! $properties1['type'] instanceof Types\GuidType) ||
if ((($properties1['type'] instanceof Types\TextType || $properties1['type'] instanceof Types\StringType) &&
! $properties1['type'] instanceof Types\GuidType) ||
$properties1['type'] instanceof Types\BinaryType
) {
// check if value of length is set at all, default value assumed otherwise.
Expand Down
50 changes: 50 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1276,4 +1276,54 @@ public function testForeignKeyRemovalWithRenamedLocalColumn()
self::assertCount(1, $actual->changedTables['table2']->addedForeignKeys, "FK to table3 should be added.");
self::assertEquals("table3", $actual->changedTables['table2']->addedForeignKeys[0]->getForeignTableName());
}

/**
* @group DBAL-2930
*/
public function testDiffLengthStringColumn()
{
$oldSchema = new Schema();

$tableFoo = $oldSchema->createTable('foo');
$tableFoo->addColumn('string_col', 'string', array('length' => 255));

$newSchema = new Schema();
$table = $newSchema->createTable('foo');
$table->addColumn('string_col', 'string', array('length' => 1000));

$expected = new SchemaDiff();
$expected->fromSchema = $oldSchema;
$tableDiff = $expected->changedTables['foo'] = new TableDiff('foo');
$tableDiff->fromTable = $tableFoo;
$columnDiff = $tableDiff->changedColumns['string_col'] = new ColumnDiff('string_col', $table->getColumn('string_col'));
$columnDiff->fromColumn = $tableFoo->getColumn('string_col');
$columnDiff->changedProperties = array('length');

self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema));
}

/**
* @group DBAL-2930
*/
public function testDiffLengthTextColumn()
{
$oldSchema = new Schema();

$tableFoo = $oldSchema->createTable('foo');
$tableFoo->addColumn('text_col', 'text', array('length' => 1000));

$newSchema = new Schema();
$table = $newSchema->createTable('foo');
$table->addColumn('text_col', 'text', array('length' => 16777215));

$expected = new SchemaDiff();
$expected->fromSchema = $oldSchema;
$tableDiff = $expected->changedTables['foo'] = new TableDiff('foo');
$tableDiff->fromTable = $tableFoo;
$columnDiff = $tableDiff->changedColumns['text_col'] = new ColumnDiff('text_col', $table->getColumn('text_col'));
$columnDiff->fromColumn = $tableFoo->getColumn('text_col');
$columnDiff->changedProperties = array('length');

self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema));
}
}

0 comments on commit cc272db

Please sign in to comment.