44
55namespace Doctrine \DBAL \Tests \Functional \Schema ;
66
7- use DateTime ;
87use Doctrine \DBAL \DriverManager ;
98use Doctrine \DBAL \Exception \DatabaseRequired ;
109use Doctrine \DBAL \Platforms \AbstractMySQLPlatform ;
1110use Doctrine \DBAL \Platforms \AbstractPlatform ;
1211use Doctrine \DBAL \Platforms \MariaDBPlatform ;
1312use Doctrine \DBAL \Schema \Column ;
1413use Doctrine \DBAL \Schema \ColumnEditor ;
14+ use Doctrine \DBAL \Schema \DefaultExpression \CurrentTimestamp ;
1515use Doctrine \DBAL \Schema \Index ;
1616use Doctrine \DBAL \Schema \Index \IndexedColumn ;
1717use Doctrine \DBAL \Schema \Index \IndexType ;
@@ -595,29 +595,30 @@ public function testColumnDefaultCurrentTimestamp(): void
595595 {
596596 $ platform = $ this ->connection ->getDatabasePlatform ();
597597
598- $ currentTimeStampSql = $ platform ->getCurrentTimestampSQL ();
598+ $ currentTimeStamp = new CurrentTimestamp ();
599+ $ currentTimeStampSQL = $ currentTimeStamp ->toSQL ($ platform );
599600
600601 $ table = Table::editor ()
601602 ->setUnquotedName ('test_column_defaults_current_timestamp ' )
602603 ->setColumns (
603604 Column::editor ()
604605 ->setUnquotedName ('col_datetime ' )
605606 ->setTypeName (Types::DATETIME_MUTABLE )
606- ->setDefaultValue ($ currentTimeStampSql )
607+ ->setDefaultValue ($ currentTimeStamp )
607608 ->create (),
608609 Column::editor ()
609610 ->setUnquotedName ('col_datetime_nullable ' )
610611 ->setTypeName (Types::DATETIME_MUTABLE )
611- ->setDefaultValue ($ currentTimeStampSql )
612+ ->setDefaultValue ($ currentTimeStamp )
612613 ->create (),
613614 )
614615 ->create ();
615616
616617 $ this ->dropAndCreateTable ($ table );
617618
618619 $ onlineTable = $ this ->schemaManager ->introspectTableByUnquotedName ('test_column_defaults_current_timestamp ' );
619- self ::assertSame ($ currentTimeStampSql , $ onlineTable ->getColumn ('col_datetime ' )->getDefault ());
620- self ::assertSame ($ currentTimeStampSql , $ onlineTable ->getColumn ('col_datetime_nullable ' )->getDefault ());
620+ self ::assertSame ($ currentTimeStampSQL , $ onlineTable ->getColumn ('col_datetime ' )->getDefault ());
621+ self ::assertSame ($ currentTimeStampSQL , $ onlineTable ->getColumn ('col_datetime_nullable ' )->getDefault ());
621622
622623 self ::assertTrue (
623624 $ this ->schemaManager
@@ -629,16 +630,9 @@ public function testColumnDefaultCurrentTimestamp(): void
629630
630631 public function testColumnDefaultsAreValid (): void
631632 {
632- $ currentTimeStampSql = $ this ->connection ->getDatabasePlatform ()->getCurrentTimestampSQL ();
633-
634633 $ table = Table::editor ()
635634 ->setUnquotedName ('test_column_defaults_are_valid ' )
636635 ->setColumns (
637- Column::editor ()
638- ->setUnquotedName ('col_datetime ' )
639- ->setTypeName (Types::DATETIME_MUTABLE )
640- ->setDefaultValue ($ currentTimeStampSql )
641- ->create (),
642636 Column::editor ()
643637 ->setUnquotedName ('col_datetime_null ' )
644638 ->setTypeName (Types::DATETIME_MUTABLE )
@@ -681,19 +675,15 @@ public function testColumnDefaultsAreValid(): void
681675 'INSERT INTO test_column_defaults_are_valid () VALUES() ' ,
682676 );
683677
684- $ row = $ this ->connection ->fetchAssociative (
685- 'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid ' ,
686- );
678+ $ row = $ this ->connection ->fetchAssociative ('SELECT * FROM test_column_defaults_are_valid ' );
687679 self ::assertNotFalse ($ row );
688680
689- self ::assertInstanceOf (DateTime::class, DateTime::createFromFormat ('Y-m-d H:i:s ' , $ row ['col_datetime ' ]));
690681 self ::assertNull ($ row ['col_datetime_null ' ]);
691682 self ::assertSame ('2012-12-12 ' , $ row ['col_date ' ]);
692683 self ::assertSame ('A ' , $ row ['col_string ' ]);
693684 self ::assertEquals (1 , $ row ['col_int ' ]);
694685 self ::assertEquals (-1 , $ row ['col_neg_int ' ]);
695686 self ::assertEquals ('-2.300 ' , $ row ['col_decimal ' ]);
696- self ::assertLessThan (5 , $ row ['diff_seconds ' ]);
697687 }
698688
699689 /**
0 commit comments