From f1f728f18c7d8dba146794586e52c275fa873574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 9 Sep 2017 17:40:16 +0200 Subject: [PATCH] Test default value declaration for the date type It was not covered, probably because it was hard to do something generic. I choose to duplicate some tests instead, so that things stay relatively simple. --- .../DBAL/Platforms/AbstractPlatformTestCase.php | 14 ++++++++++++++ .../DBAL/Platforms/SQLServer2008PlatformTest.php | 15 +++++++++++++++ .../DBAL/Platforms/SQLServer2012PlatformTest.php | 15 +++++++++++++++ .../DBAL/Platforms/SQLServerPlatformTest.php | 14 ++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index ba4646c475f..7942d213e07 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -563,6 +563,20 @@ public function testGetDefaultValueDeclarationSQLForIntegerTypes() } } + public function testGetDefaultValueDeclarationSQLForDateType() + { + $currentDateSql = $this->_platform->getCurrentDateSQL(); + $field = array( + 'type' => Type::getType('date'), + 'default' => $currentDateSql, + ); + + $this->assertEquals( + ' DEFAULT '.$currentDateSql, + $this->_platform->getDefaultValueDeclarationSQL($field) + ); + } + /** * @group DBAL-45 */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php index 5bebbd3196f..ed8a615c6d6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Platforms\SQLServer2008Platform; +use Doctrine\DBAL\Types\Type; class SQLServer2008PlatformTest extends AbstractSQLServerPlatformTestCase { @@ -19,4 +20,18 @@ public function testGeneratesTypeDeclarationForDateTimeTz() array()) ); } + + public function testGetDefaultValueDeclarationSQLForDateType() + { + $currentDateSql = $this->_platform->getCurrentDateSQL(); + $field = array( + 'type' => Type::getType('date'), + 'default' => $currentDateSql, + ); + + $this->assertEquals( + " DEFAULT '".$currentDateSql."'", + $this->_platform->getDefaultValueDeclarationSQL($field) + ); + } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php index 69e0840b629..61efbe8f30d 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Types\Type; class SQLServer2012PlatformTest extends AbstractSQLServerPlatformTestCase { @@ -371,4 +372,18 @@ public function testModifyLimitQueryWithNewlineBeforeOrderBy() $sql = $this->_platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); } + + public function testGetDefaultValueDeclarationSQLForDateType() + { + $currentDateSql = $this->_platform->getCurrentDateSQL(); + $field = array( + 'type' => Type::getType('date'), + 'default' => $currentDateSql, + ); + + $this->assertEquals( + " DEFAULT '".$currentDateSql."'", + $this->_platform->getDefaultValueDeclarationSQL($field) + ); + } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php index 5a0a0f7712f..dffb18b0977 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Platforms\SQLServerPlatform; +use Doctrine\DBAL\Types\Type; class SQLServerPlatformTest extends AbstractSQLServerPlatformTestCase { @@ -58,4 +59,17 @@ public function getModifyLimitQueries() ); } + public function testGetDefaultValueDeclarationSQLForDateType() + { + $currentDateSql = $this->_platform->getCurrentDateSQL(); + $field = array( + 'type' => Type::getType('date'), + 'default' => $currentDateSql, + ); + + $this->assertEquals( + " DEFAULT '".$currentDateSql."'", + $this->_platform->getDefaultValueDeclarationSQL($field) + ); + } }