1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Serializer\Tests; |
13
|
|
|
|
14
|
|
|
use JMS\Serializer\EventDispatcher\EventDispatcher; |
15
|
|
|
use JMS\Serializer\Handler\HandlerRegistryInterface; |
16
|
|
|
use JMS\Serializer\SerializerBuilder; |
17
|
|
|
use JMS\Serializer\SerializerInterface; |
18
|
|
|
use Xabbuh\XApi\Serializer\Event\ActorEventSubscriber; |
19
|
|
|
use Xabbuh\XApi\Serializer\Event\DocumentDataWrapper; |
20
|
|
|
use Xabbuh\XApi\Serializer\Event\ObjectEventSubscriber; |
21
|
|
|
use Xabbuh\XApi\Serializer\Event\SetSerializedTypeEventSubscriber; |
22
|
|
|
use Xabbuh\XApi\Serializer\Handler\DocumentDataUnwrapper; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Christian Flothmann <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
abstract class AbstractSerializerTest extends \PHPUnit_Framework_TestCase |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var SerializerInterface |
31
|
|
|
*/ |
32
|
|
|
protected $serializer; |
33
|
|
|
|
34
|
|
|
protected function setUp() |
35
|
|
|
{ |
36
|
|
|
$builder = SerializerBuilder::create(); |
37
|
|
|
$builder->addMetadataDir(__DIR__.'/../metadata', 'Xabbuh\XApi\Model'); |
38
|
|
|
$builder->configureListeners( |
39
|
|
View Code Duplication |
function (EventDispatcher $dispatcher) { |
|
|
|
|
40
|
|
|
$dispatcher->addSubscriber(new ActorEventSubscriber()); |
41
|
|
|
$dispatcher->addSubscriber(new DocumentDataWrapper()); |
42
|
|
|
$dispatcher->addSubscriber(new ObjectEventSubscriber()); |
43
|
|
|
$dispatcher->addSubscriber(new SetSerializedTypeEventSubscriber()); |
44
|
|
|
} |
45
|
|
|
); |
46
|
|
|
$builder->configureHandlers( |
47
|
|
|
function (HandlerRegistryInterface $registry) { |
48
|
|
|
$registry->registerSubscribingHandler(new DocumentDataUnwrapper()); |
49
|
|
|
} |
50
|
|
|
); |
51
|
|
|
$this->serializer = $builder->build(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function assertJsonEquals($expected, $actual) |
55
|
|
|
{ |
56
|
|
|
$this->assertEquals(json_decode($expected), json_decode($actual)); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.