Skip to content

Commit 4ea7c11

Browse files
committed
Adding Table::getComment and Table::setComment methods
1 parent 054e1b5 commit 4ea7c11

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/Doctrine/DBAL/Schema/Table.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,4 +838,17 @@ private function normalizeIdentifier($identifier)
838838

839839
return $this->trimQuotes(strtolower($identifier));
840840
}
841+
842+
public function setComment(?string $comment) : self
843+
{
844+
// For keeping backward compatibility with MySQL in previous releases, table comments are stored as options.
845+
$this->addOption('comment', $comment);
846+
847+
return $this;
848+
}
849+
850+
public function getComment() : ?string
851+
{
852+
return $this->_options['comment'] ?? null;
853+
}
841854
}

tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,10 +1580,10 @@ public function testCommentInTable() : void
15801580
{
15811581
$table = new Table('table_with_comment');
15821582
$table->addColumn('id', 'integer');
1583-
$table->addOption('comment', 'Foo with control characters \'\\');
1583+
$table->setComment('Foo with control characters \'\\');
15841584
$this->schemaManager->dropAndCreateTable($table);
15851585

15861586
$table = $this->schemaManager->listTableDetails('table_with_comment');
1587-
self::assertSame('Foo with control characters \'\\', $table->getOption('comment'));
1587+
self::assertSame('Foo with control characters \'\\', $table->getComment());
15881588
}
15891589
}

tests/Doctrine/Tests/DBAL/Schema/TableTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,4 +882,13 @@ public function getNormalizesAssetNames()
882882
['"FOO"'],
883883
];
884884
}
885+
886+
public function testTableComment()
887+
{
888+
$table = new Table('bar');
889+
self::assertNull($table->getComment());
890+
891+
$table->setComment('foo');
892+
self::assertEquals('foo', $table->getComment());
893+
}
885894
}

0 commit comments

Comments
 (0)