public function testEncodeDecode_HistoricalDate_Same()
 {
     $model = new TestMongoDateModel();
     $model->date = new DateTime('2001-01-01');
     $encoded = MongoEncoder::encode($model);
     $this->assertIsA($encoded['date'], 'MongoDate');
     $otherModel = new TestMongoDateModel();
     MongoDecoder::decode($otherModel, $encoded);
     $iso8601 = $otherModel->date->format(DateTime::ISO8601);
     $this->assertEqual($model->date, $otherModel->date);
 }
 public function readSubDocument($model, $rootId, $property, $id)
 {
     CodeGuard::checkTypeAndThrow($rootId, 'string');
     CodeGuard::checkTypeAndThrow($id, 'string');
     $data = $this->_collection->findOne(array("_id" => self::mongoID($rootId)), array($property . '.' . $id));
     if ($data === NULL) {
         throw new \Exception("Could not find {$property}={$id} in {$rootId}");
     }
     // TODO Check this out on nested sub docs > 1
     $data = $data[$property][$id];
     MongoDecoder::decode($model, $data, $id);
 }
 /**
  * Sets the public properties of $model to values from $values[propertyName]
  * @param object $model
  * @param array $values A mixed array of JSON (like) data.
  */
 public static function decode($model, $values, $id = '')
 {
     $decoder = new MongoDecoder();
     $decoder->_decode($model, $values, $id);
 }