|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: pawelmikolajczuk |
|
5
|
|
|
* Date: 09.03.2017 |
|
6
|
|
|
* Time: 09:18. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace SWP\Bridge\JMSSerializerBundle\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
|
12
|
|
|
use JMS\Serializer\Construction\UnserializeObjectConstructor; |
|
13
|
|
|
use JMS\Serializer\Handler\HandlerRegistry; |
|
14
|
|
|
use JMS\Serializer\JsonDeserializationVisitor; |
|
15
|
|
|
use JMS\Serializer\JsonSerializationVisitor; |
|
16
|
|
|
use JMS\Serializer\Metadata\Driver\AnnotationDriver; |
|
17
|
|
|
use JMS\Serializer\Naming\CamelCaseNamingStrategy; |
|
18
|
|
|
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; |
|
19
|
|
|
use JMS\Serializer\Serializer; |
|
20
|
|
|
use Metadata\MetadataFactory; |
|
21
|
|
|
use PhpCollection\Map; |
|
22
|
|
|
use SWP\Bridge\JMSSerializerBundle\JMSSerializer; |
|
23
|
|
|
|
|
24
|
|
|
class JMSSerializerTest extends \PHPUnit_Framework_TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
public function testSerializer() |
|
27
|
|
|
{ |
|
28
|
|
|
$factory = new MetadataFactory(new AnnotationDriver(new AnnotationReader())); |
|
29
|
|
|
|
|
30
|
|
|
$handlerRegistry = new HandlerRegistry(); |
|
31
|
|
|
$namingStrategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy()); |
|
32
|
|
|
$objectConstructor = new UnserializeObjectConstructor(); |
|
33
|
|
|
$serializationVisitors = new Map(array( |
|
34
|
|
|
'json' => new JsonSerializationVisitor($namingStrategy), |
|
35
|
|
|
)); |
|
36
|
|
|
$deserializationVisitors = new Map(array( |
|
37
|
|
|
'json' => new JsonDeserializationVisitor($namingStrategy), |
|
38
|
|
|
)); |
|
39
|
|
|
|
|
40
|
|
|
$serializer = new JMSSerializer(new Serializer( |
|
41
|
|
|
$factory, |
|
42
|
|
|
$handlerRegistry, |
|
43
|
|
|
$objectConstructor, |
|
44
|
|
|
$serializationVisitors, |
|
45
|
|
|
$deserializationVisitors |
|
46
|
|
|
)); |
|
47
|
|
|
|
|
48
|
|
|
self::assertEquals('{"a":"b"}', $serializer->serialize(['a' => 'b'], 'json')); |
|
49
|
|
|
self::assertEquals(['a' => 'b'], $serializer->deserialize('{"a":"b"}', 'array', 'json')); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|