Skip to content

Commit

Permalink
Merge pull request #3355 from morozov/issues/3336
Browse files Browse the repository at this point in the history
Implemented comparison of default values as strings regardless of their PHP types
  • Loading branch information
morozov committed Nov 24, 2018
2 parents 296b0e5 + 4389a25 commit 9dbec4b
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
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
@@ -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));
}
}
Expand Up @@ -23,6 +23,8 @@ protected function setUp()
return;
}

$this->resetSharedConn();

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

Expand Down

0 comments on commit 9dbec4b

Please sign in to comment.