예제 #1
0
 public function testIfWillConvertToYamlAndViceVerseModelWithEmbeddedDocument()
 {
     $model = new WithPlainEmbedded();
     $model->_id = new MongoId();
     $stats = new SimplePlainEmbedded();
     $stats->name = "YAML Stats";
     $model->stats = $stats;
     $model->title = 'YAML';
     $yaml = YamlString::fromModel($model);
     codecept_debug($yaml);
     $model2 = YamlString::toModel($yaml);
     $stats2 = $model2->stats;
     $this->assertInstanceOf(WithPlainEmbedded::class, $model2);
     $this->assertSame($model->title, $model2->title);
     $this->assertSame((string) $model->_id, (string) $model2->_id);
     $this->assertInstanceOf(SimplePlainEmbedded::class, $stats2);
     $this->assertSame($stats->name, $stats2->name);
 }
예제 #2
0
 /**
  * Returns the given object as an associative array
  * @param AnnotatedInterface|object $model
  * @param string[] $fields Fields to transform
  * @return array an associative array of the contents of this object
  */
 public static function fromModel(AnnotatedInterface $model, $fields = [])
 {
     $data = YamlString::fromModel($model, $fields, 1, 1);
     return (new \Dmtx\Writer())->encode($data)->dump();
 }