Commit bb2ffc4f authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-26 - Fix nasty bug with null values in Date, DateTime, DateTimeTz and...

DBAL-26 - Fix nasty bug with null values in Date, DateTime, DateTimeTz and Time fields introduced with the DBAL-22 fix
parent 1442262d
......@@ -46,8 +46,11 @@ class DateTimeType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
$val = ($value !== null)
? \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value) : null;
if (!$value) {
return $value;
}
$val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
}
......
......@@ -66,8 +66,11 @@ class DateTimeTzType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
$val = ($value !== null)
? \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value) : null;
if (!$value) {
return $value;
}
$val = \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
}
......
......@@ -46,8 +46,11 @@ class DateType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
$val = ($value !== null)
? \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value) : null;
if (!$value) {
return $value;
}
$val = \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
}
......
......@@ -55,8 +55,11 @@ class TimeType extends Type
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
$val = ($value !== null)
? \DateTime::createFromFormat($platform->getTimeFormatString(), $value) : null;
if (!$value) {
return $value;
}
$val = \DateTime::createFromFormat($platform->getTimeFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
}
......
......@@ -67,4 +67,9 @@ class DateTest extends \Doctrine\Tests\DbalTestCase
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
}
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
......@@ -42,4 +42,9 @@ class DateTimeTest extends \Doctrine\Tests\DbalTestCase
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
}
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
......@@ -42,4 +42,9 @@ class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
}
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
......@@ -39,4 +39,9 @@ class TimeTest extends \Doctrine\Tests\DbalTestCase
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
}
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
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