Unverified Commit 3a6110f2 authored by Marco Pivetta's avatar Marco Pivetta

Merge branch 'fix/#2794-revert-bc-break-preventing-datetimeimmutable-conversion'

Close #2794
parents 5cefa4d9 912b2b8b
...@@ -53,7 +53,7 @@ class DateTimeType extends Type ...@@ -53,7 +53,7 @@ class DateTimeType extends Type
return $value; return $value;
} }
if ($value instanceof \DateTime) { if ($value instanceof \DateTimeInterface) {
return $value->format($platform->getDateTimeFormatString()); return $value->format($platform->getDateTimeFormatString());
} }
...@@ -65,7 +65,7 @@ class DateTimeType extends Type ...@@ -65,7 +65,7 @@ class DateTimeType extends Type
*/ */
public function convertToPHPValue($value, AbstractPlatform $platform) public function convertToPHPValue($value, AbstractPlatform $platform)
{ {
if ($value === null || $value instanceof \DateTime) { if ($value === null || $value instanceof \DateTimeInterface) {
return $value; return $value;
} }
......
...@@ -71,7 +71,7 @@ class DateTimeTzType extends Type ...@@ -71,7 +71,7 @@ class DateTimeTzType extends Type
return $value; return $value;
} }
if ($value instanceof \DateTime) { if ($value instanceof \DateTimeInterface) {
return $value->format($platform->getDateTimeTzFormatString()); return $value->format($platform->getDateTimeTzFormatString());
} }
...@@ -83,7 +83,7 @@ class DateTimeTzType extends Type ...@@ -83,7 +83,7 @@ class DateTimeTzType extends Type
*/ */
public function convertToPHPValue($value, AbstractPlatform $platform) public function convertToPHPValue($value, AbstractPlatform $platform)
{ {
if ($value === null || $value instanceof \DateTime) { if ($value === null || $value instanceof \DateTimeInterface) {
return $value; return $value;
} }
......
...@@ -53,7 +53,7 @@ class DateType extends Type ...@@ -53,7 +53,7 @@ class DateType extends Type
return $value; return $value;
} }
if ($value instanceof \DateTime) { if ($value instanceof \DateTimeInterface) {
return $value->format($platform->getDateFormatString()); return $value->format($platform->getDateFormatString());
} }
...@@ -65,7 +65,7 @@ class DateType extends Type ...@@ -65,7 +65,7 @@ class DateType extends Type
*/ */
public function convertToPHPValue($value, AbstractPlatform $platform) public function convertToPHPValue($value, AbstractPlatform $platform)
{ {
if ($value === null || $value instanceof \DateTime) { if ($value === null || $value instanceof \DateTimeInterface) {
return $value; return $value;
} }
......
...@@ -53,7 +53,7 @@ class TimeType extends Type ...@@ -53,7 +53,7 @@ class TimeType extends Type
return $value; return $value;
} }
if ($value instanceof \DateTime) { if ($value instanceof \DateTimeInterface) {
return $value->format($platform->getTimeFormatString()); return $value->format($platform->getTimeFormatString());
} }
...@@ -65,7 +65,7 @@ class TimeType extends Type ...@@ -65,7 +65,7 @@ class TimeType extends Type
*/ */
public function convertToPHPValue($value, AbstractPlatform $platform) public function convertToPHPValue($value, AbstractPlatform $platform)
{ {
if ($value === null || $value instanceof \DateTime) { if ($value === null || $value instanceof \DateTimeInterface) {
return $value; return $value;
} }
......
...@@ -70,6 +70,35 @@ abstract class BaseDateTypeTestCase extends PHPUnit_Framework_TestCase ...@@ -70,6 +70,35 @@ abstract class BaseDateTypeTestCase extends PHPUnit_Framework_TestCase
$this->assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); $this->assertSame($date, $this->type->convertToPHPValue($date, $this->platform));
} }
/**
* @group #2794
*
* Note that while \@see \DateTimeImmutable is supposed to be handled
* by @see \Doctrine\DBAL\Types\DateTimeImmutableType, previous DBAL versions handled it just fine.
* This test is just in place to prevent further regressions, even if the type is being misused
*/
public function testConvertDateTimeImmutableToPHPValue()
{
$date = new \DateTimeImmutable('now');
self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform));
}
/**
* @group #2794
*
* Note that while \@see \DateTimeImmutable is supposed to be handled
* by @see \Doctrine\DBAL\Types\DateTimeImmutableType, previous DBAL versions handled it just fine.
* This test is just in place to prevent further regressions, even if the type is being misused
*/
public function testDateTimeImmutableConvertsToDatabaseValue()
{
self::assertInternalType(
'string',
$this->type->convertToDatabaseValue(new \DateTimeImmutable(), $this->platform)
);
}
/** /**
* @return mixed[][] * @return mixed[][]
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment