Skip to content

Commit

Permalink
Implemented comparison of default values as strings regardless of the…
Browse files Browse the repository at this point in the history
…ir PHP types

Fixes #3336.
  • Loading branch information
morozov committed Nov 24, 2018
1 parent 296b0e5 commit 4389a25
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/Doctrine/DBAL/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,10 @@ public function diffColumn(Column $column1, Column $column2)
$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 != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
($properties1['default'] === null && $properties2['default'] !== null) ||
($properties2['default'] === null && $properties1['default'] !== null)
) {
// 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.
if (($properties1['default'] === null) !== ($properties2['default'] === null)
|| (string) $properties1['default'] !== (string) $properties2['default']) {
$changedProperties[] = 'default';
}

Expand Down
39 changes: 39 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ protected function setUp()
return;
}

$this->resetSharedConn();

Type::addType('point', MySqlPointType::class);
}

Expand Down

0 comments on commit 4389a25

Please sign in to comment.