public function testEncodeDecodeUniversalTimestamp_HistoricalDate_Same()
 {
     $model = new TestMongoDateModel();
     $model->universalTimestamp = UniversalTimestamp::fromStringTimestamp('2001-01-01 12:01:01.321');
     $encoded = MongoEncoder::encode($model);
     $this->assertInstanceOf(UTCDateTime::class, $encoded['universalTimestamp']);
     //        var_dump($encoded);
     $decodedModel = new TestMongoDateModel();
     MongoDecoder::decode($decodedModel, $encoded);
     $this->assertEquals($model->universalTimestamp, $decodedModel->universalTimestamp);
     //        $iso8601 = $decodedModel->universalTimestamp->asFormattedString(UniversalTimestamp::ISO8601_WITH_MILLISECONDS);
     //        var_dump($iso8601);
 }
 /**
  * @param object $model
  * @param string $id
  * @param int $keyStyle
  * @param string $rootId
  * @param string $property
  * @see ID_IN_KEY
  * @see ID_IN_DOC
  * @return string
  * @throws \Exception
  */
 public function write($model, $id, $keyStyle = MongoMapper::ID_IN_KEY, $rootId = '', $property = '')
 {
     CodeGuard::checkTypeAndThrow($rootId, 'string');
     CodeGuard::checkTypeAndThrow($property, 'string');
     CodeGuard::checkTypeAndThrow($id, 'string');
     $data = MongoEncoder::encode($model);
     // TODO Take into account key style for stripping key out of the model if needs be
     if (empty($rootId)) {
         // We're doing a root level update, only $model, $id are relevant
         $id = $this->update($data, $id, self::ID_IN_KEY, '', '');
     } else {
         if ($keyStyle == self::ID_IN_KEY) {
             CodeGuard::checkNullAndThrow($id, 'id');
             $id = $this->update($data, $id, self::ID_IN_KEY, $rootId, $property);
         } else {
             if (empty($id)) {
                 // TODO would be nice if the encode above gave us the id it generated so we could return it to be consistent. CP 2013-08
                 throw new \Exception("Method appendSubDocument() is not implemented");
                 //$this->appendSubDocument($data, $rootId, $property);
             } else {
                 $id = $this->update($data, $id, self::ID_IN_DOC, $rootId, $property);
             }
         }
     }
     return $id;
 }