Skip to content
Browse files

Merge pull request #787 from stephandesouza/master

Hydrator not acception DateTime objects on @ODM\Date fields
  • Loading branch information...
2 parents d598707 + 8e3b5fc commit dec2bdaabae36a4e84698ba944bfad2bfa2a539f @jmikola jmikola committed Jan 28, 2014
View
2 lib/Doctrine/ODM/MongoDB/Types/DateType.php
@@ -76,6 +76,6 @@ public function closureToMongo()
public function closureToPHP()
{
- return 'if ($value instanceof \MongoDate) { $return = new \DateTime(); $return->setTimestamp($value->sec); } elseif (is_numeric($value)) { $return = new \DateTime(); $return->setTimestamp($value); } else { $return = new \DateTime($value); }';
+ return 'if ($value instanceof \MongoDate) { $return = new \DateTime(); $return->setTimestamp($value->sec); } elseif (is_numeric($value)) { $return = new \DateTime(); $return->setTimestamp($value); } elseif ($value instanceof \DateTime) { $return = $value; } else { $return = new \DateTime($value); }';
}
}
View
5 tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php
@@ -14,6 +14,7 @@ public function testHydrator()
$this->dm->getHydratorFactory()->hydrate($user, array(
'_id' => 1,
'name' => 'jon',
+ 'birthdate' => new \DateTime('1961-01-01'),
'referenceOne' => array('$id' => '1'),
'referenceMany' => array(
array(
@@ -31,6 +32,7 @@ public function testHydrator()
$this->assertEquals(1, $user->id);
$this->assertEquals('jon', $user->name);
+ $this->assertInstanceOf('DateTime', $user->birthdate);
$this->assertInstanceOf(__NAMESPACE__.'\HydrationClosureReferenceOne', $user->referenceOne);
$this->assertInstanceOf('Doctrine\ODM\MongoDB\PersistentCollection', $user->referenceMany);
$this->assertInstanceOf('Doctrine\ODM\MongoDB\Proxy\Proxy', $user->referenceMany[0]);
@@ -49,6 +51,9 @@ class HydrationClosureUser
/** @ODM\String */
public $name;
+
+ /** @ODM\Date */
+ public $birthdate;
/** @ODM\ReferenceOne(targetDocument="HydrationClosureReferenceOne") */
public $referenceOne;

0 comments on commit dec2bda

Please sign in to comment.
Something went wrong with that request. Please try again.