|
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
|
|
|
|