Skip to content

Commit

Permalink
Make the schema manager aware of the disabling of type comments
Browse files Browse the repository at this point in the history
Without this change, the schema comparison will not remove existing type
comments when disabling them because it will still silently remove that
part of the comment during introspection (and so won't detect an
expected change between the expected empty comment and the introspected
comment).
Disabling that stripping logic when disabling type comments corresponds
to the behavior of DBAL 4 regarding comments, which is exactly what the
configuration option is about.
  • Loading branch information
stof committed Aug 6, 2024
1 parent 8a7e9b7 commit 8ce05ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,10 @@ public function getSchemaSearchPaths()
*/
public function extractDoctrineTypeFromComment($comment, $currentType)
{
if ($this->_conn->getConfiguration()->getDisableTypeComments()) {
return $currentType;

Check warning on line 1744 in src/Schema/AbstractSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/AbstractSchemaManager.php#L1744

Added line #L1744 was not covered by tests
}

if ($comment !== null && preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match) === 1) {
return $match[1];
}
Expand All @@ -1757,6 +1761,10 @@ public function extractDoctrineTypeFromComment($comment, $currentType)
*/
public function removeDoctrineTypeFromComment($comment, $type)
{
if ($this->_conn->getConfiguration()->getDisableTypeComments()) {
return $comment;

Check warning on line 1765 in src/Schema/AbstractSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/AbstractSchemaManager.php#L1765

Added line #L1765 was not covered by tests
}

if ($comment === null) {
return null;
}
Expand Down
8 changes: 7 additions & 1 deletion tests/Functional/Ticket/DBAL461Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\DBAL\Tests\Functional\Ticket;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
Expand All @@ -14,7 +15,12 @@ class DBAL461Test extends TestCase
{
public function testIssue(): void
{
$conn = $this->createMock(Connection::class);
$configuration = $this->createStub(Configuration::class);
$configuration->method('getDisableTypeComments')->willReturn(false);

$conn = $this->createMock(Connection::class);
$conn->method('getConfiguration')->willReturn($configuration);

$platform = new SQLServer2012Platform();
$platform->registerDoctrineTypeMapping('numeric', Types::DECIMAL);

Expand Down

0 comments on commit 8ce05ed

Please sign in to comment.