@@ -38,21 +38,21 @@ public function testInterface()
38
38
*/
39
39
public function testNormalizeNoMatch ()
40
40
{
41
- $ this -> serializer = new Serializer (array ($ this ->getMock ('Symfony\Component\Serializer\Normalizer\CustomNormalizer ' )));
42
- $ this -> serializer ->normalize (new \stdClass (), 'xml ' );
41
+ $ serializer = new Serializer (array ($ this ->getMock ('Symfony\Component\Serializer\Normalizer\CustomNormalizer ' )));
42
+ $ serializer ->normalize (new \stdClass (), 'xml ' );
43
43
}
44
44
45
45
public function testNormalizeTraversable ()
46
46
{
47
- $ this -> serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
48
- $ result = $ this -> serializer ->serialize (new TraversableDummy (), 'json ' );
47
+ $ serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
48
+ $ result = $ serializer ->serialize (new TraversableDummy (), 'json ' );
49
49
$ this ->assertEquals ('{"foo":"foo","bar":"bar"} ' , $ result );
50
50
}
51
51
52
52
public function testNormalizeGivesPriorityToInterfaceOverTraversable ()
53
53
{
54
- $ this -> serializer = new Serializer (array (new CustomNormalizer ()), array ('json ' => new JsonEncoder ()));
55
- $ result = $ this -> serializer ->serialize (new NormalizableTraversableDummy (), 'json ' );
54
+ $ serializer = new Serializer (array (new CustomNormalizer ()), array ('json ' => new JsonEncoder ()));
55
+ $ result = $ serializer ->serialize (new NormalizableTraversableDummy (), 'json ' );
56
56
$ this ->assertEquals ('{"foo":"normalizedFoo","bar":"normalizedBar"} ' , $ result );
57
57
}
58
58
@@ -61,58 +61,58 @@ public function testNormalizeGivesPriorityToInterfaceOverTraversable()
61
61
*/
62
62
public function testNormalizeOnDenormalizer ()
63
63
{
64
- $ this -> serializer = new Serializer (array (new TestDenormalizer ()), array ());
65
- $ this ->assertTrue ($ this -> serializer ->normalize (new \stdClass (), 'json ' ));
64
+ $ serializer = new Serializer (array (new TestDenormalizer ()), array ());
65
+ $ this ->assertTrue ($ serializer ->normalize (new \stdClass (), 'json ' ));
66
66
}
67
67
68
68
/**
69
69
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
70
70
*/
71
71
public function testDenormalizeNoMatch ()
72
72
{
73
- $ this -> serializer = new Serializer (array ($ this ->getMock ('Symfony\Component\Serializer\Normalizer\CustomNormalizer ' )));
74
- $ this -> serializer ->denormalize ('foo ' , 'stdClass ' );
73
+ $ serializer = new Serializer (array ($ this ->getMock ('Symfony\Component\Serializer\Normalizer\CustomNormalizer ' )));
74
+ $ serializer ->denormalize ('foo ' , 'stdClass ' );
75
75
}
76
76
77
77
/**
78
78
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
79
79
*/
80
80
public function testDenormalizeOnNormalizer ()
81
81
{
82
- $ this -> serializer = new Serializer (array (new TestNormalizer ()), array ());
82
+ $ serializer = new Serializer (array (new TestNormalizer ()), array ());
83
83
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
84
- $ this ->assertTrue ($ this -> serializer ->denormalize (json_encode ($ data ), 'stdClass ' , 'json ' ));
84
+ $ this ->assertTrue ($ serializer ->denormalize (json_encode ($ data ), 'stdClass ' , 'json ' ));
85
85
}
86
86
87
87
public function testCustomNormalizerCanNormalizeCollectionsAndScalar ()
88
88
{
89
- $ this -> serializer = new Serializer (array (new TestNormalizer ()), array ());
90
- $ this ->assertNull ($ this -> serializer ->normalize (array ('a ' , 'b ' )));
91
- $ this ->assertNull ($ this -> serializer ->normalize (new \ArrayObject (array ('c ' , 'd ' ))));
92
- $ this ->assertNull ($ this -> serializer ->normalize (array ()));
93
- $ this ->assertNull ($ this -> serializer ->normalize ('test ' ));
89
+ $ serializer = new Serializer (array (new TestNormalizer ()), array ());
90
+ $ this ->assertNull ($ serializer ->normalize (array ('a ' , 'b ' )));
91
+ $ this ->assertNull ($ serializer ->normalize (new \ArrayObject (array ('c ' , 'd ' ))));
92
+ $ this ->assertNull ($ serializer ->normalize (array ()));
93
+ $ this ->assertNull ($ serializer ->normalize ('test ' ));
94
94
}
95
95
96
96
public function testSerialize ()
97
97
{
98
- $ this -> serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ('json ' => new JsonEncoder ()));
98
+ $ serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ('json ' => new JsonEncoder ()));
99
99
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
100
- $ result = $ this -> serializer ->serialize (Model::fromArray ($ data ), 'json ' );
100
+ $ result = $ serializer ->serialize (Model::fromArray ($ data ), 'json ' );
101
101
$ this ->assertEquals (json_encode ($ data ), $ result );
102
102
}
103
103
104
104
public function testSerializeScalar ()
105
105
{
106
- $ this -> serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
107
- $ result = $ this -> serializer ->serialize ('foo ' , 'json ' );
106
+ $ serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
107
+ $ result = $ serializer ->serialize ('foo ' , 'json ' );
108
108
$ this ->assertEquals ('"foo" ' , $ result );
109
109
}
110
110
111
111
public function testSerializeArrayOfScalars ()
112
112
{
113
- $ this -> serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
113
+ $ serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
114
114
$ data = array ('foo ' , array (5 , 3 ));
115
- $ result = $ this -> serializer ->serialize ($ data , 'json ' );
115
+ $ result = $ serializer ->serialize ($ data , 'json ' );
116
116
$ this ->assertEquals (json_encode ($ data ), $ result );
117
117
}
118
118
@@ -121,36 +121,36 @@ public function testSerializeArrayOfScalars()
121
121
*/
122
122
public function testSerializeNoEncoder ()
123
123
{
124
- $ this -> serializer = new Serializer (array (), array ());
124
+ $ serializer = new Serializer (array (), array ());
125
125
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
126
- $ this -> serializer ->serialize ($ data , 'json ' );
126
+ $ serializer ->serialize ($ data , 'json ' );
127
127
}
128
128
129
129
/**
130
130
* @expectedException \Symfony\Component\Serializer\Exception\LogicException
131
131
*/
132
132
public function testSerializeNoNormalizer ()
133
133
{
134
- $ this -> serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
134
+ $ serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
135
135
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
136
- $ this -> serializer ->serialize (Model::fromArray ($ data ), 'json ' );
136
+ $ serializer ->serialize (Model::fromArray ($ data ), 'json ' );
137
137
}
138
138
139
139
public function testDeserialize ()
140
140
{
141
- $ this -> serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ('json ' => new JsonEncoder ()));
141
+ $ serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ('json ' => new JsonEncoder ()));
142
142
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
143
- $ result = $ this -> serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
143
+ $ result = $ serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
144
144
$ this ->assertEquals ($ data , $ result ->toArray ());
145
145
}
146
146
147
147
public function testDeserializeUseCache ()
148
148
{
149
- $ this -> serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ('json ' => new JsonEncoder ()));
149
+ $ serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ('json ' => new JsonEncoder ()));
150
150
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
151
- $ this -> serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
151
+ $ serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
152
152
$ data = array ('title ' => 'bar ' , 'numbers ' => array (2 , 8 ));
153
- $ result = $ this -> serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
153
+ $ result = $ serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
154
154
$ this ->assertEquals ($ data , $ result ->toArray ());
155
155
}
156
156
@@ -159,65 +159,65 @@ public function testDeserializeUseCache()
159
159
*/
160
160
public function testDeserializeNoNormalizer ()
161
161
{
162
- $ this -> serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
162
+ $ serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
163
163
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
164
- $ this -> serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
164
+ $ serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
165
165
}
166
166
167
167
/**
168
168
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
169
169
*/
170
170
public function testDeserializeWrongNormalizer ()
171
171
{
172
- $ this -> serializer = new Serializer (array (new CustomNormalizer ()), array ('json ' => new JsonEncoder ()));
172
+ $ serializer = new Serializer (array (new CustomNormalizer ()), array ('json ' => new JsonEncoder ()));
173
173
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
174
- $ this -> serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
174
+ $ serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
175
175
}
176
176
177
177
/**
178
178
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
179
179
*/
180
180
public function testDeserializeNoEncoder ()
181
181
{
182
- $ this -> serializer = new Serializer (array (), array ());
182
+ $ serializer = new Serializer (array (), array ());
183
183
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
184
- $ this -> serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
184
+ $ serializer ->deserialize (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' );
185
185
}
186
186
187
187
public function testDeserializeSupported ()
188
188
{
189
- $ this -> serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ());
189
+ $ serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ());
190
190
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
191
- $ this ->assertTrue ($ this -> serializer ->supportsDenormalization (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' ));
191
+ $ this ->assertTrue ($ serializer ->supportsDenormalization (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' ));
192
192
}
193
193
194
194
public function testDeserializeNotSupported ()
195
195
{
196
- $ this -> serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ());
196
+ $ serializer = new Serializer (array (new GetSetMethodNormalizer ()), array ());
197
197
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
198
- $ this ->assertFalse ($ this -> serializer ->supportsDenormalization (json_encode ($ data ), 'stdClass ' , 'json ' ));
198
+ $ this ->assertFalse ($ serializer ->supportsDenormalization (json_encode ($ data ), 'stdClass ' , 'json ' ));
199
199
}
200
200
201
201
public function testDeserializeNotSupportedMissing ()
202
202
{
203
- $ this -> serializer = new Serializer (array (), array ());
203
+ $ serializer = new Serializer (array (), array ());
204
204
$ data = array ('title ' => 'foo ' , 'numbers ' => array (5 , 3 ));
205
- $ this ->assertFalse ($ this -> serializer ->supportsDenormalization (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' ));
205
+ $ this ->assertFalse ($ serializer ->supportsDenormalization (json_encode ($ data ), '\Symfony\Component\Serializer\Tests\Model ' , 'json ' ));
206
206
}
207
207
208
208
public function testEncode ()
209
209
{
210
- $ this -> serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
210
+ $ serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
211
211
$ data = array ('foo ' , array (5 , 3 ));
212
- $ result = $ this -> serializer ->encode ($ data , 'json ' );
212
+ $ result = $ serializer ->encode ($ data , 'json ' );
213
213
$ this ->assertEquals (json_encode ($ data ), $ result );
214
214
}
215
215
216
216
public function testDecode ()
217
217
{
218
- $ this -> serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
218
+ $ serializer = new Serializer (array (), array ('json ' => new JsonEncoder ()));
219
219
$ data = array ('foo ' , array (5 , 3 ));
220
- $ result = $ this -> serializer ->decode (json_encode ($ data ), 'json ' );
220
+ $ result = $ serializer ->decode (json_encode ($ data ), 'json ' );
221
221
$ this ->assertEquals ($ data , $ result );
222
222
}
223
223
}
0 commit comments