Unverified Commit acb9d148 authored by Sergei Morozov's avatar Sergei Morozov

Merge pull request #3511 from morozov/column-type-hints

Added type hints to the Column class
parents 8d359773 eba7b78c
......@@ -7,7 +7,6 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Types\Type;
use const E_USER_DEPRECATED;
use function array_merge;
use function is_numeric;
use function method_exists;
use function sprintf;
use function trigger_error;
......@@ -21,9 +20,9 @@ class Column extends AbstractAsset
protected $_type;
/** @var int|null */
protected $_length = null;
protected $_length;
/** @var int */
/** @var int|null */
protected $_precision = 10;
/** @var int */
......@@ -38,8 +37,8 @@ class Column extends AbstractAsset
/** @var bool */
protected $_notnull = true;
/** @var string|null */
protected $_default = null;
/** @var mixed */
protected $_default;
/** @var bool */
protected $_autoincrement = false;
......@@ -48,10 +47,10 @@ class Column extends AbstractAsset
protected $_platformOptions = [];
/** @var string|null */
protected $_columnDefinition = null;
protected $_columnDefinition;
/** @var string|null */
protected $_comment = null;
protected $_comment;
/** @var mixed[] */
protected $_customSchemaOptions = [];
......@@ -59,22 +58,19 @@ class Column extends AbstractAsset
/**
* Creates a new Column.
*
* @param string $columnName
* @param mixed[] $options
*/
public function __construct($columnName, Type $type, array $options = [])
public function __construct(string $name, Type $type, array $options = [])
{
$this->_setName($columnName);
$this->_setName($name);
$this->setType($type);
$this->setOptions($options);
}
/**
* @param mixed[] $options
*
* @return Column
*/
public function setOptions(array $options)
public function setOptions(array $options) : self
{
foreach ($options as $name => $value) {
$method = 'set' . $name;
......@@ -94,106 +90,63 @@ class Column extends AbstractAsset
return $this;
}
/**
* @return Column
*/
public function setType(Type $type)
public function setType(Type $type) : self
{
$this->_type = $type;
return $this;
}
/**
* @param int|null $length
*
* @return Column
*/
public function setLength($length)
public function setLength(?int $length) : self
{
if ($length !== null) {
$this->_length = (int) $length;
} else {
$this->_length = null;
}
$this->_length = $length;
return $this;
}
/**
* @param int $precision
*
* @return Column
*/
public function setPrecision($precision)
public function setPrecision(?int $precision) : self
{
if (! is_numeric($precision)) {
$precision = 10; // defaults to 10 when no valid precision is given.
if ($precision === null) {
$precision = 10; // defaults to 10 when no precision is given.
}
$this->_precision = (int) $precision;
$this->_precision = $precision;
return $this;
}
/**
* @param int $scale
*
* @return Column
*/
public function setScale($scale)
public function setScale(int $scale) : self
{
if (! is_numeric($scale)) {
$scale = 0;
}
$this->_scale = (int) $scale;
$this->_scale = $scale;
return $this;
}
/**
* @param bool $unsigned
*
* @return Column
*/
public function setUnsigned($unsigned)
public function setUnsigned(bool $unsigned) : self
{
$this->_unsigned = (bool) $unsigned;
$this->_unsigned = $unsigned;
return $this;
}
/**
* @param bool $fixed
*
* @return Column
*/
public function setFixed($fixed)
public function setFixed(bool $fixed) : self
{
$this->_fixed = (bool) $fixed;
$this->_fixed = $fixed;
return $this;
}
/**
* @param bool $notnull
*
* @return Column
*/
public function setNotnull($notnull)
public function setNotnull(bool $notnull) : self
{
$this->_notnull = (bool) $notnull;
$this->_notnull = $notnull;
return $this;
}
/**
* @param mixed $default
*
* @return Column
*/
public function setDefault($default)
public function setDefault($default) : self
{
$this->_default = $default;
......@@ -202,10 +155,8 @@ class Column extends AbstractAsset
/**
* @param mixed[] $platformOptions
*
* @return Column
*/
public function setPlatformOptions(array $platformOptions)
public function setPlatformOptions(array $platformOptions) : self
{
$this->_platformOptions = $platformOptions;
......@@ -213,88 +164,59 @@ class Column extends AbstractAsset
}
/**
* @param string $name
* @param mixed $value
*
* @return Column
* @param mixed $value
*/
public function setPlatformOption($name, $value)
public function setPlatformOption(string $name, $value) : self
{
$this->_platformOptions[$name] = $value;
return $this;
}
/**
* @param string $value
*
* @return Column
*/
public function setColumnDefinition($value)
public function setColumnDefinition(string $value) : self
{
$this->_columnDefinition = $value;
return $this;
}
/**
* @return Type
*/
public function getType()
public function getType() : Type
{
return $this->_type;
}
/**
* @return int|null
*/
public function getLength()
public function getLength() : ?int
{
return $this->_length;
}
/**
* @return int
*/
public function getPrecision()
public function getPrecision() : ?int
{
return $this->_precision;
}
/**
* @return int
*/
public function getScale()
public function getScale() : ?int
{
return $this->_scale;
}
/**
* @return bool
*/
public function getUnsigned()
public function getUnsigned() : bool
{
return $this->_unsigned;
}
/**
* @return bool
*/
public function getFixed()
public function getFixed() : bool
{
return $this->_fixed;
}
/**
* @return bool
*/
public function getNotnull()
public function getNotnull() : bool
{
return $this->_notnull;
}
/**
* @return string|null
* @return mixed
*/
public function getDefault()
{
......@@ -304,118 +226,80 @@ class Column extends AbstractAsset
/**
* @return mixed[]
*/
public function getPlatformOptions()
public function getPlatformOptions() : array
{
return $this->_platformOptions;
}
/**
* @param string $name
*
* @return bool
*/
public function hasPlatformOption($name)
public function hasPlatformOption(string $name) : bool
{
return isset($this->_platformOptions[$name]);
}
/**
* @param string $name
*
* @return mixed
*/
public function getPlatformOption($name)
public function getPlatformOption(string $name)
{
return $this->_platformOptions[$name];
}
/**
* @return string|null
*/
public function getColumnDefinition()
public function getColumnDefinition() : ?string
{
return $this->_columnDefinition;
}
/**
* @return bool
*/
public function getAutoincrement()
public function getAutoincrement() : bool
{
return $this->_autoincrement;
}
/**
* @param bool $flag
*
* @return Column
*/
public function setAutoincrement($flag)
public function setAutoincrement(bool $flag) : self
{
$this->_autoincrement = $flag;
return $this;
}
/**
* @param string|null $comment
*
* @return Column
*/
public function setComment($comment)
public function setComment(?string $comment) : self
{
$this->_comment = $comment;
return $this;
}
/**
* @return string|null
*/
public function getComment()
public function getComment() : ?string
{
return $this->_comment;
}
/**
* @param string $name
* @param mixed $value
*
* @return Column
* @param mixed $value
*/
public function setCustomSchemaOption($name, $value)
public function setCustomSchemaOption(string $name, $value) : self
{
$this->_customSchemaOptions[$name] = $value;
return $this;
}
/**
* @param string $name
*
* @return bool
*/
public function hasCustomSchemaOption($name)
public function hasCustomSchemaOption(string $name) : bool
{
return isset($this->_customSchemaOptions[$name]);
}
/**
* @param string $name
*
* @return mixed
*/
public function getCustomSchemaOption($name)
public function getCustomSchemaOption(string $name)
{
return $this->_customSchemaOptions[$name];
}
/**
* @param mixed[] $customSchemaOptions
*
* @return Column
*/
public function setCustomSchemaOptions(array $customSchemaOptions)
public function setCustomSchemaOptions(array $customSchemaOptions) : self
{
$this->_customSchemaOptions = $customSchemaOptions;
......@@ -425,7 +309,7 @@ class Column extends AbstractAsset
/**
* @return mixed[]
*/
public function getCustomSchemaOptions()
public function getCustomSchemaOptions() : array
{
return $this->_customSchemaOptions;
}
......@@ -433,7 +317,7 @@ class Column extends AbstractAsset
/**
* @return mixed[]
*/
public function toArray()
public function toArray() : array
{
return array_merge([
'name' => $this->_name,
......
......@@ -47,12 +47,9 @@ class DB2SchemaManager extends AbstractSchemaManager
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
$length = null;
$fixed = null;
$scale = false;
$precision = false;
$default = null;
$length = $precision = $default = null;
$scale = 0;
$fixed = false;
if ($tableColumn['default'] !== null && $tableColumn['default'] !== 'NULL') {
$default = $tableColumn['default'];
......@@ -68,7 +65,6 @@ class DB2SchemaManager extends AbstractSchemaManager
switch (strtolower($tableColumn['typename'])) {
case 'varchar':
$length = $tableColumn['length'];
$fixed = false;
break;
case 'character':
$length = $tableColumn['length'];
......@@ -88,12 +84,10 @@ class DB2SchemaManager extends AbstractSchemaManager
$options = [
'length' => $length,
'unsigned' => false,
'fixed' => (bool) $fixed,
'fixed' => $fixed,
'default' => $default,
'autoincrement' => (bool) $tableColumn['autoincrement'],
'notnull' => (bool) ($tableColumn['nulls'] === 'N'),
'scale' => null,
'precision' => null,
'notnull' => $tableColumn['nulls'] === 'N',
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
? $tableColumn['comment']
: null,
......
......@@ -118,13 +118,13 @@ class MySqlSchemaManager extends AbstractSchemaManager
$length = $tableColumn['length'] ?? strtok('(), ');
$fixed = null;
$fixed = false;
if (! isset($tableColumn['name'])) {
$tableColumn['name'] = '';
}
$scale = null;
$scale = 0;
$precision = null;
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'])
......@@ -141,8 +141,8 @@ class MySqlSchemaManager extends AbstractSchemaManager
case 'numeric':
case 'decimal':
if (preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['type'], $match)) {
$precision = $match[1];
$scale = $match[2];
$precision = (int) $match[1];
$scale = (int) $match[2];
$length = null;
}
break;
......@@ -184,22 +184,17 @@ class MySqlSchemaManager extends AbstractSchemaManager
$options = [
'length' => $length !== null ? (int) $length : null,
'unsigned' => strpos($tableColumn['type'], 'unsigned') !== false,
'fixed' => (bool) $fixed,
'fixed' => $fixed,
'default' => $columnDefault,
'notnull' => $tableColumn['null'] !== 'YES',
'scale' => null,
'precision' => null,
'scale' => $scale,
'precision' => $precision,
'autoincrement' => strpos($tableColumn['extra'], 'auto_increment') !== false,
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
? $tableColumn['comment']
: null,
];
if ($scale !== null && $precision !== null) {
$options['scale'] = (int) $scale;
$options['precision'] = (int) $precision;
}
$column = new Column($tableColumn['field'], Type::getType($type), $options);
if (isset($tableColumn['characterset'])) {
......
......@@ -133,7 +133,9 @@ class OracleSchemaManager extends AbstractSchemaManager
}
}
$unsigned = $fixed = $precision = $scale = $length = null;
$length = $precision = null;
$scale = 0;
$fixed = false;
if (! isset($tableColumn['column_name'])) {
$tableColumn['column_name'] = '';
......@@ -182,20 +184,18 @@ class OracleSchemaManager extends AbstractSchemaManager
case 'varchar':
case 'varchar2':
case 'nvarchar2':
$length = $tableColumn['char_length'];
$fixed = false;
$length = (int) $tableColumn['char_length'];
break;
case 'char':
case 'nchar':
$length = $tableColumn['char_length'];
$length = (int) $tableColumn['char_length'];
$fixed = true;
break;
}
$options = [
'notnull' => (bool) ($tableColumn['nullable'] === 'N'),
'fixed' => (bool) $fixed,
'unsigned' => (bool) $unsigned,
'notnull' => $tableColumn['nullable'] === 'N',
'fixed' => $fixed,
'default' => $tableColumn['data_default'],
'length' => $length,
'precision' => $precision,
......
......@@ -20,7 +20,6 @@ use function explode;
use function implode;
use function in_array;
use function preg_match;
use function preg_replace;
use function sprintf;
use function str_replace;
use function strlen;
......@@ -316,10 +315,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
if (strtolower($tableColumn['type']) === 'varchar' || strtolower($tableColumn['type']) === 'bpchar') {
// get length from varchar definition
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $tableColumn['complete_type']);
$tableColumn['length'] = $length;
$length = null;
if (in_array(strtolower($tableColumn['type']), ['varchar', 'bpchar'], true)
&& preg_match('/\((\d*)\)/', $tableColumn['complete_type'], $matches)) {
$length = (int) $matches[1];
}
$matches = [];
......@@ -339,21 +339,22 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
}
}
$length = $tableColumn['length'] ?? null;
if ($length === '-1' && isset($tableColumn['atttypmod'])) {
if ($length === -1 && isset($tableColumn['atttypmod'])) {
$length = $tableColumn['atttypmod'] - 4;
}
if ((int) $length <= 0) {
$length = null;
}
$fixed = null;
$fixed = false;
if (! isset($tableColumn['name'])) {
$tableColumn['name'] = '';
}
$precision = null;
$scale = null;
$scale = 0;
$jsonb = null;
$dbType = strtolower($tableColumn['type']);
......@@ -401,10 +402,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case '_varchar':
case 'varchar':
$tableColumn['default'] = $this->parseDefaultExpression($tableColumn['default']);
$fixed = false;
break;
case 'interval':
$fixed = false;
break;
case 'char':
case 'bpchar':
......@@ -422,8 +419,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);
if (preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['complete_type'], $match)) {
$precision = $match[1];
$scale = $match[2];
$precision = (int) $match[1];
$scale = (int) $match[2];
$length = null;
}
break;
......
......@@ -70,16 +70,27 @@ class SQLServerSchemaManager extends AbstractSchemaManager
$dbType = strtok($tableColumn['type'], '(), ');
assert(is_string($dbType));
$fixed = null;
$length = (int) $tableColumn['length'];
$default = $tableColumn['default'];
$length = (int) $tableColumn['length'];
$precision = $default = null;
$scale = 0;
$fixed = false;
if (! isset($tableColumn['name'])) {
$tableColumn['name'] = '';
}
if ($default !== null) {
$default = $this->parseDefaultExpression($default);
if ($tableColumn['scale'] !== null) {
$scale = (int) $tableColumn['scale'];
}
if ($tableColumn['precision'] !== null) {
$precision = (int) $tableColumn['precision'];
}
if ($tableColumn['default'] !== null) {
$default = $this->parseDefaultExpression($tableColumn['default']);
}
switch ($dbType) {
......@@ -106,12 +117,11 @@ class SQLServerSchemaManager extends AbstractSchemaManager
$options = [
'length' => $length === 0 || ! in_array($type, ['text', 'string']) ? null : $length,
'unsigned' => false,
'fixed' => (bool) $fixed,
'fixed' => $fixed,
'default' => $default,
'notnull' => (bool) $tableColumn['notnull'],
'scale' => $tableColumn['scale'],
'precision' => $tableColumn['precision'],
'scale' => $scale,
'precision' => $precision,
'autoincrement' => (bool) $tableColumn['autoincrement'],
'comment' => $tableColumn['comment'] !== '' ? $tableColumn['comment'] : null,
];
......
......@@ -12,10 +12,9 @@ use Doctrine\DBAL\Types\TextType;
use Doctrine\DBAL\Types\Type;
use const CASE_LOWER;
use function array_change_key_case;
use function array_map;
use function array_reverse;
use function array_values;
use function explode;
use function count;
use function file_exists;
use function preg_match;
use function preg_match_all;
......@@ -300,23 +299,26 @@ class SqliteSchemaManager extends AbstractSchemaManager
*/
protected function _getPortableTableColumnDefinition($tableColumn)
{
$parts = explode('(', $tableColumn['type']);
$tableColumn['type'] = trim($parts[0]);
if (isset($parts[1])) {
$length = trim($parts[1], ')');
$tableColumn['length'] = $length;
}
preg_match('/^([^()]*)\\s*(\\(((\\d+)(,\\s*(\\d+))?)\\))?/', $tableColumn['type'], $matches);
$dbType = trim(strtolower($matches[1]));
$dbType = strtolower($tableColumn['type']);
$length = $tableColumn['length'] ?? null;
$unsigned = false;
$length = $precision = $unsigned = null;
$fixed = $unsigned = false;
$scale = 0;
if (count($matches) >= 6) {
$precision = (int) $matches[4];
$scale = (int) $matches[6];
} elseif (count($matches) >= 4) {
$length = (int) $matches[4];
}
if (strpos($dbType, ' unsigned') !== false) {
$dbType = str_replace(' unsigned', '', $dbType);
$unsigned = true;
}
$fixed = false;
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$default = $tableColumn['dflt_value'];
if ($default === 'NULL') {
......@@ -336,31 +338,13 @@ class SqliteSchemaManager extends AbstractSchemaManager
$tableColumn['name'] = '';
}
$precision = null;
$scale = null;
switch ($dbType) {
case 'char':
$fixed = true;
break;
case 'float':
case 'double':
case 'real':
case 'decimal':
case 'numeric':
if (isset($tableColumn['length'])) {
if (strpos($tableColumn['length'], ',') === false) {
$tableColumn['length'] .= ',0';
}
[$precision, $scale] = array_map('trim', explode(',', $tableColumn['length']));
}
$length = null;
break;
if ($dbType === 'char') {
$fixed = true;
}
$options = [
'length' => $length,
'unsigned' => (bool) $unsigned,
'unsigned' => $unsigned,
'fixed' => $fixed,
'notnull' => $notnull,
'default' => $default,
......
......@@ -164,10 +164,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
$table = new Table('sqlsrv_column_comment');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('comment_null', 'integer', ['comment' => null]);
$table->addColumn('comment_false', 'integer', ['comment' => false]);
$table->addColumn('comment_empty_string', 'integer', ['comment' => '']);
$table->addColumn('comment_integer_0', 'integer', ['comment' => 0]);
$table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]);
$table->addColumn('comment_string_0', 'integer', ['comment' => '0']);
$table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']);
$table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']);
......@@ -179,13 +176,10 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->schemaManager->createTable($table);
$columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment');
self::assertCount(12, $columns);
self::assertCount(9, $columns);
self::assertNull($columns['id']->getComment());
self::assertNull($columns['comment_null']->getComment());
self::assertNull($columns['comment_false']->getComment());
self::assertNull($columns['comment_empty_string']->getComment());
self::assertEquals('0', $columns['comment_integer_0']->getComment());
self::assertEquals('0', $columns['comment_float_0']->getComment());
self::assertEquals('0', $columns['comment_string_0']->getComment());
self::assertEquals('Doctrine 0wnz you!', $columns['comment']->getComment());
self::assertEquals('Doctrine 0wnz comments for explicitly quoted columns!', $columns['comment_quoted']->getComment());
......@@ -197,10 +191,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tableDiff->fromTable = $table;
$tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer'));
$tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), ['comment' => null]);
$tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), ['comment' => false]);
$tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']);
$tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), ['comment' => 0]);
$tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), ['comment' => 0.0]);
$tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), ['comment' => '0']);
$tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), ['comment' => 'Doctrine']);
$tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), ['comment' => 'rulez']);
......@@ -208,8 +199,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object'));
$tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), ['comment' => '666']);
$tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), ['comment' => 'Double for real!']);
// Add comment to non-commented column.
$tableDiff->changedColumns['id'] = new ColumnDiff(
'id',
......@@ -226,14 +215,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
new Column('comment_null', Type::getType('integer'), ['comment' => null])
);
// Add comment to false-commented column.
$tableDiff->changedColumns['comment_false'] = new ColumnDiff(
'comment_false',
new Column('comment_false', Type::getType('integer'), ['comment' => 'false']),
['comment'],
new Column('comment_false', Type::getType('integer'), ['comment' => false])
);
// Change type to custom type from empty string commented column.
$tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff(
'comment_empty_string',
......@@ -242,10 +223,10 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
new Column('comment_empty_string', Type::getType('integer'), ['comment' => ''])
);
// Change comment to false-comment from zero-string commented column.
// Change comment to empty comment from zero-string commented column.
$tableDiff->changedColumns['comment_string_0'] = new ColumnDiff(
'comment_string_0',
new Column('comment_string_0', Type::getType('integer'), ['comment' => false]),
new Column('comment_string_0', Type::getType('integer'), ['comment' => '']),
['comment'],
new Column('comment_string_0', Type::getType('integer'), ['comment' => '0'])
);
......@@ -290,17 +271,13 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
new Column('commented_type_with_comment', Type::getType('array'), ['comment' => 'Doctrine array type.'])
);
$tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]);
$this->schemaManager->alterTable($tableDiff);
$columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment');
self::assertCount(23, $columns);
self::assertCount(18, $columns);
self::assertEquals('primary', $columns['id']->getComment());
self::assertNull($columns['comment_null']->getComment());
self::assertEquals('false', $columns['comment_false']->getComment());
self::assertNull($columns['comment_empty_string']->getComment());
self::assertEquals('0', $columns['comment_double_0']->getComment());
self::assertNull($columns['comment_string_0']->getComment());
self::assertNull($columns['comment']->getComment());
self::assertEquals('Doctrine array.', $columns['comment_quoted']->getComment());
......@@ -309,10 +286,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertNull($columns['commented_type_with_comment']->getComment());
self::assertNull($columns['added_comment_none']->getComment());
self::assertNull($columns['added_comment_null']->getComment());
self::assertNull($columns['added_comment_false']->getComment());
self::assertNull($columns['added_comment_empty_string']->getComment());
self::assertEquals('0', $columns['added_comment_integer_0']->getComment());
self::assertEquals('0', $columns['added_comment_float_0']->getComment());
self::assertEquals('0', $columns['added_comment_string_0']->getComment());
self::assertEquals('Doctrine', $columns['added_comment']->getComment());
self::assertEquals('rulez', $columns['added_comment_quoted']->getComment());
......
......@@ -704,10 +704,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
$table = new Table('mytable');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('comment_null', 'integer', ['comment' => null]);
$table->addColumn('comment_false', 'integer', ['comment' => false]);
$table->addColumn('comment_empty_string', 'integer', ['comment' => '']);
$table->addColumn('comment_integer_0', 'integer', ['comment' => 0]);
$table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]);
$table->addColumn('comment_string_0', 'integer', ['comment' => '0']);
$table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']);
$table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']);
......@@ -719,9 +716,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
self::assertEquals(
[
'CREATE TABLE mytable (id INT IDENTITY NOT NULL, comment_null INT NOT NULL, comment_false INT NOT NULL, comment_empty_string INT NOT NULL, comment_integer_0 INT NOT NULL, comment_float_0 INT NOT NULL, comment_string_0 INT NOT NULL, comment INT NOT NULL, [comment_quoted] INT NOT NULL, [create] INT NOT NULL, commented_type VARCHAR(MAX) NOT NULL, commented_type_with_comment VARCHAR(MAX) NOT NULL, comment_with_string_literal_char NVARCHAR(255) NOT NULL, PRIMARY KEY (id))',
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_integer_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_float_0",
'CREATE TABLE mytable (id INT IDENTITY NOT NULL, comment_null INT NOT NULL, comment_empty_string INT NOT NULL, comment_string_0 INT NOT NULL, comment INT NOT NULL, [comment_quoted] INT NOT NULL, [create] INT NOT NULL, commented_type VARCHAR(MAX) NOT NULL, commented_type_with_comment VARCHAR(MAX) NOT NULL, comment_with_string_literal_char NVARCHAR(255) NOT NULL, PRIMARY KEY (id))',
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_string_0",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz you!', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz comments for explicitly quoted columns!', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [comment_quoted]",
......@@ -743,10 +738,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
$table = new Table('mytable');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('comment_null', 'integer', ['comment' => null]);
$table->addColumn('comment_false', 'integer', ['comment' => false]);
$table->addColumn('comment_empty_string', 'integer', ['comment' => '']);
$table->addColumn('comment_integer_0', 'integer', ['comment' => 0]);
$table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]);
$table->addColumn('comment_string_0', 'integer', ['comment' => '0']);
$table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']);
$table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']);
......@@ -760,10 +752,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
$tableDiff->fromTable = $table;
$tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer'));
$tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), ['comment' => null]);
$tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), ['comment' => false]);
$tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']);
$tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), ['comment' => 0]);
$tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), ['comment' => 0.0]);
$tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), ['comment' => '0']);
$tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), ['comment' => 'Doctrine']);
$tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), ['comment' => 'rulez']);
......@@ -772,8 +761,6 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
$tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), ['comment' => '666']);
$tableDiff->addedColumns['added_comment_with_string_literal_char'] = new Column('added_comment_with_string_literal_char', Type::getType('string'), ['comment' => "''"]);
$tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), ['comment' => 'Double for real!']);
// Add comment to non-commented column.
$tableDiff->changedColumns['id'] = new ColumnDiff(
'id',
......@@ -790,14 +777,6 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
new Column('comment_null', Type::getType('integer'), ['comment' => null])
);
// Add comment to false-commented column.
$tableDiff->changedColumns['comment_false'] = new ColumnDiff(
'comment_false',
new Column('comment_false', Type::getType('integer'), ['comment' => 'false']),
['comment'],
new Column('comment_false', Type::getType('integer'), ['comment' => false])
);
// Change type to custom type from empty string commented column.
$tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff(
'comment_empty_string',
......@@ -806,10 +785,10 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
new Column('comment_empty_string', Type::getType('integer'), ['comment' => ''])
);
// Change comment to false-comment from zero-string commented column.
// Change comment to empty comment from zero-string commented column.
$tableDiff->changedColumns['comment_string_0'] = new ColumnDiff(
'comment_string_0',
new Column('comment_string_0', Type::getType('integer'), ['comment' => false]),
new Column('comment_string_0', Type::getType('integer'), ['comment' => '']),
['comment'],
new Column('comment_string_0', Type::getType('integer'), ['comment' => '0'])
);
......@@ -862,20 +841,12 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
new Column('comment_with_string_literal_char', Type::getType('array'), ['comment' => "O'Reilly"])
);
$tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]);
self::assertEquals(
[
// Renamed columns.
"sp_RENAME 'mytable.comment_float_0', 'comment_double_0', 'COLUMN'",
// Added columns.
'ALTER TABLE mytable ADD added_comment_none INT NOT NULL',
'ALTER TABLE mytable ADD added_comment_null INT NOT NULL',
'ALTER TABLE mytable ADD added_comment_false INT NOT NULL',
'ALTER TABLE mytable ADD added_comment_empty_string INT NOT NULL',
'ALTER TABLE mytable ADD added_comment_integer_0 INT NOT NULL',
'ALTER TABLE mytable ADD added_comment_float_0 INT NOT NULL',
'ALTER TABLE mytable ADD added_comment_string_0 INT NOT NULL',
'ALTER TABLE mytable ADD added_comment INT NOT NULL',
'ALTER TABLE mytable ADD [added_comment_quoted] INT NOT NULL',
......@@ -883,7 +854,6 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
'ALTER TABLE mytable ADD added_commented_type VARCHAR(MAX) NOT NULL',
'ALTER TABLE mytable ADD added_commented_type_with_comment VARCHAR(MAX) NOT NULL',
'ALTER TABLE mytable ADD added_comment_with_string_literal_char NVARCHAR(255) NOT NULL',
'ALTER TABLE mytable DROP COLUMN comment_integer_0',
'ALTER TABLE mytable ALTER COLUMN comment_null NVARCHAR(255) NOT NULL',
'ALTER TABLE mytable ALTER COLUMN comment_empty_string VARCHAR(MAX) NOT NULL',
'ALTER TABLE mytable ALTER COLUMN [comment_quoted] VARCHAR(MAX) NOT NULL',
......@@ -891,8 +861,6 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
'ALTER TABLE mytable ALTER COLUMN commented_type INT NOT NULL',
// Added columns.
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment_integer_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment_float_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment_string_0",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment",
"EXEC sp_addextendedproperty N'MS_Description', N'rulez', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [added_comment_quoted]",
......@@ -903,7 +871,6 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
// Changed columns.
"EXEC sp_addextendedproperty N'MS_Description', N'primary', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', id",
"EXEC sp_addextendedproperty N'MS_Description', N'false', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_false",
"EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_empty_string",
"EXEC sp_dropextendedproperty N'MS_Description', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_string_0",
"EXEC sp_dropextendedproperty N'MS_Description', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment",
......
......@@ -1224,7 +1224,7 @@ class ComparatorTest extends TestCase
$column2 = new Column(
'foo',
Type::getType('guid'),
['notnull' => false, 'length' => '36', 'fixed' => true, 'default' => 'NEWID()', 'comment' => 'GUID 2.']
['notnull' => false, 'length' => 36, 'fixed' => true, 'default' => 'NEWID()', 'comment' => 'GUID 2.']
);
self::assertEquals(['notnull', 'default', 'comment'], $comparator->diffColumn($column1, $column2));
......
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