/** * @dataProvider deserializeData */ public function testDeserializeStatement($json, Statement $expectedStatement) { $attachments = array(); if (null !== $expectedStatement->getAttachments()) { foreach ($expectedStatement->getAttachments() as $attachment) { $attachments[$attachment->getSha2()] = array('type' => $attachment->getContentType(), 'content' => $attachment->getContent()); } } $statement = $this->statementSerializer->deserializeStatement($json, $attachments); $this->assertInstanceOf('Xabbuh\\XApi\\Model\\Statement', $statement); $this->assertTrue($expectedStatement->equals($statement)); }
public static function fromModel(StatementModel $model) { $statement = new self(); $statement->id = $model->getId()->getValue(); $statement->actor = Object::fromModel($model->getActor()); $statement->verb = Verb::fromModel($model->getVerb()); $statement->object = Object::fromModel($model->getObject()); if (null !== $model->getTimestamp()) { $statement->created = $model->getTimestamp()->getTimestamp(); } if (null !== ($result = $model->getResult())) { $statement->result = Result::fromModel($result); } if (null !== ($authority = $model->getAuthority())) { $statement->authority = Object::fromModel($authority); } if (null !== ($context = $model->getContext())) { $statement->context = Context::fromModel($context); } if (null !== ($attachments = $model->getAttachments())) { $statement->hasAttachments = true; $statement->attachments = array(); foreach ($attachments as $attachment) { $mappedAttachment = Attachment::fromModel($attachment); $mappedAttachment->statement = $statement; $statement->attachments[] = $mappedAttachment; } } else { $statement->hasAttachments = false; } return $statement; }