Skip to content

Commit d23de60

Browse files
committed
Merge branch '2.2'
* 2.2: fixed CS Fixed XML syntax. Fixed parsing of leading blank lines in folded scalars. Closes #7989. [Form] Fixed a method name. Added a test case for Loader::import(). Fixed Loader import [Console] Added dedicated testcase for HelperSet class [Serializer] fixed CS (refs #7971) Fixed fatal error in normalize/denormalizeObject. Fixed 2 namespaces Conflicts: src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php
2 parents 54248f2 + 8cfdd4a commit d23de60

File tree

4 files changed

+101
-9
lines changed

4 files changed

+101
-9
lines changed

Serializer.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ public function supportsDenormalization($data, $type, $format = null)
173173
private function getNormalizer($data, $format = null)
174174
{
175175
foreach ($this->normalizers as $normalizer) {
176-
if ($normalizer instanceof NormalizerInterface
177-
&& $normalizer->supportsNormalization($data, $format)
178-
) {
176+
if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($data, $format)) {
179177
return $normalizer;
180178
}
181179
}
@@ -189,9 +187,7 @@ private function getNormalizer($data, $format = null)
189187
private function getDenormalizer($data, $type, $format = null)
190188
{
191189
foreach ($this->normalizers as $normalizer) {
192-
if ($normalizer instanceof DenormalizerInterface
193-
&& $normalizer->supportsDenormalization($data, $type, $format)
194-
) {
190+
if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $type, $format)) {
195191
return $normalizer;
196192
}
197193
}
@@ -239,7 +235,8 @@ private function normalizeObject($object, $format = null, array $context = array
239235
}
240236

241237
foreach ($this->normalizers as $normalizer) {
242-
if ($normalizer->supportsNormalization($object, $format)) {
238+
if ($normalizer instanceof NormalizerInterface
239+
&& $normalizer->supportsNormalization($object, $format)) {
243240
$this->normalizerCache[$class][$format] = $normalizer;
244241

245242
return $normalizer->normalize($object, $format, $context);
@@ -273,7 +270,8 @@ private function denormalizeObject($data, $class, $format = null, array $context
273270
}
274271

275272
foreach ($this->normalizers as $normalizer) {
276-
if ($normalizer->supportsDenormalization($data, $class, $format)) {
273+
if ($normalizer instanceof DenormalizerInterface
274+
&& $normalizer->supportsDenormalization($data, $class, $format)) {
277275
$this->denormalizerCache[$class][$format] = $normalizer;
278276

279277
return $normalizer->denormalize($data, $class, $format, $context);

Tests/Normalizer/TestDenormalizer.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Normalizer;
13+
14+
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
15+
16+
/**
17+
* Provides a test Normalizer which only implements the DenormalizerInterface.
18+
*
19+
* @author Lin Clark <lin@lin-clark.com>
20+
*/
21+
class TestDenormalizer implements DenormalizerInterface
22+
{
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function denormalize($data, $class, $format = null, array $context = array())
27+
{
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function supportsDenormalization($data, $type, $format = null)
34+
{
35+
return true;
36+
}
37+
}

Tests/Normalizer/TestNormalizer.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Normalizer;
13+
14+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
15+
16+
/**
17+
* Provides a test Normalizer which only implements the NormalizerInterface.
18+
*
19+
* @author Lin Clark <lin@lin-clark.com>
20+
*/
21+
class TestNormalizer implements NormalizerInterface
22+
{
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function normalize($object, $format = null, array $context = array())
27+
{
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function supportsNormalization($data, $format = null)
34+
{
35+
return true;
36+
}
37+
}

Tests/SerializerTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
1818
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
1919
use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy;
20+
use Symfony\Component\Serializer\Tests\Normalizer\TestNormalizer;
21+
use Symfony\Component\Serializer\Tests\Normalizer\TestDenormalizer;
2022

2123
class SerializerTest extends \PHPUnit_Framework_TestCase
2224
{
@@ -43,6 +45,15 @@ public function testNormalizeGivesPriorityToInterfaceOverTraversable()
4345
$this->assertEquals('{"foo":"normalizedFoo","bar":"normalizedBar"}', $result);
4446
}
4547

48+
/**
49+
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
50+
*/
51+
public function testNormalizeOnDenormalizer()
52+
{
53+
$this->serializer = new Serializer(array(new TestDenormalizer()), array());
54+
$this->assertTrue($this->serializer->normalize(new \stdClass, 'json'));
55+
}
56+
4657
/**
4758
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
4859
*/
@@ -52,6 +63,16 @@ public function testDenormalizeNoMatch()
5263
$this->serializer->denormalize('foo', 'stdClass');
5364
}
5465

66+
/**
67+
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
68+
*/
69+
public function testDenormalizeOnNormalizer()
70+
{
71+
$this->serializer = new Serializer(array(new TestNormalizer()), array());
72+
$data = array('title' => 'foo', 'numbers' => array(5, 3));
73+
$this->assertTrue($this->serializer->denormalize(json_encode($data), 'stdClass', 'json'));
74+
}
75+
5576
public function testSerialize()
5677
{
5778
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
@@ -223,5 +244,4 @@ public function toArray()
223244
{
224245
return array('title' => $this->title, 'numbers' => $this->numbers);
225246
}
226-
227247
}

0 commit comments

Comments
 (0)