Skip to content

Commit 430e238

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Fix license headers Ensure the ClockMock is loaded before using it in the testsuite Fix with_minutes option in time widget Fixed properties not explicitily declared
2 parents 19a34e8 + c4bfe09 commit 430e238

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
@@ -41,21 +41,21 @@ public function testInterface()
4141
*/
4242
public function testNormalizeNoMatch()
4343
{
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');
4646
}
4747

4848
public function testNormalizeTraversable()
4949
{
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');
5252
$this->assertEquals('{"foo":"foo","bar":"bar"}', $result);
5353
}
5454

5555
public function testNormalizeGivesPriorityToInterfaceOverTraversable()
5656
{
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');
5959
$this->assertEquals('{"foo":"normalizedFoo","bar":"normalizedBar"}', $result);
6060
}
6161

@@ -64,58 +64,58 @@ public function testNormalizeGivesPriorityToInterfaceOverTraversable()
6464
*/
6565
public function testNormalizeOnDenormalizer()
6666
{
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'));
6969
}
7070

7171
/**
7272
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
7373
*/
7474
public function testDenormalizeNoMatch()
7575
{
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');
7878
}
7979

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

9090
public function testCustomNormalizerCanNormalizeCollectionsAndScalar()
9191
{
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'));
9797
}
9898

9999
public function testSerialize()
100100
{
101-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
101+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
102102
$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');
104104
$this->assertEquals(json_encode($data), $result);
105105
}
106106

107107
public function testSerializeScalar()
108108
{
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');
111111
$this->assertEquals('"foo"', $result);
112112
}
113113

114114
public function testSerializeArrayOfScalars()
115115
{
116-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
116+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
117117
$data = array('foo', array(5, 3));
118-
$result = $this->serializer->serialize($data, 'json');
118+
$result = $serializer->serialize($data, 'json');
119119
$this->assertEquals(json_encode($data), $result);
120120
}
121121

@@ -124,36 +124,36 @@ public function testSerializeArrayOfScalars()
124124
*/
125125
public function testSerializeNoEncoder()
126126
{
127-
$this->serializer = new Serializer(array(), array());
127+
$serializer = new Serializer(array(), array());
128128
$data = array('title' => 'foo', 'numbers' => array(5, 3));
129-
$this->serializer->serialize($data, 'json');
129+
$serializer->serialize($data, 'json');
130130
}
131131

132132
/**
133133
* @expectedException \Symfony\Component\Serializer\Exception\LogicException
134134
*/
135135
public function testSerializeNoNormalizer()
136136
{
137-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
137+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
138138
$data = array('title' => 'foo', 'numbers' => array(5, 3));
139-
$this->serializer->serialize(Model::fromArray($data), 'json');
139+
$serializer->serialize(Model::fromArray($data), 'json');
140140
}
141141

142142
public function testDeserialize()
143143
{
144-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
144+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
145145
$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');
147147
$this->assertEquals($data, $result->toArray());
148148
}
149149

150150
public function testDeserializeUseCache()
151151
{
152-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
152+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
153153
$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');
155155
$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');
157157
$this->assertEquals($data, $result->toArray());
158158
}
159159

@@ -162,65 +162,65 @@ public function testDeserializeUseCache()
162162
*/
163163
public function testDeserializeNoNormalizer()
164164
{
165-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
165+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
166166
$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');
168168
}
169169

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

180180
/**
181181
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
182182
*/
183183
public function testDeserializeNoEncoder()
184184
{
185-
$this->serializer = new Serializer(array(), array());
185+
$serializer = new Serializer(array(), array());
186186
$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');
188188
}
189189

190190
public function testDeserializeSupported()
191191
{
192-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array());
192+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array());
193193
$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'));
195195
}
196196

197197
public function testDeserializeNotSupported()
198198
{
199-
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array());
199+
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array());
200200
$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'));
202202
}
203203

204204
public function testDeserializeNotSupportedMissing()
205205
{
206-
$this->serializer = new Serializer(array(), array());
206+
$serializer = new Serializer(array(), array());
207207
$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'));
209209
}
210210

211211
public function testEncode()
212212
{
213-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
213+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
214214
$data = array('foo', array(5, 3));
215-
$result = $this->serializer->encode($data, 'json');
215+
$result = $serializer->encode($data, 'json');
216216
$this->assertEquals(json_encode($data), $result);
217217
}
218218

219219
public function testDecode()
220220
{
221-
$this->serializer = new Serializer(array(), array('json' => new JsonEncoder()));
221+
$serializer = new Serializer(array(), array('json' => new JsonEncoder()));
222222
$data = array('foo', array(5, 3));
223-
$result = $this->serializer->decode(json_encode($data), 'json');
223+
$result = $serializer->decode(json_encode($data), 'json');
224224
$this->assertEquals($data, $result);
225225
}
226226

0 commit comments

Comments
 (0)