Browse Source

Allow BC for nullish DB values as strings.

Mark Scherer 11 years ago
parent
commit
960d3dfbe0

+ 1 - 1
src/Database/Type/DateTimeType.php

@@ -103,7 +103,7 @@ class DateTimeType extends Type
      */
     public function toPHP($value, Driver $driver)
     {
-        if ($value === null) {
+        if ($value === null || (int)$value === 0) {
             return null;
         }
 

+ 1 - 0
tests/TestCase/Database/Type/DateTimeTypeTest.php

@@ -65,6 +65,7 @@ class DateTimeTypeTest extends TestCase
     public function testToPHP()
     {
         $this->assertNull($this->type->toPHP(null, $this->driver));
+        $this->assertNull($this->type->toPHP('0000-00-00 00:00:00', $this->driver));
 
         $result = $this->type->toPHP('2001-01-04 12:13:14', $this->driver);
         $this->assertInstanceOf('Cake\I18n\Time', $result);

+ 1 - 0
tests/TestCase/Database/Type/DateTypeTest.php

@@ -45,6 +45,7 @@ class DateTypeTest extends TestCase
     public function testToPHP()
     {
         $this->assertNull($this->type->toPHP(null, $this->driver));
+        $this->assertNull($this->type->toPHP('0000-00-00', $this->driver));
 
         $result = $this->type->toPHP('2001-01-04', $this->driver);
         $this->assertInstanceOf('DateTime', $result);