public function getObjectsToValidate()
 {
     $validStatement = new Statement();
     $validStatement->setId('12345678-1234-5678-8234-567812345678');
     $validStatement->setActor(new Agent());
     $validStatement->setVerb(new Verb());
     $validStatement->setObject(new Activity());
     $statementWithoutId = new Statement();
     $statementWithoutId->setActor(new Agent());
     $statementWithoutId->setVerb(new Verb());
     $statementWithoutId->setObject(new Activity());
     $statementWithNonUuidId = new Statement();
     $statementWithNonUuidId->setId('foo');
     $statementWithNonUuidId->setActor(new Agent());
     $statementWithNonUuidId->setVerb(new Verb());
     $statementWithNonUuidId->setObject(new Activity());
     $statementWithoutActor = new Statement();
     $statementWithoutActor->setId('12345678-1234-5678-8234-567812345678');
     $statementWithoutActor->setVerb(new Verb());
     $statementWithoutActor->setObject(new Activity());
     $statementWithoutVerb = new Statement();
     $statementWithoutVerb->setId('12345678-1234-5678-8234-567812345678');
     $statementWithoutVerb->setActor(new Agent());
     $statementWithoutVerb->setObject(new Activity());
     $statementWithoutObject = new Statement();
     $statementWithoutObject->setId('12345678-1234-5678-8234-567812345678');
     $statementWithoutObject->setActor(new Agent());
     $statementWithoutObject->setVerb(new Verb());
     return array(array(StatementFixtures::getMinimalStatement(), 0), array($validStatement, 0), array($statementWithoutId, 1), array($statementWithNonUuidId, 1), array($statementWithoutActor, 1), array($statementWithoutVerb, 1), array($statementWithoutObject, 1));
 }
 public function putStatement(StatementId $id, Statement $statement)
 {
     if (null !== $statement->getId() && !$id->equals($statement->getId())) {
         throw new ConflictException(sprintf('Id parameter ("%s") and statement id ("%s") do not match.', $id->getValue(), $statement->getId()->getValue()));
     }
     try {
         $existingStatement = $this->repository->findStatementById($id->getValue());
     } catch (NotFoundException $e) {
         $this->repository->storeStatement($statement, true);
     }
     return new Response('', 204);
 }
 /**
  * @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));
 }
Exemple #4
0
 public function testGetVoidStatement()
 {
     $actor = new Agent('mailto:xapi@adlnet.gov');
     $statement = new Statement('e05aa883-acaf-40ad-bf54-02c8ce485fb0', $actor, new Verb('verb-id'), new Activity());
     $voidStatement = $statement->getVoidStatement($actor);
     /** @var \Xabbuh\XApi\Model\StatementReference $statementReference */
     $statementReference = $voidStatement->getObject();
     $this->assertEquals($actor, $voidStatement->getActor());
     $this->assertTrue($voidStatement->getVerb()->isVoidVerb());
     $this->assertInstanceOf('\\Xabbuh\\XApi\\Model\\StatementReference', $statementReference);
     $this->assertEquals('e05aa883-acaf-40ad-bf54-02c8ce485fb0', $statementReference->getStatementId());
 }
 public static function createFromModel(Statement $statement)
 {
     $mappedStatement = new MappedStatement();
     $mappedStatement->id = $statement->getId();
     $mappedStatement->actor = $statement->getActor();
     $mappedStatement->verb = MappedVerb::createFromModel($statement->getVerb());
     $mappedStatement->object = $statement->getObject();
     $mappedStatement->result = $statement->getResult();
     $mappedStatement->authority = $statement->getAuthority();
     $mappedStatement->created = $statement->getCreated();
     $mappedStatement->stored = $statement->getStored();
     return $mappedStatement;
 }
 /**
  * {@inheritdoc}
  */
 public final function storeStatement(Statement $statement, $flush = true)
 {
     if (null === $statement->getId()) {
         $statement = $statement->withId(StatementId::fromUuid(Uuid::uuid4()));
     }
     $mappedStatement = MappedStatement::fromModel($statement);
     $mappedStatement->stored = time();
     $this->repository->storeStatement($mappedStatement, $flush);
     return $statement->getId();
 }
 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;
 }
 /**
  * Writes a {@link Statement} to the underlying data storage.
  *
  * @param Statement $statement The statement to store
  * @param bool      $flush     Whether or not to flush the managed objects
  *                             immediately (i.e. write them to the data
  *                             storage)
  *
  * @return string The UUID of the created Statement
  */
 public final function storeStatement(Statement $statement, $flush = true)
 {
     $uuid = $statement->getId();
     $mappedStatement = MappedStatement::createFromModel($statement);
     $mappedStatement->stored = new \DateTime();
     if (null === $uuid) {
         $uuid = Uuid::uuid4()->toString();
         $mappedStatement->id = $uuid;
     }
     $this->storeMappedStatement($mappedStatement, $flush);
     return $uuid;
 }
 /**
  * @dataProvider statementProvider
  *
  * @param string    $serializedStatement
  * @param Statement $expectedStatement
  */
 public function testDeserializeStatement($serializedStatement, Statement $expectedStatement)
 {
     $statement = $this->statementSerializer->deserializeStatement($serializedStatement);
     $this->assertTrue($expectedStatement->equals($statement));
 }
 /**
  * {@inheritDoc}
  */
 public function voidStatement(Statement $statement, Actor $actor)
 {
     return $this->storeStatement($statement->getVoidStatement($actor));
 }
 private function assertStatementEquals(Statement $expected, Statement $actual, $validateId = true)
 {
     if ($validateId) {
         $this->assertSame($expected->getId(), $actual->getId());
     }
     $this->assertTrue($actual->getActor()->equals($expected->getActor()));
     $this->assertTrue($actual->getVerb()->equals($expected->getVerb()));
     $this->assertTrue($actual->getObject()->equals($expected->getObject()));
     if (null === $expected->getResult()) {
         $this->assertNull($actual->getResult());
     } else {
         $this->assertTrue($actual->getResult()->equals($expected->getResult()));
     }
     if (null === $expected->getAuthority()) {
         $this->assertNull($actual->getAuthority());
     } else {
         $this->assertTrue($actual->getAuthority()->equals($expected->getAuthority()));
     }
 }