Completed
Push — master ( 6421ea...db0bc7 )
by
unknown
10s
created

AnnotationDriverTest::getKernelClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Smartbox\CoreBundle\Tests\Serializer;
4
5
use JMS\Serializer\SerializerInterface;
6
use Smartbox\CoreBundle\Tests\Fixtures\Serializables\SerializableWithExclusionPolicyAll;
7
use Smartbox\CoreBundle\Tests\Fixtures\Serializables\SerializableWithExclusionPolicyAllAndFewPropertiesExposed;
8
use Smartbox\CoreBundle\Tests\Fixtures\Serializables\SerializableWithExclusionPolicyNone;
9
use Smartbox\CoreBundle\Tests\Fixtures\Serializables\SerializableWithExclusionPolicyNoneAndFewPropertiesExcluded;
10
use Smartbox\CoreBundle\Tests\Fixtures\Serializables\SerializableWithoutExclusionPolicy;
11
use Smartbox\CoreBundle\Type\SerializableInterface;
12
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
13
use Symfony\Component\DependencyInjection\ContainerInterface;
14
15
class AnnotationDriverTest extends KernelTestCase
16
{
17
    /**
18
     * @var ContainerInterface
19
     */
20
    protected $container;
21
22
    /**
23
     * @var SerializerInterface
24
     */
25
    protected $serializer;
26
27
    public static function getKernelClass()
28
    {
29
        return \Smartbox\CoreBundle\Tests\AppKernel::class;
30
    }
31
32
    protected function setUp()
33
    {
34
       static::bootKernel();
35
36
        $this->container = static::$kernel->getContainer();
37
        $this->serializer = $this->container->get('serializer');
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function dataProviderForSerializables()
44
    {
45
        $data = [];
46
47
        // should serialize only "_type"
48
        $object1 = new SerializableWithoutExclusionPolicy();
49
        $object1->setIntegerValue(4);
50
        $object1->setDoubleValue(0.08);
51
        $object1->setStringValue('test 1');
52
        $data[] = [$object1, ['_type' => SerializableWithoutExclusionPolicy::class]];
53
54
        // should be the same as SerializableWithoutExclusionPolicy
55
        $object2 = new SerializableWithExclusionPolicyAll();
56
        $object2->setIntegerValue(4);
57
        $object2->setDoubleValue(0.08);
58
        $object2->setStringValue('test 2');
59
        $data[] = [$object2, ['_type' => SerializableWithExclusionPolicyAll::class]];
60
61
        // should serialize everything
62
        $object3 = new SerializableWithExclusionPolicyNone();
63
        $object3->setIntegerValue(5);
64
        $object3->setDoubleValue(0.03);
65
        $object3->setStringValue('test 3');
66
        $data[] = [
67
            $object3,
68
            [
69
                '_type' => SerializableWithExclusionPolicyNone::class,
70
                'integer_value' => 5,
71
                'double_value' => 0.03,
72
                'string_value' => 'test 3',
73
            ],
74
        ];
75
76
        // should serialize only EXPOSED properties
77
        $object4 = new SerializableWithExclusionPolicyAllAndFewPropertiesExposed();
78
        $object4->setIntegerValue(5);
79
        $object4->setDoubleValue(0.03);
80
        $object4->setStringValue('test 4');
81
        $data[] = [
82
            $object4,
83
            [
84
                '_type' => SerializableWithExclusionPolicyAllAndFewPropertiesExposed::class,
85
                'integer_value' => 5,
86
                'string_value' => 'test 4',
87
            ],
88
        ];
89
90
        // should serialize only NOT EXCLUDED properties
91
        $object5 = new SerializableWithExclusionPolicyNoneAndFewPropertiesExcluded();
92
        $object5->setIntegerValue(5);
93
        $object5->setDoubleValue(0.03);
94
        $object5->setStringValue('test 5');
95
        $data[] = [
96
            $object5,
97
            [
98
                '_type' => SerializableWithExclusionPolicyNoneAndFewPropertiesExcluded::class,
99
                'double_value' => 0.03,
100
            ],
101
        ];
102
103
        return $data;
104
    }
105
106
    /**
107
     * @dataProvider dataProviderForSerializables
108
     *
109
     * @param SerializableInterface $data
110
     * @param array                 $expectedSerializedData
111
     */
112
    public function testSerialization(SerializableInterface $data, array $expectedSerializedData)
113
    {
114
        $serializedData = $this->serializer->serialize($data, 'array');
115
116
        $this->assertEquals($expectedSerializedData, $serializedData);
117
    }
118
}
119