Skip to content

Commit 9987dd1

Browse files
committed
split implementation out of php-xapi/serializer
0 parents  commit 9987dd1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3352
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/composer.lock
2+
/phpunit.xml
3+
/phpspec.xml
4+
/vendor

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
sudo: false
2+
3+
language: php
4+
5+
cache:
6+
directories:
7+
- $HOME/.composer/cache/files
8+
9+
php:
10+
- 5.4
11+
- 5.5
12+
- 5.6
13+
- hhvm
14+
15+
matrix:
16+
fast_finish: true
17+
include:
18+
- php: 5.3
19+
env: deps="low"
20+
- php: 7.0
21+
env: xdebug="yes"
22+
23+
before_install:
24+
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" && "$xdebug" != "yes" ]]; then phpenv config-rm xdebug.ini; fi
25+
- composer self-update
26+
27+
install:
28+
- if [ "$deps" = "low" ]; then composer update --prefer-lowest --prefer-stable; else composer install; fi
29+
30+
script:
31+
- vendor/bin/phpspec run
32+
- if [[ "$xdebug" = "yes" ]]; then phpunit --coverage-clover=coverage.clover; else phpunit; fi
33+
- if [[ "$xdebug" = "yes" ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
34+
- if [[ "$xdebug" = "yes" ]]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi

CHANGELOG.md

Whitespace-only changes.

LICENSE

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

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Symfony Console Based Serializer for the xApi
2+
=============================================
3+
4+
[![Build Status](https://travis-ci.org/php-xapi/symfony-serializer.svg?branch=master)](https://travis-ci.org/php-xapi/symfony-serializer)
5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-xapi/symfony-serializer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/php-xapi/symfony-serializer/?branch=master)
6+
[![Code Coverage](https://scrutinizer-ci.com/g/php-xapi/symfony-serializer/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/php-xapi/symfony-serializer/?branch=master)
7+
8+
Transform [Experience API](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md)
9+
model objects into JSON encoded strings conforming to the API specs and vice
10+
versa leveraging the Symfony Serializer component.
11+
12+
This package provides an implementation of the interface defined by the
13+
[php-xapi/serializer package](https://github.com/php-xapi/serializer) and
14+
provides the virtual [php-xapi/serializer-implementation](https://packagist.org/providers/php-xapi/serializer-implementation)
15+
package.

composer.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "php-xapi/symfony-serializer",
3+
"type": "library",
4+
"description": "transform Experience API model objects to JSON encoded strings and vice versa using the Symfony Serializer component",
5+
"keywords": ["xAPI", "Experience API", "Tin Can API", "serializer", "Symfony"],
6+
"homepage": "https://github.com/php-xapi/symfony-serializer",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Christian Flothmann",
11+
"homepage": "https://github.com/xabbuh"
12+
}
13+
],
14+
"require": {
15+
"php": ">=5.3.0",
16+
"php-xapi/model": "^0.5",
17+
"php-xapi/serializer": "^0.4",
18+
"symfony/serializer": "~2.8|~3.0"
19+
},
20+
"require-dev": {
21+
"php-xapi/json-test-fixtures": "^0.2.3",
22+
"php-xapi/test-fixtures": "^0.5",
23+
"phpspec/phpspec": "~2.3"
24+
},
25+
"provide": {
26+
"php-xapi/serializer-implementation": "1.0"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Xabbuh\\XApi\\Serializer\\Symfony\\": "src/"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"spec\\Xabbuh\\XApi\\Serializer\\Symfony\\": "spec/",
36+
"Xabbuh\\XApi\\Serializer\\Symfony\\Tests\\": "tests/"
37+
}
38+
},
39+
"extra": {
40+
"branch-alias": {
41+
"dev-master": "0.1.x-dev"
42+
}
43+
}
44+
}

phpspec.yml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
suites:
2+
default:
3+
namespace: Xabbuh\XApi\Serializer\Symfony
4+
psr4_prefix: Xabbuh\XApi\Serializer\Symfony

phpunit.xml.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit colors="true" bootstrap="vendor/autoload.php">
3+
<testsuites>
4+
<testsuite name="Experience API model serializer leveraging the Symfony Serializer component">
5+
<directory>./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<filter>
9+
<whitelist>
10+
<directory>./src</directory>
11+
</whitelist>
12+
</filter>
13+
</phpunit>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace spec\Xabbuh\XApi\Serializer\Symfony\Normalizer;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Xabbuh\XApi\DataFixtures\AccountFixtures;
7+
use Xabbuh\XApi\Model\IRL;
8+
use XApi\Fixtures\Json\AccountJsonFixtures;
9+
10+
class AccountNormalizerSpec extends ObjectBehavior
11+
{
12+
function it_is_a_normalizer()
13+
{
14+
$this->shouldHaveType('Symfony\Component\Serializer\Normalizer\NormalizerInterface');
15+
}
16+
17+
function it_is_a_denormalizer()
18+
{
19+
$this->shouldHaveType('Symfony\Component\Serializer\Normalizer\DenormalizerInterface');
20+
}
21+
22+
function it_supports_normalizing_accounts()
23+
{
24+
$this->supportsNormalization(AccountFixtures::getTypicalAccount())->shouldBe(true);
25+
}
26+
27+
function it_denormalizes_accounts()
28+
{
29+
$account = $this->denormalize(array('homePage' => 'https://tincanapi.com', 'name' => 'test'), 'Xabbuh\XApi\Model\Account');
30+
31+
$account->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Account');
32+
$account->getHomePage()->equals(IRL::fromString('https://tincanapi.com'))->shouldReturn(true);
33+
$account->getName()->shouldReturn('test');
34+
}
35+
36+
function it_supports_denormalizing_accounts()
37+
{
38+
$this->supportsDenormalization(AccountJsonFixtures::getTypicalAccount(), 'Xabbuh\XApi\Model\Account')->shouldBe(true);
39+
}
40+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace spec\Xabbuh\XApi\Serializer\Symfony\Normalizer;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Xabbuh\XApi\DataFixtures\ActorFixtures;
7+
use XApi\Fixtures\Json\ActorJsonFixtures;
8+
9+
class ActorNormalizerSpec extends ObjectBehavior
10+
{
11+
function it_is_a_normalizer()
12+
{
13+
$this->shouldHaveType('Symfony\Component\Serializer\Normalizer\NormalizerInterface');
14+
}
15+
16+
function it_is_a_denormalizer()
17+
{
18+
$this->shouldHaveType('Symfony\Component\Serializer\Normalizer\DenormalizerInterface');
19+
}
20+
21+
function it_requires_an_iri_when_denormalizing_an_agent()
22+
{
23+
$this
24+
->shouldThrow('\Symfony\Component\Serializer\Exception\InvalidArgumentException')
25+
->during('denormalize', array(
26+
array('objectType' => 'Agent'),
27+
'Xabbuh\XApi\Model\Actor',
28+
))
29+
;
30+
}
31+
32+
function it_can_denormalize_agents_with_mbox_sha1_sum()
33+
{
34+
$data = array(
35+
'mbox_sha1sum' => 'db77b9104b531ecbb0b967f6942549d0ba80fda1',
36+
);
37+
38+
$agent = $this->denormalize($data, 'Xabbuh\XApi\Model\Actor');
39+
40+
$agent->shouldBeAnInstanceOf('Xabbuh\XApi\Model\Agent');
41+
$agent->getInverseFunctionalIdentifier()->getMboxSha1Sum()->shouldReturn('db77b9104b531ecbb0b967f6942549d0ba80fda1');
42+
}
43+
44+
function it_supports_normalizing_agents()
45+
{
46+
$this->supportsNormalization(ActorFixtures::getTypicalAgent())->shouldBe(true);
47+
}
48+
49+
function it_supports_normalizing_groups()
50+
{
51+
$this->supportsNormalization(ActorFixtures::getTypicalGroup())->shouldBe(true);
52+
}
53+
54+
function it_supports_denormalizing_agents()
55+
{
56+
$this->supportsDenormalization(ActorJsonFixtures::getTypicalAgent(), 'Xabbuh\XApi\Model\Actor')->shouldBe(true);
57+
}
58+
59+
function it_supports_denormalizing_groups()
60+
{
61+
$this->supportsDenormalization(ActorJsonFixtures::getTypicalGroup(), 'Xabbuh\XApi\Model\Actor')->shouldBe(true);
62+
}
63+
}

0 commit comments

Comments
 (0)