From b9437edbc7fc236bcd22c5e777ae917201f6869a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 19 May 2019 12:07:09 -0700 Subject: [PATCH] Fixed some invalid tests discovered because of the changes from #2960 --- .../DBAL/Platforms/AbstractPlatform.php | 6 +++++ .../SchemaManagerFunctionalTestCase.php | 26 +++++-------------- .../AbstractSQLServerPlatformTestCase.php | 6 ++--- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index ef900f017f7..c730a97c85f 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -46,6 +46,8 @@ use function in_array; use function is_array; use function is_bool; +use function is_float; +use function is_int; use function is_string; use function preg_quote; use function preg_replace; @@ -2071,6 +2073,10 @@ public function getDefaultValueDeclarationSQL(array $field) : string return " DEFAULT '" . $this->convertBooleans($default) . "'"; } + if (is_int($default) || is_float($default)) { + return ' DEFAULT ' . $default; + } + return ' DEFAULT ' . $this->quoteStringLiteral($default); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index ee166e9c7e5..f030ca30c8c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1054,12 +1054,9 @@ public function testColumnDefaultLifecycle() : void $table = new Table('col_def_lifecycle'); $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('column1', 'string', ['default' => null]); - $table->addColumn('column2', 'string', ['default' => false]); - $table->addColumn('column3', 'string', ['default' => true]); - $table->addColumn('column4', 'string', ['default' => 0]); - $table->addColumn('column5', 'string', ['default' => '']); - $table->addColumn('column6', 'string', ['default' => 'def']); - $table->addColumn('column7', 'integer', ['default' => 0]); + $table->addColumn('column2', 'string', ['default' => '']); + $table->addColumn('column3', 'string', ['default' => 'default1']); + $table->addColumn('column4', 'integer', ['default' => 0]); $table->setPrimaryKey(['id']); $this->schemaManager->dropAndCreateTable($table); @@ -1069,21 +1066,15 @@ public function testColumnDefaultLifecycle() : void self::assertNull($columns['id']->getDefault()); self::assertNull($columns['column1']->getDefault()); self::assertSame('', $columns['column2']->getDefault()); - self::assertSame('1', $columns['column3']->getDefault()); + self::assertSame('default1', $columns['column3']->getDefault()); self::assertSame('0', $columns['column4']->getDefault()); - self::assertSame('', $columns['column5']->getDefault()); - self::assertSame('def', $columns['column6']->getDefault()); - self::assertSame('0', $columns['column7']->getDefault()); $diffTable = clone $table; - $diffTable->changeColumn('column1', ['default' => false]); + $diffTable->changeColumn('column1', ['default' => '']); $diffTable->changeColumn('column2', ['default' => null]); - $diffTable->changeColumn('column3', ['default' => false]); + $diffTable->changeColumn('column3', ['default' => 'default2']); $diffTable->changeColumn('column4', ['default' => null]); - $diffTable->changeColumn('column5', ['default' => false]); - $diffTable->changeColumn('column6', ['default' => 666]); - $diffTable->changeColumn('column7', ['default' => null]); $comparator = new Comparator(); @@ -1093,11 +1084,8 @@ public function testColumnDefaultLifecycle() : void self::assertSame('', $columns['column1']->getDefault()); self::assertNull($columns['column2']->getDefault()); - self::assertSame('', $columns['column3']->getDefault()); + self::assertSame('default2', $columns['column3']->getDefault()); self::assertNull($columns['column4']->getDefault()); - self::assertSame('', $columns['column5']->getDefault()); - self::assertSame('666', $columns['column6']->getDefault()); - self::assertNull($columns['column7']->getDefault()); } public function testListTableWithBinary() : void diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 0b8e554300d..fb90d8105f2 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -1032,9 +1032,9 @@ public function testChangeColumnsTypeWithDefaultValue() : void $tableDiff->changedColumns['col_string'] = new ColumnDiff( 'col_string', - new Column('col_string', Type::getType('string'), ['default' => 666, 'fixed' => true]), + new Column('col_string', Type::getType('string'), ['default' => 'bar', 'fixed' => true]), ['fixed'], - new Column('col_string', Type::getType('string'), ['default' => 666]) + new Column('col_string', Type::getType('string'), ['default' => 'foo']) ); $expected = $this->platform->getAlterTableSQL($tableDiff); @@ -1047,7 +1047,7 @@ public function testChangeColumnsTypeWithDefaultValue() : void 'ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_FA2CB292 DEFAULT 666 FOR col_int', 'ALTER TABLE column_def_change_type DROP CONSTRAINT DF_829302E0_2725A6D0', 'ALTER TABLE column_def_change_type ALTER COLUMN col_string NCHAR(255) NOT NULL', - "ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_2725A6D0 DEFAULT '666' FOR col_string", + "ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_2725A6D0 DEFAULT 'bar' FOR col_string", ] ); }