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);
 }