From 8618bbd7c4614e507d1755a0513c66282633787b Mon Sep 17 00:00:00 2001 From: Moritz Ringler Date: Wed, 29 Jun 2022 15:20:03 +0200 Subject: [PATCH] allow datetime type columns (#1890) * added datetime type * enable TIMESTAMP type in mysql --- .../I18nBehaviorObjectBuilderModifier.php | 1 + .../Builder/Om/AbstractObjectBuilder.php | 2 + .../Generator/Builder/Om/ObjectBuilder.php | 71 +++++++++++-------- src/Propel/Generator/Model/PropelTypes.php | 15 ++++ .../Generator/Platform/MssqlPlatform.php | 1 + .../Generator/Platform/MysqlPlatform.php | 1 - .../Generator/Platform/OraclePlatform.php | 1 + .../Generator/Platform/PgsqlPlatform.php | 1 + .../Generator/Platform/SqlitePlatform.php | 1 + .../Generator/Reverse/MysqlSchemaParser.php | 2 +- .../Generator/Reverse/SqliteSchemaParser.php | 2 +- src/Propel/Generator/Util/QuickBuilder.php | 2 +- src/Propel/Runtime/Adapter/Pdo/PdoAdapter.php | 1 + src/Propel/Runtime/Map/ColumnMap.php | 1 + .../GeneratedObjectTemporalColumnTypeTest.php | 51 ++++++------- .../Tests/Generator/Migration/BaseTest.php | 7 ++ .../Platform/DefaultPlatformTest.php | 1 + .../Generator/Platform/MysqlPlatformTest.php | 17 +++++ 18 files changed, 116 insertions(+), 62 deletions(-) diff --git a/src/Propel/Generator/Behavior/I18n/I18nBehaviorObjectBuilderModifier.php b/src/Propel/Generator/Behavior/I18n/I18nBehaviorObjectBuilderModifier.php index ca27be4900..1b22b6be89 100644 --- a/src/Propel/Generator/Behavior/I18n/I18nBehaviorObjectBuilderModifier.php +++ b/src/Propel/Generator/Behavior/I18n/I18nBehaviorObjectBuilderModifier.php @@ -311,6 +311,7 @@ protected function isDateType(string $columnType): bool { return in_array($columnType, [ PropelTypes::DATE, + PropelTypes::DATETIME, PropelTypes::TIME, PropelTypes::TIMESTAMP, ], true); diff --git a/src/Propel/Generator/Builder/Om/AbstractObjectBuilder.php b/src/Propel/Generator/Builder/Om/AbstractObjectBuilder.php index 250013c15d..ae72f48bcf 100644 --- a/src/Propel/Generator/Builder/Om/AbstractObjectBuilder.php +++ b/src/Propel/Generator/Builder/Om/AbstractObjectBuilder.php @@ -39,6 +39,7 @@ protected function addColumnAccessorMethods(string &$script): void // if they're not using the DateTime class then we will generate "compatibility" accessor method if ( $type === PropelTypes::DATE + || $type === PropelTypes::DATETIME || $type === PropelTypes::TIME || $type === PropelTypes::TIMESTAMP ) { @@ -90,6 +91,7 @@ protected function addColumnMutatorMethods(string &$script): void $this->addLobMutator($script, $col); } elseif ( $col->getType() === PropelTypes::DATE + || $col->getType() === PropelTypes::DATETIME || $col->getType() === PropelTypes::TIME || $col->getType() === PropelTypes::TIMESTAMP ) { diff --git a/src/Propel/Generator/Builder/Om/ObjectBuilder.php b/src/Propel/Generator/Builder/Om/ObjectBuilder.php index 7a0e56d74f..dd06775281 100644 --- a/src/Propel/Generator/Builder/Om/ObjectBuilder.php +++ b/src/Propel/Generator/Builder/Om/ObjectBuilder.php @@ -149,6 +149,7 @@ protected function getTemporalFormatter(Column $column): ?string case PropelTypes::TIME: return $this->getPlatformOrFail()->getTimeFormatter(); case PropelTypes::TIMESTAMP: + case PropelTypes::DATETIME: return $this->getPlatformOrFail()->getTimestampFormatter(); default: return null; @@ -885,7 +886,7 @@ public function addTemporalAccessorComment(string &$script, Column $column): voi $handleMysqlDate = false; $mysqlInvalidDateString = ''; if ($this->getPlatform() instanceof MysqlPlatform) { - if ($column->getType() === PropelTypes::TIMESTAMP) { + if (in_array($column->getType(), [PropelTypes::TIMESTAMP, PropelTypes::DATETIME], true)) { $handleMysqlDate = true; $mysqlInvalidDateString = '0000-00-00 00:00:00'; } elseif ($column->getType() === PropelTypes::DATE) { @@ -915,6 +916,43 @@ public function addTemporalAccessorComment(string &$script, Column $column): voi */"; } + /** + * Gets the default format for a temporal column from the configuration + * + * @param \Propel\Generator\Model\Column $column + * + * @return string|null + */ + protected function getTemporalTypeDefaultFormat(Column $column): ?string + { + $configKey = $this->getTemporalTypeDefaultFormatConfigKey($column); + + return $configKey ? $this->getBuildProperty($configKey) : null; + } + + /** + * Knows which key in the configuration holds the default format for a + * temporal type column. + * + * @param \Propel\Generator\Model\Column $column + * + * @return string|null + */ + protected function getTemporalTypeDefaultFormatConfigKey(Column $column): ?string + { + switch ($column->getType()) { + case PropelTypes::DATE: + return 'generator.dateTime.defaultDateFormat'; + case PropelTypes::TIME: + return 'generator.dateTime.defaultTimeFormat'; + case PropelTypes::TIMESTAMP: + case PropelTypes::DATETIME: + return 'generator.dateTime.defaultTimeStampFormat'; + default: + return null; + } + } + /** * Adds the function declaration for a temporal accessor. * @@ -927,22 +965,9 @@ public function addTemporalAccessorOpen(string &$script, Column $column): void { $cfc = $column->getPhpName(); - $defaultfmt = null; + $defaultfmt = $this->getTemporalTypeDefaultFormat($column); $visibility = $column->getAccessorVisibility(); - // Default date/time formatter strings are specified in propel config - if ($column->getType() === PropelTypes::DATE) { - $defaultfmt = $this->getBuildProperty('generator.dateTime.defaultDateFormat'); - } elseif ($column->getType() === PropelTypes::TIME) { - $defaultfmt = $this->getBuildProperty('generator.dateTime.defaultTimeFormat'); - } elseif ($column->getType() === PropelTypes::TIMESTAMP) { - $defaultfmt = $this->getBuildProperty('generator.dateTime.defaultTimeStampFormat'); - } - - if (!$defaultfmt) { - $defaultfmt = null; - } - $format = var_export($defaultfmt, true); if ($format === 'NULL') { $format = 'null'; @@ -999,20 +1024,6 @@ protected function addTemporalAccessorBody(string &$script, Column $column): voi $dateTimeClass = $this->getDateTimeClass($column); $this->declareClasses($dateTimeClass); - $defaultfmt = null; - - // Default date/time formatter strings are specified in propel config - if ($column->getType() === PropelTypes::DATE) { - $defaultfmt = $this->getBuildProperty('generator.dateTime.defaultDateFormat'); - } elseif ($column->getType() === PropelTypes::TIME) { - $defaultfmt = $this->getBuildProperty('generator.dateTime.defaultTimeFormat'); - } elseif ($column->getType() === PropelTypes::TIMESTAMP) { - $defaultfmt = $this->getBuildProperty('generator.dateTime.defaultTimeStampFormat'); - } - - if (!$defaultfmt) { - $defaultfmt = null; - } if ($column->isLazyLoad()) { $script .= $this->getAccessorLazyLoadSnippet($column); @@ -2688,7 +2699,7 @@ protected function addHydrateBody(string &$script): void $dateTimeClass = $this->getDateTimeClass($col); $handleMysqlDate = false; if ($this->getPlatform() instanceof MysqlPlatform) { - if ($col->getType() === PropelTypes::TIMESTAMP) { + if (in_array($col->getType(), [PropelTypes::TIMESTAMP, PropelTypes::DATETIME], true)) { $handleMysqlDate = true; $mysqlInvalidDateString = '0000-00-00 00:00:00'; } elseif ($col->getType() === PropelTypes::DATE) { diff --git a/src/Propel/Generator/Model/PropelTypes.php b/src/Propel/Generator/Model/PropelTypes.php index 1563110755..cf364f7a84 100644 --- a/src/Propel/Generator/Model/PropelTypes.php +++ b/src/Propel/Generator/Model/PropelTypes.php @@ -116,6 +116,11 @@ class PropelTypes */ public const DATE = 'DATE'; + /** + * @var string + */ + public const DATETIME = 'DATETIME'; + /** * @var string */ @@ -276,6 +281,11 @@ class PropelTypes */ public const DATE_NATIVE_TYPE = 'string'; + /** + * @var string + */ + public const DATETIME_NATIVE_TYPE = 'string'; + /** * @var string */ @@ -355,6 +365,7 @@ class PropelTypes self::LONGVARBINARY, self::BLOB, self::DATE, + self::DATETIME, self::TIME, self::TIMESTAMP, self::BOOLEAN, @@ -397,6 +408,7 @@ class PropelTypes self::LONGVARBINARY => self::LONGVARBINARY_NATIVE_TYPE, self::BLOB => self::BLOB_NATIVE_TYPE, self::DATE => self::DATE_NATIVE_TYPE, + self::DATETIME => self::DATETIME_NATIVE_TYPE, self::BU_DATE => self::BU_DATE_NATIVE_TYPE, self::TIME => self::TIME_NATIVE_TYPE, self::TIMESTAMP => self::TIMESTAMP_NATIVE_TYPE, @@ -437,6 +449,7 @@ class PropelTypes self::LONGVARBINARY => PDO::PARAM_LOB, self::BLOB => PDO::PARAM_LOB, self::DATE => PDO::PARAM_STR, + self::DATETIME => PDO::PARAM_STR, self::TIME => PDO::PARAM_STR, self::TIMESTAMP => PDO::PARAM_STR, self::BOOLEAN => PDO::PARAM_BOOL, @@ -524,6 +537,7 @@ public static function isTemporalType(string $type): bool { return in_array($type, [ self::DATE, + self::DATETIME, self::TIME, self::TIMESTAMP, self::BU_DATE, @@ -546,6 +560,7 @@ public static function isTextType(string $mappingType): bool self::LONGVARCHAR, self::CLOB, self::DATE, + self::DATETIME, self::TIME, self::TIMESTAMP, self::BU_DATE, diff --git a/src/Propel/Generator/Platform/MssqlPlatform.php b/src/Propel/Generator/Platform/MssqlPlatform.php index 7dfa925e00..ba5e33c462 100644 --- a/src/Propel/Generator/Platform/MssqlPlatform.php +++ b/src/Propel/Generator/Platform/MssqlPlatform.php @@ -44,6 +44,7 @@ protected function initialize(): void $this->setSchemaDomainMapping(new Domain(PropelTypes::LONGVARCHAR, 'VARCHAR(MAX)')); $this->setSchemaDomainMapping(new Domain(PropelTypes::CLOB, 'VARCHAR(MAX)')); $this->setSchemaDomainMapping(new Domain(PropelTypes::DATE, 'DATE')); + $this->setSchemaDomainMapping(new Domain(PropelTypes::DATETIME, 'DATETIME2')); $this->setSchemaDomainMapping(new Domain(PropelTypes::BU_DATE, 'DATE')); $this->setSchemaDomainMapping(new Domain(PropelTypes::TIME, 'TIME')); $this->setSchemaDomainMapping(new Domain(PropelTypes::TIMESTAMP, 'DATETIME2')); diff --git a/src/Propel/Generator/Platform/MysqlPlatform.php b/src/Propel/Generator/Platform/MysqlPlatform.php index c5a7678d5c..3c95f79958 100644 --- a/src/Propel/Generator/Platform/MysqlPlatform.php +++ b/src/Propel/Generator/Platform/MysqlPlatform.php @@ -60,7 +60,6 @@ protected function initialize(): void $this->setSchemaDomainMapping(new Domain(PropelTypes::VARBINARY, 'MEDIUMBLOB')); $this->setSchemaDomainMapping(new Domain(PropelTypes::LONGVARBINARY, 'LONGBLOB')); $this->setSchemaDomainMapping(new Domain(PropelTypes::CLOB, 'LONGTEXT')); - $this->setSchemaDomainMapping(new Domain(PropelTypes::TIMESTAMP, 'DATETIME')); $this->setSchemaDomainMapping(new Domain(PropelTypes::OBJECT, 'MEDIUMBLOB')); $this->setSchemaDomainMapping(new Domain(PropelTypes::PHP_ARRAY, 'TEXT')); $this->setSchemaDomainMapping(new Domain(PropelTypes::ENUM, 'TINYINT')); diff --git a/src/Propel/Generator/Platform/OraclePlatform.php b/src/Propel/Generator/Platform/OraclePlatform.php index 9941d142d7..2df48ba199 100644 --- a/src/Propel/Generator/Platform/OraclePlatform.php +++ b/src/Propel/Generator/Platform/OraclePlatform.php @@ -51,6 +51,7 @@ protected function initialize(): void $this->setSchemaDomainMapping(new Domain(PropelTypes::LONGVARCHAR, 'NVARCHAR2', 2000)); $this->setSchemaDomainMapping(new Domain(PropelTypes::TIME, 'DATE')); $this->setSchemaDomainMapping(new Domain(PropelTypes::DATE, 'DATE')); + $this->setSchemaDomainMapping(new Domain(PropelTypes::DATETIME, 'TIMESTAMP')); $this->setSchemaDomainMapping(new Domain(PropelTypes::TIMESTAMP, 'TIMESTAMP')); $this->setSchemaDomainMapping(new Domain(PropelTypes::BINARY, 'LONG RAW')); $this->setSchemaDomainMapping(new Domain(PropelTypes::VARBINARY, 'BLOB')); diff --git a/src/Propel/Generator/Platform/PgsqlPlatform.php b/src/Propel/Generator/Platform/PgsqlPlatform.php index 6a7c1f5dac..96481f944f 100755 --- a/src/Propel/Generator/Platform/PgsqlPlatform.php +++ b/src/Propel/Generator/Platform/PgsqlPlatform.php @@ -61,6 +61,7 @@ protected function initialize(): void $this->setSchemaDomainMapping(new Domain(PropelTypes::ENUM, 'INT2')); $this->setSchemaDomainMapping(new Domain(PropelTypes::SET, 'INT4')); $this->setSchemaDomainMapping(new Domain(PropelTypes::DECIMAL, 'NUMERIC')); + $this->setSchemaDomainMapping(new Domain(PropelTypes::DATETIME, 'TIMESTAMP')); } /** diff --git a/src/Propel/Generator/Platform/SqlitePlatform.php b/src/Propel/Generator/Platform/SqlitePlatform.php index 0a1f86a511..78d356a177 100644 --- a/src/Propel/Generator/Platform/SqlitePlatform.php +++ b/src/Propel/Generator/Platform/SqlitePlatform.php @@ -62,6 +62,7 @@ protected function initialize(): void $this->setSchemaDomainMapping(new Domain(PropelTypes::NUMERIC, 'DECIMAL')); $this->setSchemaDomainMapping(new Domain(PropelTypes::LONGVARCHAR, 'MEDIUMTEXT')); $this->setSchemaDomainMapping(new Domain(PropelTypes::DATE, 'DATETIME')); + $this->setSchemaDomainMapping(new Domain(PropelTypes::DATETIME, 'DATETIME')); $this->setSchemaDomainMapping(new Domain(PropelTypes::BINARY, 'BLOB')); $this->setSchemaDomainMapping(new Domain(PropelTypes::VARBINARY, 'MEDIUMBLOB')); $this->setSchemaDomainMapping(new Domain(PropelTypes::LONGVARBINARY, 'LONGBLOB')); diff --git a/src/Propel/Generator/Reverse/MysqlSchemaParser.php b/src/Propel/Generator/Reverse/MysqlSchemaParser.php index 77a64affd4..8041162150 100644 --- a/src/Propel/Generator/Reverse/MysqlSchemaParser.php +++ b/src/Propel/Generator/Reverse/MysqlSchemaParser.php @@ -55,7 +55,7 @@ class MysqlSchemaParser extends AbstractSchemaParser 'date' => PropelTypes::DATE, 'time' => PropelTypes::TIME, 'year' => PropelTypes::INTEGER, - 'datetime' => PropelTypes::TIMESTAMP, + 'datetime' => PropelTypes::DATETIME, 'timestamp' => PropelTypes::TIMESTAMP, 'tinyblob' => PropelTypes::BINARY, 'blob' => PropelTypes::BLOB, diff --git a/src/Propel/Generator/Reverse/SqliteSchemaParser.php b/src/Propel/Generator/Reverse/SqliteSchemaParser.php index e3bea913e5..ef506431ae 100644 --- a/src/Propel/Generator/Reverse/SqliteSchemaParser.php +++ b/src/Propel/Generator/Reverse/SqliteSchemaParser.php @@ -56,7 +56,7 @@ class SqliteSchemaParser extends AbstractSchemaParser 'date' => PropelTypes::DATE, 'time' => PropelTypes::TIME, 'year' => PropelTypes::INTEGER, - 'datetime' => PropelTypes::DATE, + 'datetime' => PropelTypes::DATETIME, 'timestamp' => PropelTypes::TIMESTAMP, 'tinyblob' => PropelTypes::BINARY, 'blob' => PropelTypes::BLOB, diff --git a/src/Propel/Generator/Util/QuickBuilder.php b/src/Propel/Generator/Util/QuickBuilder.php index 0d93c3bd3f..77e26d2715 100644 --- a/src/Propel/Generator/Util/QuickBuilder.php +++ b/src/Propel/Generator/Util/QuickBuilder.php @@ -344,7 +344,7 @@ public function updateDB(ConnectionInterface $con): ?Database } catch (Exception $e) { //echo $sql; //uncomment for better debugging throw new BuildException(sprintf( - "Can not execute SQL: \n%s\nFrom database: \n%s\n\nTo database: \n%s\n\nDiff:\n%s", + "Cannot execute SQL: \n%s\nFrom database: \n%s\n\nTo database: \n%s\n\nDiff:\n%s", $statement, $this->database, $database, diff --git a/src/Propel/Runtime/Adapter/Pdo/PdoAdapter.php b/src/Propel/Runtime/Adapter/Pdo/PdoAdapter.php index 7ec5c4f607..16b108d2d9 100644 --- a/src/Propel/Runtime/Adapter/Pdo/PdoAdapter.php +++ b/src/Propel/Runtime/Adapter/Pdo/PdoAdapter.php @@ -331,6 +331,7 @@ public function formatTemporalValue($value, ColumnMap $cMap): string switch ($cMap->getType()) { case PropelTypes::TIMESTAMP: case PropelTypes::BU_TIMESTAMP: + case PropelTypes::DATETIME: $value = $dt->format($this->getTimestampFormatter()); break; diff --git a/src/Propel/Runtime/Map/ColumnMap.php b/src/Propel/Runtime/Map/ColumnMap.php index 5a2804db54..5e8f38c8f1 100644 --- a/src/Propel/Runtime/Map/ColumnMap.php +++ b/src/Propel/Runtime/Map/ColumnMap.php @@ -243,6 +243,7 @@ public function isTemporal(): bool return in_array($this->type, [ PropelTypes::TIMESTAMP, PropelTypes::DATE, + PropelTypes::DATETIME, PropelTypes::TIME, PropelTypes::BU_DATE, PropelTypes::BU_TIMESTAMP, diff --git a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTemporalColumnTypeTest.php b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTemporalColumnTypeTest.php index e65be786d1..8c78de4c6e 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTemporalColumnTypeTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTemporalColumnTypeTest.php @@ -39,6 +39,7 @@ public function setUp(): void + EOF; @@ -112,45 +113,39 @@ public function testUnixTimestampValue() $r = new ComplexColumnTypeEntity5(); $r->setBar3(time()); $this->assertEquals(date('Y-m-d H:i'), $r->getBar3('Y-m-d H:i')); - } - - /** - * @return void - */ - public function testDatePersistence() - { + $r = new ComplexColumnTypeEntity5(); - $r->setBar1(new DateTime('1999-12-20')); - $r->save(); - ComplexColumnTypeEntity5TableMap::clearInstancePool(); - $r1 = ComplexColumnTypeEntity5Query::create()->findPk($r->getId()); - $this->assertEquals('1999-12-20', $r1->getBar1(null)->format('Y-m-d')); + $r->setDatetimecolumn(time()); + $this->assertEquals(date('Y-m-d H:i'), $r->getDatetimecolumn('Y-m-d H:i')); } - - /** - * @return void - */ - public function testTimePersistence() + + public function persistenceDataProvider() { - $r = new ComplexColumnTypeEntity5(); - $r->setBar2(strtotime('12:55')); - $r->save(); - ComplexColumnTypeEntity5TableMap::clearInstancePool(); - $r1 = ComplexColumnTypeEntity5Query::create()->findPk($r->getId()); - $this->assertEquals('12:55', $r1->getBar2(null)->format('H:i')); + return [ + // type description, column name , input date value, formatted input date, format + ['Date', 'Bar1', new DateTime('1999-12-20'), '1999-12-20', 'Y-m-d'], + ['Time', 'Bar2', strtotime('12:55'), '12:55', 'H:i'], + ['Timestamp', 'Bar3', new DateTime('1999-12-20 12:55'), '1999-12-20 12:55', 'Y-m-d H:i'], + ['Datetime', 'Datetimecolumn', new DateTime('2022-06-28 11:55'), '2022-06-28 11:55', 'Y-m-d H:i'], + ]; } - + /** - * @return void + * @dataProvider persistenceDataProvider */ - public function testTimestampPersistence() + public function testPersistence($typeDescription, $columnName, $inputDateValue, $formattedDate, $format) { $r = new ComplexColumnTypeEntity5(); - $r->setBar3(new DateTime('1999-12-20 12:55')); + $r->setByName($columnName, $inputDateValue); $r->save(); ComplexColumnTypeEntity5TableMap::clearInstancePool(); $r1 = ComplexColumnTypeEntity5Query::create()->findPk($r->getId()); - $this->assertEquals('1999-12-20 12:55', $r1->getBar3(null)->format('Y-m-d H:i')); + + $storedValue = $r1->getByName($columnName); + $this->assertInstanceOf(DateTime::class, $storedValue, "$typeDescription column should return DateTime objects"); + + $formattedReturnValue = $storedValue->format($format); + $this->assertEquals($formattedDate, $formattedReturnValue, "$typeDescription column: persisted value should match"); } /** diff --git a/tests/Propel/Tests/Generator/Migration/BaseTest.php b/tests/Propel/Tests/Generator/Migration/BaseTest.php index 314f299753..d51dcb1ea8 100644 --- a/tests/Propel/Tests/Generator/Migration/BaseTest.php +++ b/tests/Propel/Tests/Generator/Migration/BaseTest.php @@ -247,6 +247,9 @@ public function testColumnTypeChangeMoreComplex() + + + '; @@ -272,6 +275,10 @@ public function testColumnTypeChangeMoreComplex() + + + + '; diff --git a/tests/Propel/Tests/Generator/Platform/DefaultPlatformTest.php b/tests/Propel/Tests/Generator/Platform/DefaultPlatformTest.php index 5d9593fb2a..4912fc1388 100644 --- a/tests/Propel/Tests/Generator/Platform/DefaultPlatformTest.php +++ b/tests/Propel/Tests/Generator/Platform/DefaultPlatformTest.php @@ -179,6 +179,7 @@ public function getColumnBindingDataProvider(): array [$this->createColumn(PropelTypes::DATE, '2020-02-03'), '$stmt->bindValue(ID, ACCESSOR ? ACCESSOR->format("Y-m-d") : null, PDO::PARAM_STR);'], [$this->createColumn(PropelTypes::TIME, '11:01:03'), '$stmt->bindValue(ID, ACCESSOR ? ACCESSOR->format("H:i:s.u") : null, PDO::PARAM_STR);'], [$this->createColumn(PropelTypes::TIMESTAMP, '2020-02-03 11:01:03'), '$stmt->bindValue(ID, ACCESSOR ? ACCESSOR->format("Y-m-d H:i:s.u") : null, PDO::PARAM_STR);'], + [$this->createColumn(PropelTypes::DATETIME, '2022-06-28 11:01:03'), '$stmt->bindValue(ID, ACCESSOR ? ACCESSOR->format("Y-m-d H:i:s.u") : null, PDO::PARAM_STR);'], [$this->createColumn(PropelTypes::BLOB, 'BLOB'), '$stmt->bindValue(ID, ACCESSOR, PDO::PARAM_LOB);'], ]; } diff --git a/tests/Propel/Tests/Generator/Platform/MysqlPlatformTest.php b/tests/Propel/Tests/Generator/Platform/MysqlPlatformTest.php index c2192377b1..c9c8a9b179 100644 --- a/tests/Propel/Tests/Generator/Platform/MysqlPlatformTest.php +++ b/tests/Propel/Tests/Generator/Platform/MysqlPlatformTest.php @@ -18,6 +18,7 @@ use Propel\Generator\Model\Table; use Propel\Generator\Model\VendorInfo; use Propel\Generator\Platform\MysqlPlatform; +use Propel\Generator\Model\PropelTypes; class MysqlPlatformTest extends PlatformTestProvider { @@ -957,4 +958,20 @@ public function testNormalizeTable() $this->getPlatform()->normalizeTable($table); $this->assertEquals('`price` DECIMAL(10,3)', $this->getPlatform()->getColumnDDL($column)); } + + public function typeMappingDataProvider() + { + return [ + [PropelTypes::DATETIME, 'DATETIME'], + [PropelTypes::TIMESTAMP, 'TIMESTAMP'], + ]; + } + + /** + * @dataProvider typeMappingDataProvider + */ + public function testTypeMapping(string $propelDataType, string $expectedMysqlDataType){ + $actualMysqlDataType = $this->getPlatform()->getDomainForType($propelDataType)->getSqlType(); + $this->assertEquals($expectedMysqlDataType, $actualMysqlDataType); + } }