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