Skip to content

Commit

Permalink
Fixed some invalid tests discovered because of the changes from doctr…
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed May 24, 2019
1 parent 1f2f6bb commit 36fd23b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
6 changes: 6 additions & 0 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2011,6 +2013,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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,12 +1063,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);
Expand All @@ -1078,21 +1075,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();

Expand All @@ -1102,11 +1093,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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",
]
);
}
Expand Down

0 comments on commit 36fd23b

Please sign in to comment.