Skip to content

Commit

Permalink
Added unit test for changing column lengths
Browse files Browse the repository at this point in the history
Unit tests currently only cover SQLite, MySQL and PostgreSQL.

Tests for other platforms have been marked as incomplete.
  • Loading branch information
PVince81 committed Jul 22, 2014
1 parent f8c1d77 commit b4f2b77
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,20 @@ protected function getQuotedAlterTableRenameColumnSQL()
"CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'"
);
}

/**
* {@inheritdoc}
*/
protected function getQuotedAlterTableChangeColumnLengthSQL()
{
return array(
"ALTER TABLE mytable " .
"CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " .
"CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " .
"CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " .
"CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " .
"CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " .
"CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'"
);
}
}
42 changes: 42 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,48 @@ public function testQuotesAlterTableRenameColumn()
*/
abstract protected function getQuotedAlterTableRenameColumnSQL();

/**
* @group DBAL-835
*/
public function testQuotesAlterTableChangeColumnLength()
{
$fromTable = new Table('mytable');

$fromTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 10));
$fromTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 10));
$fromTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 10));

$fromTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 10));
$fromTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 10));
$fromTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 10));

$toTable = new Table('mytable');

$toTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 255));
$toTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 255));
$toTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 255));

$toTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 255));
$toTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 255));
$toTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 255));

$comparator = new Comparator();

$this->assertEquals(
$this->getQuotedAlterTableChangeColumnLengthSQL(),
$this->_platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable))
);
}

/**
* Returns SQL statements for {@link testQuotesAlterTableChangeColumnLength}.
*
* @return array
*
* @group DBAL-835
*/
abstract protected function getQuotedAlterTableChangeColumnLengthSQL();

/**
* @group DBAL-807
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,21 @@ protected function getQuotedAlterTableRenameColumnSQL()
);
}

/**
* {@inheritdoc}
*/
protected function getQuotedAlterTableChangeColumnLengthSQL()
{
return array(
'ALTER TABLE mytable ALTER unquoted1 TYPE VARCHAR(255)',
'ALTER TABLE mytable ALTER unquoted2 TYPE VARCHAR(255)',
'ALTER TABLE mytable ALTER unquoted3 TYPE VARCHAR(255)',
'ALTER TABLE mytable ALTER "create" TYPE VARCHAR(255)',
'ALTER TABLE mytable ALTER "table" TYPE VARCHAR(255)',
'ALTER TABLE mytable ALTER "select" TYPE VARCHAR(255)',
);
}

/**
* @group DBAL-807
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,14 @@ protected function getQuotedAlterTableRenameColumnSQL()
);
}

/**
* {@inheritdoc}
*/
protected function getQuotedAlterTableChangeColumnLengthSQL()
{
$this->markTestIncomplete('Not implemented yet');
}

/**
* @group DBAL-807
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ protected function getQuotedAlterTableRenameColumnSQL()
);
}

/**
* {@inheritdoc}
*/
protected function getQuotedAlterTableChangeColumnLengthSQL()
{
$this->markTestIncomplete('Not implemented yet');
}

/**
* @group DBAL-807
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,14 @@ protected function getQuotedAlterTableRenameColumnSQL()
);
}

/**
* {@inheritdoc}
*/
protected function getQuotedAlterTableChangeColumnLengthSQL()
{
$this->markTestIncomplete('Not implemented yet');
}

/**
* @group DBAL-807
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,14 @@ protected function getQuotedAlterTableRenameColumnSQL()
);
}

/**
* {@inheritdoc}
*/
protected function getQuotedAlterTableChangeColumnLengthSQL()
{
$this->markTestIncomplete('Not implemented yet');
}

/**
* @group DBAL-807
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,20 @@ protected function getQuotedAlterTableRenameColumnSQL()
'INSERT INTO mytable (unquoted, "where", "foo", reserved_keyword, "from", "bar", quoted, "and", "baz") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM __temp__mytable',
'DROP TABLE __temp__mytable',
);
}

/**
* {@inheritdoc}
*/
protected function getQuotedAlterTableChangeColumnLengthSQL()
{
return array(
'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM mytable',
'DROP TABLE mytable',
'CREATE TABLE mytable (unquoted1 VARCHAR(255) NOT NULL, unquoted2 VARCHAR(255) NOT NULL, unquoted3 VARCHAR(255) NOT NULL, "create" VARCHAR(255) NOT NULL, "table" VARCHAR(255) NOT NULL, "select" VARCHAR(255) NOT NULL)',
'INSERT INTO mytable (unquoted1, unquoted2, unquoted3, "create", "table", "select") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM __temp__mytable',
'DROP TABLE __temp__mytable',
);
}

/**
Expand Down

0 comments on commit b4f2b77

Please sign in to comment.