Commit d6317d35 authored by Steve Müller's avatar Steve Müller

preserve quotation of old column name in ColumnDiff

fixes #1206
parent 50f4482f
...@@ -77,6 +77,8 @@ class ColumnDiff ...@@ -77,6 +77,8 @@ class ColumnDiff
*/ */
public function getOldColumnName() public function getOldColumnName()
{ {
return new Identifier($this->oldColumnName); $quote = $this->fromColumn && $this->fromColumn->isQuoted();
return new Identifier($this->oldColumnName, $quote);
} }
} }
...@@ -35,9 +35,14 @@ class Identifier extends AbstractAsset ...@@ -35,9 +35,14 @@ class Identifier extends AbstractAsset
* Constructor. * Constructor.
* *
* @param string $identifier Identifier name to wrap. * @param string $identifier Identifier name to wrap.
* @param bool $quote Whether to force quoting the given identifier.
*/ */
public function __construct($identifier) public function __construct($identifier, $quote = false)
{ {
$this->_setName($identifier); $this->_setName($identifier);
if ($quote && ! $this->_quoted) {
$this->_setName('"' . $this->getName() . '"');
}
} }
} }
<?php
namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Types\Type;
class ColumnDiffTest extends \PHPUnit_Framework_TestCase
{
/**
* @group DBAL-1255
*/
public function testPreservesOldColumnNameQuotation()
{
$fromColumn = new Column('"foo"', Type::getType(Type::INTEGER));
$toColumn = new Column('bar', Type::getType(Type::INTEGER));
$columnDiff = new ColumnDiff('"foo"', $toColumn, array());
$this->assertTrue($columnDiff->getOldColumnName()->isQuoted());
$columnDiff = new ColumnDiff('"foo"', $toColumn, array(), $fromColumn);
$this->assertTrue($columnDiff->getOldColumnName()->isQuoted());
$columnDiff = new ColumnDiff('foo', $toColumn, array(), $fromColumn);
$this->assertTrue($columnDiff->getOldColumnName()->isQuoted());
}
}
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