Implemented comparison of default values as strings regardless of their PHP types

Fixes #3336.
parent 296b0e51
...@@ -432,12 +432,10 @@ class Comparator ...@@ -432,12 +432,10 @@ class Comparator
$changedProperties[] = 'comment'; $changedProperties[] = 'comment';
} }
if ($properties1['default'] !== $properties2['default'] || // Null values need to be checked additionally as they tell whether to create or drop a default value.
// Null values need to be checked additionally as they tell whether to create or drop a default value. // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
// null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation. if (($properties1['default'] === null) !== ($properties2['default'] === null)
($properties1['default'] === null && $properties2['default'] !== null) || || (string) $properties1['default'] !== (string) $properties2['default']) {
($properties2['default'] === null && $properties1['default'] !== null)
) {
$changedProperties[] = 'default'; $changedProperties[] = 'default';
} }
......
<?php
declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase;
class ComparatorTest extends DbalFunctionalTestCase
{
/** @var AbstractSchemaManager */
private $schemaManager;
/** @var Comparator */
private $comparator;
protected function setUp()
{
parent::setUp();
$this->schemaManager = $this->connection->getSchemaManager();
$this->comparator = new Comparator();
}
public function testDefaultValueComparison()
{
$table = new Table('default_value');
$table->addColumn('id', 'integer', ['default' => 1]);
$this->schemaManager->createTable($table);
$onlineTable = $this->schemaManager->listTableDetails('default_value');
self::assertFalse($this->comparator->diffTable($table, $onlineTable));
}
}
...@@ -23,6 +23,8 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -23,6 +23,8 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
return; return;
} }
$this->resetSharedConn();
Type::addType('point', MySqlPointType::class); Type::addType('point', MySqlPointType::class);
} }
......
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