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); }
/** * Create document from array * * @param mixed[] $data * @param string|object $className * @param AnnotatedInterface $instance * @return AnnotatedInterface * @throws TransformatorException */ public static function toModel($data, $className = null, AnnotatedInterface $instance = null) { $data = (new \Dmtx\Reader())->decode($data); return YamlString::toModel($data, $className, $instance); }