Skip to content

Commit c4bfe09

Browse files
committed
Fixed properties not explicitily declared
1 parent baf24f8 commit c4bfe09

File tree

2 files changed

+51
-48
lines changed

2 files changed

+51
-48
lines changed

Tests/Encoder/JsonEncoderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
class JsonEncoderTest extends \PHPUnit_Framework_TestCase
1919
{
20+
private $encoder;
21+
private $serializer;
22+
2023
protected function setUp()
2124
{
2225
$this->encoder = new JsonEncoder();

Tests/SerializerTest.php

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ public function testInterface()
3838
*/
3939
public function testNormalizeNoMatch()
4040
{
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');
4343
}
4444

4545
public function testNormalizeTraversable()
4646
{
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');
4949
$this->assertEquals('{"foo":"foo","bar":"bar"}', $result);
5050
}
5151

5252
public function testNormalizeGivesPriorityToInterfaceOverTraversable()
5353
{
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');
5656
$this->assertEquals('{"foo":"normalizedFoo","bar":"normalizedBar"}', $result);
5757
}
5858

@@ -61,58 +61,58 @@ public function testNormalizeGivesPriorityToInterfaceOverTraversable()
6161
*/
6262
public function testNormalizeOnDenormalizer()
6363
{
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'));
6666
}
6767

6868
/**
6969
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
7070
*/
7171
public function testDenormalizeNoMatch()
7272
{
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');
7575
}
7676

7777
/**
7878
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
7979
*/
8080
public function testDenormalizeOnNormalizer()
8181
{
82-
$this->serializer = new Serializer(array(new TestNormalizer()), array());
82+
$serializer = new Serializer(array(new TestNormalizer()), array());
8383
$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'));
8585
}
8686

8787
public function testCustomNormalizerCanNormalizeCollectionsAndScalar()
8888
{
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'));
9494
}
9595

9696
public function testSerialize()
9797
{
98-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
98+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
9999
$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');
101101
$this->assertEquals(json_encode($data), $result);
102102
}
103103

104104
public function testSerializeScalar()
105105
{
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');
108108
$this->assertEquals('"foo"', $result);
109109
}
110110

111111
public function testSerializeArrayOfScalars()
112112
{
113-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
113+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
114114
$data = array('foo', array(5, 3));
115-
$result = $this->serializer->serialize($data, 'json');
115+
$result = $serializer->serialize($data, 'json');
116116
$this->assertEquals(json_encode($data), $result);
117117
}
118118

@@ -121,36 +121,36 @@ public function testSerializeArrayOfScalars()
121121
*/
122122
public function testSerializeNoEncoder()
123123
{
124-
$this->serializer = new Serializer(array(), array());
124+
$serializer = new Serializer(array(), array());
125125
$data = array('title' => 'foo', 'numbers' => array(5, 3));
126-
$this->serializer->serialize($data, 'json');
126+
$serializer->serialize($data, 'json');
127127
}
128128

129129
/**
130130
* @expectedException \Symfony\Component\Serializer\Exception\LogicException
131131
*/
132132
public function testSerializeNoNormalizer()
133133
{
134-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
134+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
135135
$data = array('title' => 'foo', 'numbers' => array(5, 3));
136-
$this->serializer->serialize(Model::fromArray($data), 'json');
136+
$serializer->serialize(Model::fromArray($data), 'json');
137137
}
138138

139139
public function testDeserialize()
140140
{
141-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
141+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
142142
$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');
144144
$this->assertEquals($data, $result->toArray());
145145
}
146146

147147
public function testDeserializeUseCache()
148148
{
149-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
149+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
150150
$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');
152152
$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');
154154
$this->assertEquals($data, $result->toArray());
155155
}
156156

@@ -159,65 +159,65 @@ public function testDeserializeUseCache()
159159
*/
160160
public function testDeserializeNoNormalizer()
161161
{
162-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
162+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
163163
$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');
165165
}
166166

167167
/**
168168
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
169169
*/
170170
public function testDeserializeWrongNormalizer()
171171
{
172-
$this->serializer = new Serializer(array(new CustomNormalizer()), array('json' => new JsonEncoder()));
172+
$serializer = new Serializer(array(new CustomNormalizer()), array('json' => new JsonEncoder()));
173173
$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');
175175
}
176176

177177
/**
178178
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
179179
*/
180180
public function testDeserializeNoEncoder()
181181
{
182-
$this->serializer = new Serializer(array(), array());
182+
$serializer = new Serializer(array(), array());
183183
$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');
185185
}
186186

187187
public function testDeserializeSupported()
188188
{
189-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array());
189+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array());
190190
$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'));
192192
}
193193

194194
public function testDeserializeNotSupported()
195195
{
196-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array());
196+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array());
197197
$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'));
199199
}
200200

201201
public function testDeserializeNotSupportedMissing()
202202
{
203-
$this->serializer = new Serializer(array(), array());
203+
$serializer = new Serializer(array(), array());
204204
$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'));
206206
}
207207

208208
public function testEncode()
209209
{
210-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
210+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
211211
$data = array('foo', array(5, 3));
212-
$result = $this->serializer->encode($data, 'json');
212+
$result = $serializer->encode($data, 'json');
213213
$this->assertEquals(json_encode($data), $result);
214214
}
215215

216216
public function testDecode()
217217
{
218-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
218+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
219219
$data = array('foo', array(5, 3));
220-
$result = $this->serializer->decode(json_encode($data), 'json');
220+
$result = $serializer->decode(json_encode($data), 'json');
221221
$this->assertEquals($data, $result);
222222
}
223223
}

0 commit comments

Comments
 (0)