From 4389a258c0b6a6c47099e65a54db98904d7235b2 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 23 Nov 2018 20:01:42 -0800 Subject: [PATCH] Implemented comparison of default values as strings regardless of their PHP types Fixes #3336. --- lib/Doctrine/DBAL/Schema/Comparator.php | 10 ++--- .../DBAL/Functional/Schema/ComparatorTest.php | 39 +++++++++++++++++++ .../Schema/MySqlSchemaManagerTest.php | 2 + 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index f95417face2..3b5a0b155d0 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -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'; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php new file mode 100644 index 00000000000..a97eb90bbce --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php @@ -0,0 +1,39 @@ +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)); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index b1669e345f5..475dcee3ee6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -23,6 +23,8 @@ protected function setUp() return; } + $this->resetSharedConn(); + Type::addType('point', MySqlPointType::class); }