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

CompositionTest::testDeserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Happyr\SerializerBundle\Tests\Functional;
4
5
use Happyr\SerializerBundle\Tests\Fixtures\Composition\Car;
6
use Happyr\SerializerBundle\Tests\Fixtures\Composition\Owner;
7
8
/**
9
 * Test what happens when a object owns another.
10
 *
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13
class CompositionTest extends SerializerTestCase
14
{
15
    public function testSerialize()
16
    {
17
        $data = $this->serialize(new Owner(true));
18
19
        $this->assertTrue(isset($data['car']));
20
        $this->assertTrue(isset($data['car']['color']));
21
        $this->assertTrue(isset($data['name']));
22
        $this->assertTrue(isset($data['birthday']));
23
    }
24
25
    public function testDeserialize()
26
    {
27
        $data = json_decode('{"name":"Foobar","car":{"super_model":"val_model","car_size":"val_size","color":"val_color"},"birthday":"1995-07-14T20:07:41+02:00"}', true);
28
        $obj = $this->deserialize($data, Owner::class);
29
30
        $this->assertPropertyValue($obj, 'name', 'Foobar');
31
        $car = $obj->getCar();
32
        $this->assertInstanceOf(Car::class, $car);
33
        $this->assertPropertyValue($car, 'color', 'val_color');
34
    }
35
}
36