Unverified Commit 1eba78d6 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3949 from morozov/non-nullable-comments

Make table and column comments non-nullable strings
parents 24dbc4e8 2ff70719
......@@ -446,7 +446,7 @@ abstract class AbstractPlatform
/**
* Gets the comment of a passed column modified by potential doctrine type comment hints.
*/
protected function getColumnComment(Column $column) : ?string
protected function getColumnComment(Column $column) : string
{
$comment = $column->getComment();
......@@ -1369,7 +1369,7 @@ abstract class AbstractPlatform
foreach ($table->getColumns() as $column) {
$comment = $this->getColumnComment($column);
if ($comment === null || $comment === '') {
if ($comment === '') {
continue;
}
......@@ -1380,18 +1380,18 @@ abstract class AbstractPlatform
return array_merge($sql, $columnSql);
}
protected function getCommentOnTableSQL(string $tableName, ?string $comment) : string
protected function getCommentOnTableSQL(string $tableName, string $comment) : string
{
$tableName = new Identifier($tableName);
return sprintf(
'COMMENT ON TABLE %s IS %s',
$tableName->getQuotedName($this),
$this->quoteStringLiteral((string) $comment)
$this->quoteStringLiteral($comment)
);
}
public function getCommentOnColumnSQL(string $tableName, string $columnName, ?string $comment) : string
public function getCommentOnColumnSQL(string $tableName, string $columnName, string $comment) : string
{
$tableName = new Identifier($tableName);
$columnName = new Identifier($columnName);
......@@ -1400,7 +1400,7 @@ abstract class AbstractPlatform
'COMMENT ON COLUMN %s.%s IS %s',
$tableName->getQuotedName($this),
$columnName->getQuotedName($this),
$this->quoteStringLiteral((string) $comment)
$this->quoteStringLiteral($comment)
);
}
......@@ -1409,13 +1409,13 @@ abstract class AbstractPlatform
*
* @throws DBALException If not supported on this platform.
*/
public function getInlineColumnCommentSQL(?string $comment) : string
public function getInlineColumnCommentSQL(string $comment) : string
{
if (! $this->supportsInlineColumnComments()) {
throw NotSupported::new(__METHOD__);
}
return 'COMMENT ' . $this->quoteStringLiteral((string) $comment);
return 'COMMENT ' . $this->quoteStringLiteral($comment);
}
/**
......
......@@ -419,7 +419,7 @@ class DB2Platform extends AbstractPlatform
$comment = $this->getColumnComment($column);
if ($comment === null || $comment === '') {
if ($comment === '') {
continue;
}
......
......@@ -701,7 +701,7 @@ SQL
$fields[] = $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$comment = $this->getColumnComment($column);
if ($comment === null || $comment === '') {
if ($comment === '') {
continue;
}
......
......@@ -402,7 +402,7 @@ SQL
$comment = $this->getColumnComment($column);
if ($comment === null || $comment === '') {
if ($comment === '') {
continue;
}
......@@ -584,20 +584,6 @@ SQL
return ['ALTER INDEX ' . $oldIndexName . ' RENAME TO ' . $index->getQuotedName($this)];
}
public function getCommentOnColumnSQL(string $tableName, string $columnName, ?string $comment) : string
{
$tableName = new Identifier($tableName);
$columnName = new Identifier($columnName);
$comment = $comment === null ? 'NULL' : $this->quoteStringLiteral($comment);
return sprintf(
'COMMENT ON COLUMN %s.%s IS %s',
$tableName->getQuotedName($this),
$columnName->getQuotedName($this),
$comment
);
}
public function getCreateSequenceSQL(Sequence $sequence) : string
{
return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) .
......
......@@ -123,7 +123,7 @@ class SQLAnywhere16Platform extends AbstractPlatform
$comment = $this->getColumnComment($column);
if ($comment === null || $comment === '') {
if ($comment === '') {
continue;
}
......@@ -320,20 +320,6 @@ class SQLAnywhere16Platform extends AbstractPlatform
return 'TEXT';
}
public function getCommentOnColumnSQL(string $tableName, string $columnName, ?string $comment) : string
{
$tableName = new Identifier($tableName);
$columnName = new Identifier($columnName);
$comment = $comment === null ? 'NULL' : $this->quoteStringLiteral($comment);
return sprintf(
'COMMENT ON COLUMN %s.%s IS %s',
$tableName->getQuotedName($this),
$columnName->getQuotedName($this),
$comment
);
}
public function getConcatExpression(string ...$string) : string
{
return 'STRING(' . implode(', ', $string) . ')';
......
......@@ -357,11 +357,11 @@ SQL
* as column comments are stored in the same property there when
* specifying a column's "Description" attribute.
*
* @param string $tableName The quoted table name to which the column belongs.
* @param string $columnName The quoted column name to create the comment for.
* @param string|null $comment The column's comment.
* @param string $tableName The quoted table name to which the column belongs.
* @param string $columnName The quoted column name to create the comment for.
* @param string $comment The column's comment.
*/
protected function getCreateColumnCommentSQL(string $tableName, string $columnName, ?string $comment) : string
protected function getCreateColumnCommentSQL(string $tableName, string $columnName, string $comment) : string
{
if (strpos($tableName, '.') !== false) {
[$schemaSQL, $tableSQL] = explode('.', $tableName);
......@@ -474,7 +474,7 @@ SQL
$comment = $this->getColumnComment($column);
if (empty($comment) && ! is_numeric($comment)) {
if ($comment === '') {
continue;
}
......@@ -500,11 +500,11 @@ SQL
$column = $columnDiff->column;
$comment = $this->getColumnComment($column);
$hasComment = ! empty($comment) || is_numeric($comment);
$hasComment = $comment !== '';
if ($columnDiff->fromColumn instanceof Column) {
$fromComment = $this->getColumnComment($columnDiff->fromColumn);
$hasFromComment = ! empty($fromComment) || is_numeric($fromComment);
$hasFromComment = $fromComment !== '';
if ($hasFromComment && $hasComment && $fromComment !== $comment) {
$commentsSql[] = $this->getAlterColumnCommentSQL(
......@@ -689,11 +689,11 @@ SQL
* as column comments are stored in the same property there when
* specifying a column's "Description" attribute.
*
* @param string $tableName The quoted table name to which the column belongs.
* @param string $columnName The quoted column name to alter the comment for.
* @param string|null $comment The column's comment.
* @param string $tableName The quoted table name to which the column belongs.
* @param string $columnName The quoted column name to alter the comment for.
* @param string $comment The column's comment.
*/
protected function getAlterColumnCommentSQL(string $tableName, string $columnName, ?string $comment) : string
protected function getAlterColumnCommentSQL(string $tableName, string $columnName, string $comment) : string
{
if (strpos($tableName, '.') !== false) {
[$schemaSQL, $tableSQL] = explode('.', $tableName);
......@@ -1449,7 +1449,7 @@ SQL
return strtoupper(dechex(crc32($identifier->getName())));
}
protected function getCommentOnTableSQL(string $tableName, ?string $comment) : string
protected function getCommentOnTableSQL(string $tableName, string $comment) : string
{
return sprintf(
<<<'SQL'
......@@ -1458,7 +1458,7 @@ EXEC sys.sp_addextendedproperty @name=N'MS_Description',
@level1type=N'TABLE', @level1name=N%s
SQL
,
$this->quoteStringLiteral((string) $comment),
$this->quoteStringLiteral($comment),
$this->quoteStringLiteral($tableName)
);
}
......
......@@ -514,9 +514,9 @@ class SqlitePlatform extends AbstractPlatform
return '';
}
public function getInlineColumnCommentSQL(?string $comment) : string
public function getInlineColumnCommentSQL(string $comment) : string
{
if ($comment === null || $comment === '') {
if ($comment === '') {
return '';
}
......
......@@ -47,8 +47,8 @@ class Column extends AbstractAsset
/** @var string|null */
protected $_columnDefinition;
/** @var string|null */
protected $_comment;
/** @var string */
protected $_comment = '';
/** @var array<string, mixed> */
protected $_customSchemaOptions = [];
......@@ -250,14 +250,14 @@ class Column extends AbstractAsset
return $this;
}
public function setComment(?string $comment) : self
public function setComment(string $comment) : self
{
$this->_comment = $comment;
return $this;
}
public function getComment() : ?string
public function getComment() : string
{
return $this->_comment;
}
......
......@@ -80,18 +80,19 @@ class DB2SchemaManager extends AbstractSchemaManager
}
$options = [
'length' => $length,
'unsigned' => false,
'fixed' => $fixed,
'default' => $default,
'autoincrement' => (bool) $tableColumn['autoincrement'],
'notnull' => $tableColumn['nulls'] === 'N',
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
? $tableColumn['comment']
: null,
'length' => $length,
'unsigned' => false,
'fixed' => $fixed,
'default' => $default,
'autoincrement' => (bool) $tableColumn['autoincrement'],
'notnull' => $tableColumn['nulls'] === 'N',
'platformOptions' => [],
];
if (isset($tableColumn['comment'])) {
$options['comment'] = $tableColumn['comment'];
}
if ($scale !== null && $precision !== null) {
$options['scale'] = $scale;
$options['precision'] = $precision;
......
......@@ -196,11 +196,12 @@ class MySqlSchemaManager extends AbstractSchemaManager
'scale' => $scale,
'precision' => $precision,
'autoincrement' => strpos($tableColumn['extra'], 'auto_increment') !== false,
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
? $tableColumn['comment']
: null,
];
if (isset($tableColumn['comment'])) {
$options['comment'] = $tableColumn['comment'];
}
$column = new Column($tableColumn['field'], Type::getType($type), $options);
if (isset($tableColumn['characterset'])) {
......
......@@ -200,11 +200,12 @@ class OracleSchemaManager extends AbstractSchemaManager
'length' => $length,
'precision' => $precision,
'scale' => $scale,
'comment' => isset($tableColumn['comments']) && $tableColumn['comments'] !== ''
? $tableColumn['comments']
: null,
];
if (isset($tableColumn['comments'])) {
$options['comment'] = $tableColumn['comments'];
}
return new Column($this->getQuotedIdentifierName($tableColumn['column_name']), Type::getType($type), $options);
}
......
......@@ -463,11 +463,12 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
'fixed' => $fixed,
'unsigned' => false,
'autoincrement' => $autoincrement,
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
? $tableColumn['comment']
: null,
];
if (isset($tableColumn['comment'])) {
$options['comment'] = $tableColumn['comment'];
}
$column = new Column($tableColumn['field'], Type::getType($type), $options);
if (isset($tableColumn['collation']) && ! empty($tableColumn['collation'])) {
......
......@@ -123,9 +123,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
'notnull' => (bool) $tableColumn['notnull'],
'default' => $default,
'autoincrement' => (bool) $tableColumn['autoincrement'],
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
? $tableColumn['comment']
: null,
'comment' => $tableColumn['comment'] ?? '',
]
);
}
......
......@@ -120,9 +120,12 @@ class SQLServerSchemaManager extends AbstractSchemaManager
'scale' => $scale,
'precision' => $precision,
'autoincrement' => (bool) $tableColumn['autoincrement'],
'comment' => $tableColumn['comment'] !== '' ? $tableColumn['comment'] : null,
];
if (isset($tableColumn['comment'])) {
$options['comment'] = $tableColumn['comment'];
}
if ($length !== 0 && ($type === 'text' || $type === 'string')) {
$options['length'] = $length;
}
......
......@@ -12,6 +12,7 @@ use Doctrine\DBAL\Types\Type;
use function array_change_key_case;
use function array_reverse;
use function array_values;
use function assert;
use function count;
use function file_exists;
use function is_string;
......@@ -463,18 +464,19 @@ CREATE\sTABLE # Match "CREATE TABLE"
return $comment === '' ? null : $comment;
}
private function parseColumnCommentFromSQL(string $column, string $sql) : ?string
private function parseColumnCommentFromSQL(string $column, string $sql) : string
{
$pattern = '{[\s(,](?:\W' . preg_quote($this->_platform->quoteSingleIdentifier($column)) . '\W|\W' . preg_quote($column)
. '\W)(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i';
if (preg_match($pattern, $sql, $match) !== 1) {
return null;
return '';
}
$comment = preg_replace('{^\s*--}m', '', rtrim($match[1], "\n"));
assert(is_string($comment));
return $comment === '' ? null : $comment;
return $comment;
}
private function getCreateTableSQL(string $table) : string
......
......@@ -801,7 +801,7 @@ class Table extends AbstractAsset
return $this->trimQuotes(strtolower($identifier));
}
public function setComment(?string $comment) : self
public function setComment(string $comment) : self
{
// For keeping backward compatibility with MySQL in previous releases, table comments are stored as options.
$this->addOption('comment', $comment);
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Functional\Schema;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use function array_merge;
use function sprintf;
class ColumnCommentTest extends FunctionalTestCase
{
/** @var bool */
private static $initialized = false;
protected function setUp() : void
{
parent::setUp();
if (self::$initialized) {
return;
}
self::$initialized = true;
$table = new Table('column_comments');
$table->addColumn('id', 'integer');
foreach (self::columnProvider() as [$name, $type, $options]) {
$table->addColumn($name, $type, $options);
}
$this->connection->getSchemaManager()
->dropAndCreateTable($table);
}
/**
* @param array<string,mixed> $options
*
* @dataProvider columnProvider
*/
public function testColumnComment(string $name, string $type, array $options) : void
{
$this->assertColumnComment('column_comments', $name, $options['comment'] ?? '');
}
/**
* @return mixed[][]
*/
public static function columnProvider() : iterable
{
foreach ([
'commented' => [
'string',
['length' => 16],
],
'not_commented' => [
'array',
[],
],
] as $typeName => [$type, $typeOptions]) {
foreach ([
'no_comment' => [],
'with_comment' => ['comment' => 'Some comment'],
'zero_comment' => ['comment' => '0'],
'empty_comment' => ['comment' => ''],
'quoted_comment' => ['comment' => "O'Reilly"],
] as $caseName => $caseOptions) {
$name = sprintf('%s_%s', $typeName, $caseName);
yield $name => [
$name,
$type,
array_merge($typeOptions, $caseOptions),
];
}
}
}
/**
* @dataProvider alterColumnCommentProvider
*/
public function testAlterColumnComment(string $comment1, string $comment2) : void
{
$table1 = new Table('column_comments');
$table1->addColumn('id', 'integer', ['comment' => $comment1]);
$this->connection->getSchemaManager()
->dropAndCreateTable($table1);
$table2 = clone $table1;
$table2->getColumn('id')->setComment($comment2);
$diff = (new Comparator())->diffTable($table1, $table2);
self::assertNotNull($diff);
$sm = $this->connection->getSchemaManager();
$sm->alterTable($diff);
$this->assertColumnComment('column_comments', 'id', $comment2);
}
/**
* @return mixed[][]
*/
public static function alterColumnCommentProvider() : iterable
{
return [
'Empty to non-empty' => ['', 'foo'],
'Non-empty to empty' => ['foo', ''],
'Empty to zero' => ['', '0'],
'Zero to empty' => ['0', ''],
'Non-empty to non-empty' => ['foo', 'bar'],
];
}
private function assertColumnComment(string $table, string $column, string $expectedComment) : void
{
self::assertSame(
$expectedComment,
$this->connection->getSchemaManager()
->listTableDetails($table)
->getColumn($column)
->getComment()
);
}
}
......@@ -4,31 +4,8 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Functional\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\BooleanType;
class Db2SchemaManagerTest extends SchemaManagerFunctionalTestCase
{
/**
* @group DBAL-939
*/
public function testGetBooleanColumn() : void
{
$table = new Table('boolean_column_test');
$table->addColumn('bool', 'boolean');
$table->addColumn('bool_commented', 'boolean', ['comment' => "That's a comment"]);
$this->schemaManager->createTable($table);
$columns = $this->schemaManager->listTableColumns('boolean_column_test');
self::assertInstanceOf(BooleanType::class, $columns['bool']->getType());
self::assertInstanceOf(BooleanType::class, $columns['bool_commented']->getType());
self::assertNull($columns['bool']->getComment());
self::assertSame("That's a comment", $columns['bool_commented']->getComment());
}
public function testListTableWithBinary() : void
{
self::markTestSkipped('Binary data type is currently not supported on DB2 LUW');
......
......@@ -134,10 +134,10 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$offlinePrimaryTable->addColumn(
'"Id"',
'integer',
['autoincrement' => true, 'comment' => 'Explicit casing.']
['autoincrement' => true]
);
$offlinePrimaryTable->addColumn('select', 'integer', ['comment' => 'Reserved keyword.']);
$offlinePrimaryTable->addColumn('foo', 'integer', ['comment' => 'Implicit uppercasing.']);
$offlinePrimaryTable->addColumn('select', 'integer');
$offlinePrimaryTable->addColumn('foo', 'integer');
$offlinePrimaryTable->addColumn('BAR', 'integer');
$offlinePrimaryTable->addColumn('"BAZ"', 'integer');
$offlinePrimaryTable->addIndex(['select'], 'from');
......
......@@ -171,148 +171,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertEquals(666, $columns['df_integer']->getDefault());
}
/**
* @group DBAL-543
*/
public function testColumnComments() : void
{
$table = new Table('sqlsrv_column_comment');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('comment_null', 'integer', ['comment' => null]);
$table->addColumn('comment_empty_string', 'integer', ['comment' => '']);
$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!']);
$table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']);
$table->addColumn('commented_type', 'object');
$table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']);
$table->setPrimaryKey(['id']);
$this->schemaManager->createTable($table);
$columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment');
self::assertCount(9, $columns);
self::assertNull($columns['id']->getComment());
self::assertNull($columns['comment_null']->getComment());
self::assertNull($columns['comment_empty_string']->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());
self::assertEquals('Doctrine 0wnz comments for reserved keyword columns!', $columns['[create]']->getComment());
self::assertNull($columns['commented_type']->getComment());
self::assertEquals('Doctrine array type.', $columns['commented_type_with_comment']->getComment());
$tableDiff = new TableDiff('sqlsrv_column_comment');
$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_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']);
$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']);
$tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), ['comment' => '666']);
$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']);
// Add comment to non-commented column.
$tableDiff->changedColumns['id'] = new ColumnDiff(
'id',
new Column('id', Type::getType('integer'), ['autoincrement' => true, 'comment' => 'primary']),
['comment'],
new Column('id', Type::getType('integer'), ['autoincrement' => true])
);
// Remove comment from null-commented column.
$tableDiff->changedColumns['comment_null'] = new ColumnDiff(
'comment_null',
new Column('comment_null', Type::getType('string'), ['length' => 255]),
['type'],
new Column('comment_null', Type::getType('integer'), [
'length' => 255,
'comment' => null,
])
);
// Change type to custom type from empty string commented column.
$tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff(
'comment_empty_string',
new Column('comment_empty_string', Type::getType('object')),
['type'],
new Column('comment_empty_string', Type::getType('integer'), ['comment' => ''])
);
// 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' => '']),
['comment'],
new Column('comment_string_0', Type::getType('integer'), ['comment' => '0'])
);
// Remove comment from regular commented column.
$tableDiff->changedColumns['comment'] = new ColumnDiff(
'comment',
new Column('comment', Type::getType('integer')),
['comment'],
new Column('comment', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!'])
);
// Change comment and change type to custom type from regular commented column.
$tableDiff->changedColumns['`comment_quoted`'] = new ColumnDiff(
'`comment_quoted`',
new Column('`comment_quoted`', Type::getType('array'), ['comment' => 'Doctrine array.']),
['comment', 'type'],
new Column('`comment_quoted`', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!'])
);
// Remove comment and change type to custom type from regular commented column.
$tableDiff->changedColumns['create'] = new ColumnDiff(
'create',
new Column('create', Type::getType('object')),
['comment', 'type'],
new Column('create', Type::getType('integer'), ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!'])
);
// Add comment and change custom type to regular type from non-commented column.
$tableDiff->changedColumns['commented_type'] = new ColumnDiff(
'commented_type',
new Column('commented_type', Type::getType('integer'), ['comment' => 'foo']),
['comment', 'type'],
new Column('commented_type', Type::getType('object'))
);
// Remove comment from commented custom type column.
$tableDiff->changedColumns['commented_type_with_comment'] = new ColumnDiff(
'commented_type_with_comment',
new Column('commented_type_with_comment', Type::getType('array')),
['comment'],
new Column('commented_type_with_comment', Type::getType('array'), ['comment' => 'Doctrine array type.'])
);
$this->schemaManager->alterTable($tableDiff);
$columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment');
self::assertCount(18, $columns);
self::assertEquals('primary', $columns['id']->getComment());
self::assertNull($columns['comment_null']->getComment());
self::assertNull($columns['comment_empty_string']->getComment());
self::assertNull($columns['comment_string_0']->getComment());
self::assertNull($columns['comment']->getComment());
self::assertEquals('Doctrine array.', $columns['comment_quoted']->getComment());
self::assertNull($columns['[create]']->getComment());
self::assertEquals('foo', $columns['commented_type']->getComment());
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_empty_string']->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());
self::assertEquals('666', $columns['[select]']->getComment());
self::assertNull($columns['added_commented_type']->getComment());
self::assertEquals('666', $columns['added_commented_type_with_comment']->getComment());
}
public function testPkOrdering() : void
{
// SQL Server stores index column information in a system table with two
......
......@@ -295,7 +295,7 @@ SQL;
$sm = $this->connection->getSchemaManager();
$sm->createTable($table);
self::assertNull($sm->listTableDetails('own_column_comment')
self::assertSame('', $sm->listTableDetails('own_column_comment')
->getColumn('col1')
->getComment());
}
......
......@@ -35,7 +35,6 @@ class DBAL461Test extends TestCase
'precision' => 0,
'autoincrement' => false,
'collation' => 'foo',
'comment' => null,
]);
self::assertInstanceOf(DecimalType::class, $column->getType());
......
......@@ -1306,7 +1306,7 @@ abstract class AbstractPlatformTestCase extends TestCase
* @group DBAL-1176
* @dataProvider getGeneratesInlineColumnCommentSQL
*/
public function testGeneratesInlineColumnCommentSQL(?string $comment, string $expectedSql) : void
public function testGeneratesInlineColumnCommentSQL(string $comment, string $expectedSql) : void
{
if (! $this->platform->supportsInlineColumnComments()) {
self::markTestSkipped(sprintf('%s does not support inline column comments.', get_class($this->platform)));
......
......@@ -347,7 +347,7 @@ abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCa
return [
'ALTER TABLE mytable ADD quota INT NOT NULL',
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
'COMMENT ON COLUMN mytable.foo IS NULL',
"COMMENT ON COLUMN mytable.foo IS ''",
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
];
}
......
......@@ -662,7 +662,6 @@ 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_empty_string', 'integer', ['comment' => '']);
$table->addColumn('comment_string_0', 'integer', ['comment' => '0']);
$table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']);
......@@ -678,7 +677,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
self::assertEquals(
[
'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))',
'CREATE TABLE mytable (id INT IDENTITY 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]",
......@@ -699,7 +698,6 @@ 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_empty_string', 'integer', ['comment' => '']);
$table->addColumn('comment_string_0', 'integer', ['comment' => '0']);
$table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']);
......@@ -716,7 +714,6 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
$tableDiff = new TableDiff('mytable');
$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_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']);
$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']);
......@@ -737,14 +734,6 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
new Column('id', Type::getType('integer'), ['autoincrement' => true])
);
// Remove comment from null-commented column.
$tableDiff->changedColumns['comment_null'] = new ColumnDiff(
'comment_null',
new Column('comment_null', Type::getType('string'), ['length' => 255]),
['type'],
new Column('comment_null', Type::getType('integer'), ['comment' => null])
);
// Change type to custom type from empty string commented column.
$tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff(
'comment_empty_string',
......@@ -813,7 +802,6 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
[
// 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_empty_string INT NOT NULL',
'ALTER TABLE mytable ADD added_comment_string_0 INT NOT NULL',
'ALTER TABLE mytable ADD added_comment INT NOT NULL',
......@@ -822,7 +810,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 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',
'ALTER TABLE mytable ALTER COLUMN [create] VARCHAR(MAX) NOT NULL',
......
......@@ -136,7 +136,7 @@ class SQLAnywhere16PlatformTest extends AbstractPlatformTestCase
return [
'ALTER TABLE mytable ADD quota INT NOT NULL',
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
'COMMENT ON COLUMN mytable.foo IS NULL',
"COMMENT ON COLUMN mytable.foo IS ''",
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
];
}
......@@ -229,7 +229,7 @@ class SQLAnywhere16PlatformTest extends AbstractPlatformTestCase
);
self::assertEquals(
['COMMENT ON COLUMN mytable.foo IS NULL'],
["COMMENT ON COLUMN mytable.foo IS ''"],
$this->platform->getAlterTableSQL($tableDiff)
);
}
......
......@@ -55,12 +55,12 @@ class ColumnTest extends TestCase
'unsigned' => true,
'autoincrement' => false,
'columnDefinition' => null,
'comment' => null,
'comment' => '',
'foo' => 'bar',
'bar' => 'baz',
];
self::assertEquals($expected, $this->createColumn()->toArray());
self::assertSame($expected, $this->createColumn()->toArray());
}
public function testSettingUnknownOptionIsStillSupported() : void
......@@ -157,7 +157,7 @@ class ColumnTest extends TestCase
public function testColumnComment() : void
{
$column = new Column('bar', Type::getType('string'));
self::assertNull($column->getComment());
self::assertSame('', $column->getComment());
$column->setComment('foo');
self::assertEquals('foo', $column->getComment());
......
......@@ -1236,7 +1236,7 @@ class ComparatorTest extends TestCase
* @group DBAL-1009
* @dataProvider getCompareColumnComments
*/
public function testCompareColumnComments(?string $comment1, ?string $comment2, bool $equals) : void
public function testCompareColumnComments(string $comment1, string $comment2, bool $equals) : void
{
$column1 = new Column('foo', Type::getType('integer'), ['comment' => $comment1]);
$column2 = new Column('foo', Type::getType('integer'), ['comment' => $comment2]);
......@@ -1260,17 +1260,11 @@ class ComparatorTest extends TestCase
public static function getCompareColumnComments() : iterable
{
return [
[null, null, true],
['', '', true],
[' ', ' ', true],
['0', '0', true],
['foo', 'foo', true],
[null, '', true],
[null, ' ', false],
[null, '0', false],
[null, 'foo', false],
['', ' ', false],
['', '0', false],
['', 'foo', false],
......
......@@ -57,7 +57,7 @@ class SqliteSchemaManagerTest extends TestCase
* @dataProvider getDataColumnComment
* @group 2865
*/
public function testParseColumnCommentFromSQL(?string $comment, string $column, string $sql) : void
public function testParseColumnCommentFromSQL(string $comment, string $column, string $sql) : void
{
$conn = $this->createMock(Connection::class);
$conn->method('getDatabasePlatform')->willReturn(new SqlitePlatform());
......@@ -76,7 +76,7 @@ class SqliteSchemaManagerTest extends TestCase
{
return [
'Single column with no comment' => [
null,
'',
'a',
'CREATE TABLE "a" ("a" TEXT DEFAULT "a" COLLATE RTRIM)',
],
......@@ -87,7 +87,7 @@ class SqliteSchemaManagerTest extends TestCase
)',
],
'Multiple similar columns with type comment 1' => [
null,
'',
'b',
'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" TEXT DEFAULT "a" COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x)
)',
......@@ -99,7 +99,7 @@ class SqliteSchemaManagerTest extends TestCase
)',
],
'Multiple similar columns on different lines, with type comment 1' => [
null,
'',
'bb',
'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x)
, "bb" TEXT DEFAULT "a" COLLATE RTRIM',
......@@ -111,14 +111,14 @@ class SqliteSchemaManagerTest extends TestCase
, "b" TEXT DEFAULT "a" COLLATE RTRIM',
],
'Column with numeric but no comment 1' => [
null,
'',
'a',
'CREATE TABLE "a" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array)
, "c" CHAR(36) NOT NULL --(DC2Type:guid)
)',
],
'Column with numeric but no comment 2' => [
null,
'',
'a',
'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array)
, "c" CHAR(36) NOT NULL --(DC2Type:guid)
......@@ -140,7 +140,7 @@ class SqliteSchemaManagerTest extends TestCase
)',
],
'Column "bar", select "bar" with no comment' => [
null,
'',
'bar',
'CREATE TABLE dummy_table (
id INTEGER NOT NULL,
......@@ -162,7 +162,7 @@ class SqliteSchemaManagerTest extends TestCase
)',
],
'Column "bar", select "baz" with no comment' => [
null,
'',
'baz',
'CREATE TABLE dummy_table (
id INTEGER NOT NULL,
......@@ -185,7 +185,7 @@ class SqliteSchemaManagerTest extends TestCase
],
'Column "bar#", select "bar#" with no comment' => [
null,
'',
'bar#',
'CREATE TABLE dummy_table (
id INTEGER NOT NULL,
......@@ -207,7 +207,7 @@ class SqliteSchemaManagerTest extends TestCase
)',
],
'Column "bar#", select "baz" with no comment' => [
null,
'',
'baz',
'CREATE TABLE dummy_table (
id INTEGER NOT NULL,
......@@ -230,7 +230,7 @@ class SqliteSchemaManagerTest extends TestCase
],
'Column "bar/", select "bar/" with no comment' => [
null,
'',
'bar/',
'CREATE TABLE dummy_table (
id INTEGER NOT NULL,
......@@ -252,7 +252,7 @@ class SqliteSchemaManagerTest extends TestCase
)',
],
'Column "bar/", select "baz" with no comment' => [
null,
'',
'baz',
'CREATE TABLE dummy_table (
id INTEGER NOT NULL,
......
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