Completed
Push — master ( 2e5350...f0c5b4 )
by Tobias
10:07
created

ReadOnlyTest::testSerializeReadOnlyClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 8
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Happyr\SerializerBundle\Tests\Functional;
4
5
use Happyr\SerializerBundle\Tests\Fixtures\ReadOnly\Car;
6
use Happyr\SerializerBundle\Tests\Fixtures\ReadOnly\ClassReadOnly;
7
8
class ReadOnlyTest extends SerializerTestCase
9
{
10
    public function testSerialize()
11
    {
12
        $data = $this->serialize(new Car(true));
13
14
        $this->assertTrue(isset($data['model']));
15
        $this->assertTrue(isset($data['size']));
16
    }
17
18
    public function testDeserialize()
19
    {
20
        $data = ['model' => 'model_value', 'size' => 'size_value'];
21
        $obj = $this->deserialize($data, Car::class);
22
23
        $this->assertPropertyValue($obj, 'model', null);
24
        $this->assertPropertyValue($obj, 'size', 'size_value');
25
    }
26
27
    public function testSerializeReadOnlyClass()
28
    {
29
        $data = $this->serialize(new ClassReadOnly(true));
30
31
        $this->assertTrue(isset($data['model']));
32
        $this->assertTrue(isset($data['size']));
33
        $this->assertTrue(isset($data['color']));
34
    }
35
36
    public function testDeserializeReadOnlyClass()
37
    {
38
        $data = ['model' => 'model_value', 'size' => 'size_value', 'color' => 'color_value'];
39
        $obj = $this->deserialize($data, ClassReadOnly::class);
40
41
        $this->assertPropertyValue($obj, 'model', 'model_value');
42
        $this->assertPropertyValue($obj, 'size', null);
43
        $this->assertPropertyValue($obj, 'color', null);
44
    }
45
}
46