1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Happyr\SerializerBundle\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use Happyr\SerializerBundle\Tests\Fixtures\Groups\Car; |
6
|
|
|
|
7
|
|
|
class GroupsTest extends SerializerTestCase |
8
|
|
|
{ |
9
|
|
|
public function testSerialize() |
10
|
|
|
{ |
11
|
|
|
$data = $this->serialize(new Car(true), ['groups' => ['First']]); |
12
|
|
|
$this->assertTrue(isset($data['model'])); |
13
|
|
|
$this->assertTrue(isset($data['size'])); |
14
|
|
|
$this->assertFalse(isset($data['color'])); |
15
|
|
|
|
16
|
|
|
$data = $this->serialize(new Car(true), ['groups' => ['Second']]); |
17
|
|
|
$this->assertTrue(isset($data['model'])); |
18
|
|
|
$this->assertFalse(isset($data['size'])); |
19
|
|
|
$this->assertFalse(isset($data['color'])); |
20
|
|
|
|
21
|
|
|
$data = $this->serialize(new Car(true), ['groups' => ['First', 'Second']]); |
22
|
|
|
$this->assertTrue(isset($data['model'])); |
23
|
|
|
$this->assertTrue(isset($data['size'])); |
24
|
|
|
$this->assertFalse(isset($data['color'])); |
25
|
|
|
|
26
|
|
|
$data = $this->serialize(new Car(true), ['groups' => ['Default', 'Second']]); |
27
|
|
|
$this->assertTrue(isset($data['model'])); |
28
|
|
|
$this->assertFalse(isset($data['size'])); |
29
|
|
|
$this->assertTrue(isset($data['color'])); |
30
|
|
|
|
31
|
|
|
$data = $this->serialize(new Car(true), ['groups' => []]); |
32
|
|
|
$this->assertTrue(isset($data['model'])); |
33
|
|
|
$this->assertTrue(isset($data['size'])); |
34
|
|
|
$this->assertTrue(isset($data['color'])); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testDeserialize() |
38
|
|
|
{ |
39
|
|
|
$data = ['model' => 'model_value', 'size' => 'size_value', 'color' => 'color_value']; |
40
|
|
|
|
41
|
|
|
$obj = $this->deserialize($data, Car::class, ['groups' => ['First']]); |
42
|
|
|
$this->assertPropertyValue($obj, 'model', 'model_value'); |
43
|
|
|
$this->assertPropertyValue($obj, 'size', 'size_value'); |
44
|
|
|
$this->assertPropertyValue($obj, 'color', null); |
45
|
|
|
|
46
|
|
|
$obj = $this->deserialize($data, Car::class, ['groups' => ['Second']]); |
47
|
|
|
$this->assertPropertyValue($obj, 'model', 'model_value'); |
48
|
|
|
$this->assertPropertyValue($obj, 'size', null); |
49
|
|
|
$this->assertPropertyValue($obj, 'color', null); |
50
|
|
|
|
51
|
|
|
$obj = $this->deserialize($data, Car::class, ['groups' => ['First', 'Second']]); |
52
|
|
|
$this->assertPropertyValue($obj, 'model', 'model_value'); |
53
|
|
|
$this->assertPropertyValue($obj, 'size', 'size_value'); |
54
|
|
|
$this->assertPropertyValue($obj, 'color', null); |
55
|
|
|
|
56
|
|
|
$obj = $this->deserialize($data, Car::class, ['groups' => ['Default', 'Second']]); |
57
|
|
|
$this->assertPropertyValue($obj, 'model', 'model_value'); |
58
|
|
|
$this->assertPropertyValue($obj, 'size', null); |
59
|
|
|
$this->assertPropertyValue($obj, 'color', 'color_value'); |
60
|
|
|
|
61
|
|
|
$obj = $this->deserialize($data, Car::class, ['groups' => []]); |
62
|
|
|
$this->assertPropertyValue($obj, 'model', 'model_value'); |
63
|
|
|
$this->assertPropertyValue($obj, 'size', 'size_value'); |
64
|
|
|
$this->assertPropertyValue($obj, 'color', 'color_value'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|