This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

4
vendor/php-xapi/serializer/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/composer.lock
/phpunit.xml
/phpspec.xml
/vendor

34
vendor/php-xapi/serializer/.travis.yml vendored Normal file
View File

@@ -0,0 +1,34 @@
sudo: false
language: php
cache:
directories:
- $HOME/.composer/cache/files
php:
- 5.4
- 5.5
- 5.6
- 7.1
matrix:
fast_finish: true
include:
- php: 5.3
dist: precise
env: COMPOSER_OPTIONS="--prefer-lowest --prefer-stable"
- php: 7.0
- php: 7.2
env: deps="high"
before_install:
- phpenv config-rm xdebug.ini
- composer self-update
install:
- if [ "$deps" = "high" ]; then composer config minimum-stability dev; fi
- composer update $COMPOSER_OPTIONS
script:
- vendor/bin/phpspec run

150
vendor/php-xapi/serializer/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,150 @@
CHANGELOG
=========
2.2.0
-----
* allow `3.x` releases of the `php-xapi/model` package too
* dropped support for HHVM
2.1.0
-----
* allow `2.x` releases of the `php-xapi/model` package too
2.0.0
-----
Raw attachment content data must be passed in order to make it possible for
serializer implementations to populate the `$content` attribute of `Attachment`
objects during deserialization.
In order to achieve this an optional `$attachments` argument has been added
to the `StatementResultSerializerInterface::deserializeStatementResult()`,
and the `deserializeStatement()` and `deserializeStatements()` methods of
the `StatementSerializerInterface`.
When being passed, this argument must be an array mapping SHA-2 hashes to an
array which in turn maps the `type` and `content` keys to the attachment's
content type and raw content data respectively.
1.0.0
-----
This is the first stable release of the Experience API serialization API.
In terms of functions, there are no differences to the `0.4.0` release, but
required versions of the `php-xapi` packages each have been bumped to `^1.0`.
0.4.0
-----
* The serializer implementation has been separated from its API definition.
This package now no longer ships with an implementation.
The Symfony Serializer component integration has been moved to the separate
[php-xapi/symfony-serializer package](https://github.com/php-xapi/symfony-serializer).
A default implementation of the `SerializerRegistryInterface` is still part
of the `php-xapi/serializer` package though.
This package ships with the following interfaces that must be implemented
by packages that want to provide the xAPI serialization functionality:
* `ActorSerializerInterface`
* `DocumentDataSerializerInterface`
* `StatementResultSerializerInterface`
* `StatementSerializerInterface`
* `StatementFactoryInterface`
Implementors of the API provided by this package are advised to add the
`php-xapi/serializer-implementation` package to the `provide` section of
their `composer.json` file.
The `Tests` subnamespace of this package contains a set of base abstract
PHPUnit test classes integrators can use to make sure that their implementation
adheres to the API specified by the `php-xapi/serializer` package.
* Added a `SerializerFactoryInterface` that abstracts the creation of serializer
instances.
* The `SerializerRegistry` class is now final. If you need custom behavior
inside the serializer registry, create your own implementation of the
`SerializerRegistryInterface`.
0.3.0
-----
* Normalization and denormalization support for `IRI` and `IRL` instances
where they have been introduced in the `php-xapi/model` package.
* Fixed that context attributes are no longer ignored when statements are
normalized/denormalized.
* Added support for normalizing/denormalizing activity definition extensions.
* Added support for normalizing/denormalizing statement activity interactions.
* Added support for normalizing/denormalizing `LanguageMap` instances which
is now the data type for the `$display` property of the `Verb` class as
well as for the `$name` and `$description` properties of the `Definition`
class.
* Updated how statement ids are normalized/denormalized to reflect the introduction
of the `StatementId` value object in the `php-xapi/model` package.
* Added support for normalizing and denormalizing statement contexts, context
activities, and extensions.
* Properly denormalize statement objects (activities, agents, groups, statement
references, and sub statements).
0.2.2
-----
* Added support for (de)serializing a statement's `timestamp` and `stored`
properties.
0.2.1
-----
* The object type is now optional. When the `objectType` key is omitted while an
object is deserialized, it is to be assumed that the type of the denormalized
object is activity.
* Empty PHP arrays are now dumped as JSON objects instead of empty lists.
* fixed the key of the mbox SHA1 sum property when denormalizing actors
* fixed deserializing incomplete agent objects that are missing the required
IRI (the `ActorNormalizer` wil now throw an exception)
* add a `FilterNullValueNormalizer` that prevents `null` values from being
serialized
* empty group member lists are not normalized, but the property will be omitted
* ignore nullable result properties when they are not set during normalization
and denormalization
0.2.0
-----
* made the package compatible with version 0.2 of the `php-xapi/model` package
* replaced the JMS Serializer with the Symfony Serializer component
0.1.1
-----
* restrict dependency versions to not pull in potentially BC breaking package
versions
0.1.0
-----
First release leveraging the JMS serializer library to convert xAPI model
objects into JSON strings confirming to the xAPI specs and vice versa.
This package replaces the `xabbuh/xapi-serializer` package which is now deprecated
and should no longer be used.

19
vendor/php-xapi/serializer/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2014-2017 Christian Flothmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

9
vendor/php-xapi/serializer/README.md vendored Normal file
View File

@@ -0,0 +1,9 @@
xApi Serializer
===============
[![Build Status](https://travis-ci.org/php-xapi/serializer.svg?branch=master)](https://travis-ci.org/php-xapi/serializer)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-xapi/serializer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/php-xapi/serializer/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/php-xapi/serializer/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/php-xapi/serializer/?branch=master)
Transform [Experience API](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md)
model objects into JSON strings conforming to the API specs and vice versa.

51
vendor/php-xapi/serializer/UPGRADE.md vendored Normal file
View File

@@ -0,0 +1,51 @@
UPGRADE
=======
Upgrading from 1.x to 2.0
-------------------------
Raw attachment content data must be passed in order to make it possible for
serializer implementiations to populate the `$content` attribute of `Attachment`
objects during deserialization.
In order to achieve this an optional `$attachments` argument has been added
to the `StatementResultSerializerInterface::deserializeStatementResult()`,
and the `deserializeStatement()` and `deserializeStatements()` methods of
the `StatementSerializerInterface`.
When being passed, this argument must be an array mapping SHA-2 hashes to an
array which in turn maps the `type` and `content` keys to the attachment's
content type and raw content data respectively.
Upgrading from 0.3 to 0.4
-------------------------
* The serializer implementation has been separated from its API definition.
This package now no longer ships with an implementation.
The Symfony Serializer component integration has been moved to the separate
[php-xapi/symfony-serializer package](https://github.com/php-xapi/symfony-serializer).
A default implementation of the `SerializerRegistryInterface` is still part
of the `php-xapi/serializer` package though.
This package ships with the following interfaces that must be implemented
by packages that want to provide the xAPI serialization functionality:
* `ActorSerializerInterface`
* `DocumentDataSerializerInterface`
* `StatementResultSerializerInterface`
* `StatementSerializerInterface`
* `StatementFactoryInterface`
Implementors of the API provided by this package are advised to add the
`php-xapi/serializer-implementation` package to the `provide` section of
their `composer.json` file.
The `Tests` subnamespace of this package contains a set of base abstract
PHPUnit test classes integrators can use to make sure that their implementation
adheres to the API specified by the `php-xapi/serializer` package.
* The `SerializerRegistry` class is now final. If you need custom behavior
inside the serializer registry, create your own implementation of the
`SerializerRegistryInterface`.

View File

@@ -0,0 +1,38 @@
{
"name": "php-xapi/serializer",
"type": "library",
"description": "transform Experience API model objects to JSON strings and vice versa",
"keywords": ["xAPI", "Experience API", "Tin Can API", "serializer"],
"homepage": "https://github.com/php-xapi/serializer",
"license": "MIT",
"authors": [
{
"name": "Christian Flothmann",
"homepage": "https://github.com/xabbuh"
}
],
"require": {
"php": ">=5.3.0",
"php-xapi/json-test-fixtures": "^2.0",
"php-xapi/model": "^1.1 || ^2.0 || ^3.0",
"php-xapi/test-fixtures": "^1.0.1"
},
"require-dev": {
"phpspec/phpspec": "^2.3"
},
"conflict": {
"xabbuh/xapi-serializer": "*"
},
"autoload": {
"psr-4": {
"spec\\Xabbuh\\XApi\\Serializer\\": "spec/",
"Xabbuh\\XApi\\Serializer\\": "src/",
"Xabbuh\\XApi\\Serializer\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"2.x-dev": "2.2.x-dev"
}
}
}

View File

@@ -0,0 +1,4 @@
suites:
default:
namespace: Xabbuh\XApi\Serializer
psr4_prefix: Xabbuh\XApi\Serializer

View File

@@ -0,0 +1,28 @@
<?php
namespace spec\Xabbuh\XApi\Serializer;
use PhpSpec\ObjectBehavior;
abstract class SerializerFactoryInterfaceSpec extends ObjectBehavior
{
function it_creates_a_statement_serializer()
{
$this->createStatementSerializer()->shouldHaveType('Xabbuh\XApi\Serializer\StatementSerializerInterface');
}
function it_creates_a_statement_result_serializer()
{
$this->createStatementResultSerializer()->shouldHaveType('Xabbuh\XApi\Serializer\StatementResultSerializerInterface');
}
function it_creates_an_actor_serializer()
{
$this->createActorSerializer()->shouldHaveType('Xabbuh\XApi\Serializer\ActorSerializerInterface');
}
function it_creates_a_document_data_serializer()
{
$this->createDocumentDataSerializer()->shouldHaveType('Xabbuh\XApi\Serializer\DocumentDataSerializerInterface');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace spec\Xabbuh\XApi\Serializer;
use PhpSpec\ObjectBehavior;
use Xabbuh\XApi\Serializer\ActorSerializerInterface;
use Xabbuh\XApi\Serializer\DocumentDataSerializerInterface;
use Xabbuh\XApi\Serializer\StatementResultSerializerInterface;
use Xabbuh\XApi\Serializer\StatementSerializerInterface;
class SerializerRegistrySpec extends ObjectBehavior
{
function it_is_a_serializer_registry()
{
$this->shouldHaveType('Xabbuh\XApi\Serializer\SerializerRegistryInterface');
}
function it_stores_a_statement_serializer_for_later_retrieval(StatementSerializerInterface $statementSerializer)
{
$this->setStatementSerializer($statementSerializer);
$this->getStatementSerializer()->shouldReturn($statementSerializer);
}
function it_stores_a_statement_result_serializer_for_later_retrieval(StatementResultSerializerInterface $statementResultSerializer)
{
$this->setStatementResultSerializer($statementResultSerializer);
$this->getStatementResultSerializer()->shouldReturn($statementResultSerializer);
}
function it_stores_an_actor_serializer_for_later_retrieval(ActorSerializerInterface $actorSerializer)
{
$this->setActorSerializer($actorSerializer);
$this->getActorSerializer()->shouldReturn($actorSerializer);
}
function it_stores_a_document_data_serializer_for_later_retrieval(DocumentDataSerializerInterface $documentDataSerializer)
{
$this->setDocumentDataSerializer($documentDataSerializer);
$this->getDocumentDataSerializer()->shouldReturn($documentDataSerializer);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer;
use Xabbuh\XApi\Model\Actor;
/**
* Serialize and deserialize {@link Actor actors}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
interface ActorSerializerInterface
{
/**
* Serializes an actor into a JSON encoded string.
*
* @param Actor $actor The actor to serialize
*
* @return string The serialized actor
*/
public function serializeActor(Actor $actor);
/**
* Parses a serialized actor.
*
* @param string $data The serialized actor
*
* @return Actor The parsed actor
*/
public function deserializeActor($data);
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer;
use Xabbuh\XApi\Model\DocumentData;
/**
* Serialize and deserialize {@link DocumentData document data}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
interface DocumentDataSerializerInterface
{
/**
* Serializes document data into a JSON encoded string.
*
* @param DocumentData $data The document data to serialize
*
* @return string The serialized document data
*/
public function serializeDocumentData(DocumentData $data);
/**
* Parses serialized document data.
*
* @param string $data The serialized document data
*
* @return DocumentData The parsed document data
*/
public function deserializeDocumentData($data);
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer;
/**
* Handles the creation of serializer objects.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
interface SerializerFactoryInterface
{
/**
* Creates a statement serializer.
*
* @return StatementSerializerInterface
*/
public function createStatementSerializer();
/**
* Creates a statement result serializer.
*
* @return StatementResultSerializerInterface
*/
public function createStatementResultSerializer();
/**
* Creates an actor serializer.
*
* @return ActorSerializerInterface
*/
public function createActorSerializer();
/**
* Creates a document data serializer.
*
* @return DocumentDataSerializerInterface
*/
public function createDocumentDataSerializer();
}

View File

@@ -0,0 +1,104 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer;
/**
* Registry containing all the serializers.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class SerializerRegistry implements SerializerRegistryInterface
{
/**
* @var StatementSerializerInterface The statement serializer
*/
private $statementSerializer;
/**
* @var StatementResultSerializerInterface The statement result serializer
*/
private $statementResultSerializer;
/**
* @var ActorSerializerInterface The actor serializer
*/
private $actorSerializer;
/**
* @var DocumentDataSerializerInterface The document data serializer
*/
private $documentDataSerializer;
/**
* {@inheritDoc}
*/
public function setStatementSerializer(StatementSerializerInterface $serializer)
{
$this->statementSerializer = $serializer;
}
/**
* {@inheritDoc}
*/
public function getStatementSerializer()
{
return $this->statementSerializer;
}
/**
* {@inheritDoc}
*/
public function setStatementResultSerializer(StatementResultSerializerInterface $serializer)
{
$this->statementResultSerializer = $serializer;
}
/**
* {@inheritDoc}
*/
public function getStatementResultSerializer()
{
return $this->statementResultSerializer;
}
/**
* {@inheritDoc}
*/
public function setActorSerializer(ActorSerializerInterface $serializer)
{
$this->actorSerializer = $serializer;
}
/**
* {@inheritDoc}
*/
public function getActorSerializer()
{
return $this->actorSerializer;
}
/**
* {@inheritDoc}
*/
public function setDocumentDataSerializer(DocumentDataSerializerInterface $serializer)
{
$this->documentDataSerializer = $serializer;
}
/**
* {@inheritDoc}
*/
public function getDocumentDataSerializer()
{
return $this->documentDataSerializer;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer;
/**
* Registry containing all the serializers.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
interface SerializerRegistryInterface
{
/**
* Sets the {@link StatementSerializerInterface statement serializer}.
*
* @param StatementSerializerInterface $serializer The serializer
*/
public function setStatementSerializer(StatementSerializerInterface $serializer);
/**
* Returns the {@link StatementSerializerInterface statement serializer}.
*
* @return StatementSerializerInterface|null The serializer
*/
public function getStatementSerializer();
/**
* Sets the {@link StatementResultSerializerInterface statement result serializer}.
*
* @param StatementResultSerializerInterface $serializer The serializer
*/
public function setStatementResultSerializer(StatementResultSerializerInterface $serializer);
/**
* Returns the {@link StatementResultSerializerInterface statement result serializer}.
*
* @return StatementResultSerializerInterface|null The serializer
*/
public function getStatementResultSerializer();
/**
* Sets the {@link ActorSerializerInterface actor serializer}.
*
* @param ActorSerializerInterface $serializer The serializer
*/
public function setActorSerializer(ActorSerializerInterface $serializer);
/**
* Returns the {@link ActorSerializerInterface actor serializer}.
*
* @return ActorSerializerInterface|null The serializer
*/
public function getActorSerializer();
/**
* Sets the {@link DocumentDataSerializerInterface document data serializer}.
*
* @param DocumentDataSerializerInterface $serializer The serializer
*/
public function setDocumentDataSerializer(DocumentDataSerializerInterface $serializer);
/**
* Returns the {@link DocumentDataSerializerInterface document data serializer}.
*
* @return DocumentDataSerializerInterface|null The serializer
*/
public function getDocumentDataSerializer();
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer;
use Xabbuh\XApi\Model\StatementResult;
/**
* Serialize and deserialize {@link StatementResult statement results}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
interface StatementResultSerializerInterface
{
/**
* Serializes a statement result into a JSON encoded string.
*
* @param StatementResult $statementResult The statement result to serialize
*
* @return string The serialized statement result
*/
public function serializeStatementResult(StatementResult $statementResult);
/**
* Parses a serialized statement result.
*
* @param string $data The serialized statement result
* @param array $attachments The raw attachment data, a mapping of SHA-2 hashes to attachments data (the data is an
* array with the keys type, the attachment's MIME type, and content, the attachment's raw
* content data)
*
* @return StatementResult The parsed statement result
*/
public function deserializeStatementResult($data, array $attachments = array());
}

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer;
use Xabbuh\XApi\Model\Statement;
/**
* Serialize and deserialize {@link Statement statements}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
interface StatementSerializerInterface
{
/**
* Serializes a statement into a JSON encoded string.
*
* @param Statement $statement The statement to serialize
*
* @return string The serialized statement
*/
public function serializeStatement(Statement $statement);
/**
* Serializes a collection of statements into a JSON encoded string.
*
* @param Statement[] $statements The statements to serialize
*
* @return string The serialized statements
*/
public function serializeStatements(array $statements);
/**
* Parses a serialized statement.
*
* @param string $data The serialized statement
* @param array $attachments The raw attachment data, a mapping of SHA-2 hashes to attachments data (the data is an
* array with the keys type, the attachment's MIME type, and content, the attachment's raw
* content data)
*
* @return Statement The parsed statement
*/
public function deserializeStatement($data, array $attachments = array());
/**
* Parses a serialized collection of statements.
*
* @param string $data The serialized statements
* @param array $attachments The raw attachment data, a mapping of SHA-2 hashes to attachments data (the data is an
* array with the keys type, the attachment's MIME type, and content, the attachment's raw
* content data)
*
* @return Statement[] The parsed statements
*/
public function deserializeStatements($data, array $attachments = array());
}

View File

@@ -0,0 +1,58 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer\Tests;
use Xabbuh\XApi\Model\Actor;
/**
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class ActorSerializerTest extends SerializerTest
{
private $actorSerializer;
protected function setUp()
{
$this->actorSerializer = $this->createActorSerializer();
}
/**
* @dataProvider serializeData
*/
public function testSerializeActor(Actor $actor, $expectedJson)
{
$this->assertJsonStringEqualsJsonString($expectedJson, $this->actorSerializer->serializeActor($actor));
}
public function serializeData()
{
return $this->buildSerializeTestCases('Actor');
}
/**
* @dataProvider deserializeData
*/
public function testDeserializeActor($json, Actor $expectedActor)
{
$actor = $this->actorSerializer->deserializeActor($json);
$this->assertInstanceOf('Xabbuh\XApi\Model\Actor', $actor);
$this->assertTrue($expectedActor->equals($actor), 'Deserialized actor has the expected properties');
}
public function deserializeData()
{
return $this->buildDeserializeTestCases('Actor');
}
abstract protected function createActorSerializer();
}

View File

@@ -0,0 +1,49 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer\Tests;
use Xabbuh\XApi\DataFixtures\DocumentFixtures;
use XApi\Fixtures\Json\DocumentJsonFixtures;
/**
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class DocumentDataSerializerTest extends SerializerTest
{
private $documentDataSerializer;
protected function setUp()
{
$this->documentDataSerializer = $this->createDocumentDataSerializer();
}
public function testDeserializeDocumentData()
{
$documentData = $this->documentDataSerializer->deserializeDocumentData(DocumentJsonFixtures::getDocument());
$this->assertInstanceOf('\Xabbuh\XApi\Model\DocumentData', $documentData);
$this->assertEquals('foo', $documentData['x']);
$this->assertEquals('bar', $documentData['y']);
}
public function testSerializeDocumentData()
{
$documentData = DocumentFixtures::getDocumentData();
$this->assertJsonStringEqualsJsonString(
DocumentJsonFixtures::getDocument(),
$this->documentDataSerializer->serializeDocumentData($documentData)
);
}
abstract protected function createDocumentDataSerializer();
}

View File

@@ -0,0 +1,68 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer\Tests;
use PHPUnit\Framework\TestCase;
abstract class SerializerTest extends TestCase
{
protected function buildSerializeTestCases($objectType)
{
$tests = array();
$phpFixturesClass = 'Xabbuh\XApi\DataFixtures\\'.$objectType.'Fixtures';
$jsonFixturesClass = 'XApi\Fixtures\Json\\'.$objectType.'JsonFixtures';
$jsonFixturesMethods = get_class_methods($jsonFixturesClass);
foreach (get_class_methods($phpFixturesClass) as $method) {
if (false !== strpos($method, 'ForQuery')) {
continue;
}
// serialized data will always contain type information
if (in_array($method.'WithType', $jsonFixturesMethods)) {
$jsonMethod = $method.'WithType';
} else {
$jsonMethod = $method;
}
$tests[$method] = array(
call_user_func(array($phpFixturesClass, $method)),
call_user_func(array($jsonFixturesClass, $jsonMethod)),
);
}
return $tests;
}
protected function buildDeserializeTestCases($objectType)
{
$tests = array();
$jsonFixturesClass = 'XApi\Fixtures\Json\\'.$objectType.'JsonFixtures';
$phpFixturesClass = 'Xabbuh\XApi\DataFixtures\\'.$objectType.'Fixtures';
foreach (get_class_methods($jsonFixturesClass) as $method) {
// PHP objects do not contain the type information as a dedicated property
if ('WithType' === substr($method, -8)) {
continue;
}
$tests[$method] = array(
call_user_func(array($jsonFixturesClass, $method)),
call_user_func(array($phpFixturesClass, $method)),
);
}
return $tests;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer\Tests;
use Xabbuh\XApi\Model\StatementResult;
/**
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class StatementResultSerializerTest extends SerializerTest
{
private $statementResultSerializer;
protected function setUp()
{
$this->statementResultSerializer = $this->createStatementResultSerializer();
}
/**
* @dataProvider serializeData
*/
public function testSerializeStatementResult(StatementResult $statementResult, $expectedJson)
{
$this->assertJsonStringEqualsJsonString($expectedJson, $this->statementResultSerializer->serializeStatementResult($statementResult));
}
public function serializeData()
{
return $this->buildSerializeTestCases('StatementResult');
}
/**
* @dataProvider deserializeData
*/
public function testDeserializeStatementResult($json, StatementResult $expectedStatementResult)
{
$statementResult = $this->statementResultSerializer->deserializeStatementResult($json);
$this->assertInstanceOf('Xabbuh\XApi\Model\StatementResult', $statementResult);
$expectedStatements = $expectedStatementResult->getStatements();
$statements = $statementResult->getStatements();
$this->assertCount(count($expectedStatements), $statements, 'Statement result sets have the same size');
foreach ($expectedStatements as $key => $expectedStatement) {
$this->assertTrue($expectedStatement->equals($statements[$key]), 'Statements in result are the same');
}
if (null === $expectedStatementResult->getMoreUrlPath()) {
$this->assertNull($statementResult->getMoreUrlPath(), 'The more URL path is null');
} else {
$this->assertTrue($expectedStatementResult->getMoreUrlPath()->equals($statementResult->getMoreUrlPath()), 'More URL paths are equal');
}
}
public function deserializeData()
{
return $this->buildDeserializeTestCases('StatementResult');
}
abstract protected function createStatementResultSerializer();
}

View File

@@ -0,0 +1,110 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Serializer\Tests;
use Xabbuh\XApi\DataFixtures\StatementFixtures;
use Xabbuh\XApi\Model\Statement;
use XApi\Fixtures\Json\StatementJsonFixtures;
/**
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class StatementSerializerTest extends SerializerTest
{
private $statementSerializer;
protected function setUp()
{
$this->statementSerializer = $this->createStatementSerializer();
}
/**
* @dataProvider serializeData
*/
public function testSerializeStatement(Statement $statement, $expectedJson)
{
$this->assertJsonStringEqualsJsonString($expectedJson, $this->statementSerializer->serializeStatement($statement));
}
public function serializeData()
{
$testCases = array();
foreach ($this->buildSerializeTestCases('Statement') as $fixtures) {
if ($fixtures[0] instanceof Statement) {
if ($fixtures[0]->getVerb()->isVoidVerb()) {
$fixtures[0] = StatementFixtures::getVoidingStatement(StatementFixtures::DEFAULT_STATEMENT_ID);
}
$testCases[] = $fixtures;
}
}
return $testCases;
}
/**
* @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 function deserializeData()
{
$testCases = array();
foreach ($this->buildDeserializeTestCases('Statement') as $fixtures) {
if ($fixtures[1] instanceof Statement) {
if ($fixtures[1]->getVerb()->isVoidVerb()) {
$fixtures[1] = StatementFixtures::getVoidingStatement(StatementFixtures::DEFAULT_STATEMENT_ID);
}
$testCases[] = $fixtures;
}
}
return $testCases;
}
public function testDeserializeStatementCollection()
{
/** @var \Xabbuh\XApi\Model\Statement[] $statements */
$statements = $this->statementSerializer->deserializeStatements(
StatementJsonFixtures::getStatementCollection()
);
$expectedCollection = StatementFixtures::getStatementCollection();
$this->assertSame(count($expectedCollection), count($statements));
foreach ($expectedCollection as $index => $expectedStatement) {
$this->assertTrue($expectedStatement->equals($statements[$index]));
}
}
abstract protected function createStatementSerializer();
}