Skip to content

Commit 6257035

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: (95 commits) [DependencyInjection] provide better error message when using deprecated configuration options [console][TableCell] get cell width without decoration. Improve the config validation in TwigBundle [VarDumper] Changed tooltip to expand-all keybinding in OS X [Bridge\PhpUnit] Fix composer installed phpunit detection [VarDumper] Fix generic casters calling order [2.7][SecurityBundle] Remove SecurityContext from Compile [WebProfilerBundle][logger] added missing deprecation message. Fix profiler CSS [Security][Acl] enforce string identifiers [FrameworkBundle] make `templating.helper.router` service available again for BC reasons [BrowserKit] Fix bug when uri starts with http. bumped Symfony version to 2.7.1 updated VERSION for 2.7.0 updated CHANGELOG for 2.7.0 bumped Symfony version to 2.6.10 updated VERSION for 2.6.9 updated CHANGELOG for 2.6.9 fixed tests bumped Symfony version to 2.3.31 ... Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/Translation/Loader/JsonFileLoader.php
2 parents c1275cc + 634d3ad commit 6257035

File tree

6 files changed

+111
-8
lines changed

6 files changed

+111
-8
lines changed

Normalizer/AbstractNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
5959
/**
6060
* Sets the {@link ClassMetadataFactoryInterface} to use.
6161
*
62-
* @param ClassMetadataFactoryInterface|null $classMetadataFactory
63-
* @param NameConverterInterface|null $nameConverter
62+
* @param ClassMetadataFactoryInterface|null $classMetadataFactory
63+
* @param NameConverterInterface|null $nameConverter
6464
*/
6565
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null)
6666
{
@@ -324,11 +324,11 @@ protected function instantiateObject(array $data, $class, array &$context, \Refl
324324

325325
$allowed = $allowedAttributes === false || in_array($paramName, $allowedAttributes);
326326
$ignored = in_array($paramName, $this->ignoredAttributes);
327-
if ($allowed && !$ignored && isset($data[$key])) {
327+
if ($allowed && !$ignored && array_key_exists($key, $data)) {
328328
$params[] = $data[$key];
329329
// don't run set for a parameter passed to the constructor
330330
unset($data[$key]);
331-
} elseif ($constructorParameter->isOptional()) {
331+
} elseif ($constructorParameter->isDefaultValueAvailable()) {
332332
$params[] = $constructorParameter->getDefaultValue();
333333
} else {
334334
throw new RuntimeException(

Normalizer/PropertyNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function normalize($object, $format = null, array $context = array())
5959
}
6060

6161
// Override visibility
62-
if (! $property->isPublic()) {
62+
if (!$property->isPublic()) {
6363
$property->setAccessible(true);
6464
}
6565

@@ -111,7 +111,7 @@ public function denormalize($data, $class, $format = null, array $context = arra
111111
$property = $reflectionClass->getProperty($propertyName);
112112

113113
// Override visibility
114-
if (! $property->isPublic()) {
114+
if (!$property->isPublic()) {
115115
$property->setAccessible(true);
116116
}
117117

@@ -151,7 +151,7 @@ private function supports($class)
151151

152152
// We look for at least one non-static property
153153
foreach ($class->getProperties() as $property) {
154-
if (! $property->isStatic()) {
154+
if (!$property->isStatic()) {
155155
return true;
156156
}
157157
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Serializer Component
22
====================
33

4-
With the Serializer component its possible to handle serializing data structures,
4+
With the Serializer component it's possible to handle serializing data structures,
55
including object graphs, into array structures or other formats like XML and JSON.
66
It can also handle deserializing XML and JSON back to object graphs.
77

Tests/Normalizer/GetSetMethodNormalizerTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ public function testConstructorDenormalize()
193193
$this->assertTrue($obj->isBaz());
194194
}
195195

196+
public function testConstructorDenormalizeWithNullArgument()
197+
{
198+
$obj = $this->normalizer->denormalize(
199+
array('foo' => 'foo', 'bar' => null, 'baz' => true),
200+
__NAMESPACE__.'\GetConstructorDummy', 'any');
201+
$this->assertEquals('foo', $obj->getFoo());
202+
$this->assertNull($obj->getBar());
203+
$this->assertTrue($obj->isBaz());
204+
}
205+
196206
public function testConstructorDenormalizeWithMissingOptionalArgument()
197207
{
198208
$obj = $this->normalizer->denormalize(
@@ -203,6 +213,15 @@ public function testConstructorDenormalizeWithMissingOptionalArgument()
203213
$this->assertEquals(array(1, 2, 3), $obj->getBaz());
204214
}
205215

216+
public function testConstructorDenormalizeWithOptionalDefaultArgument()
217+
{
218+
$obj = $this->normalizer->denormalize(
219+
array('bar' => 'test'),
220+
__NAMESPACE__.'\GetConstructorArgsWithDefaultValueDummy', 'any');
221+
$this->assertEquals(array(), $obj->getFoo());
222+
$this->assertEquals('test', $obj->getBar());
223+
}
224+
206225
public function testConstructorWithObjectDenormalize()
207226
{
208227
$data = new \stdClass();
@@ -650,6 +669,33 @@ public function otherMethod()
650669
}
651670
}
652671

672+
class GetConstructorArgsWithDefaultValueDummy
673+
{
674+
protected $foo;
675+
protected $bar;
676+
677+
public function __construct($foo = array(), $bar)
678+
{
679+
$this->foo = $foo;
680+
$this->bar = $bar;
681+
}
682+
683+
public function getFoo()
684+
{
685+
return $this->foo;
686+
}
687+
688+
public function getBar()
689+
{
690+
return $this->bar;
691+
}
692+
693+
public function otherMethod()
694+
{
695+
throw new \RuntimeException('Dummy::otherMethod() should not be called');
696+
}
697+
}
698+
653699
class GetCamelizedDummy
654700
{
655701
private $kevinDunglas;

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ public function testConstructorDenormalize()
137137
$this->assertTrue($obj->isBaz());
138138
}
139139

140+
public function testConstructorDenormalizeWithNullArgument()
141+
{
142+
$obj = $this->normalizer->denormalize(
143+
array('foo' => 'foo', 'bar' => null, 'baz' => true),
144+
__NAMESPACE__.'\ObjectConstructorDummy', 'any');
145+
$this->assertEquals('foo', $obj->getFoo());
146+
$this->assertNull($obj->bar);
147+
$this->assertTrue($obj->isBaz());
148+
}
149+
140150
public function testConstructorDenormalizeWithMissingOptionalArgument()
141151
{
142152
$obj = $this->normalizer->denormalize(
@@ -147,6 +157,15 @@ public function testConstructorDenormalizeWithMissingOptionalArgument()
147157
$this->assertEquals(array(1, 2, 3), $obj->getBaz());
148158
}
149159

160+
public function testConstructorDenormalizeWithOptionalDefaultArgument()
161+
{
162+
$obj = $this->normalizer->denormalize(
163+
array('bar' => 'test'),
164+
__NAMESPACE__.'\ObjectConstructorArgsWithDefaultValueDummy', 'any');
165+
$this->assertEquals(array(), $obj->getFoo());
166+
$this->assertEquals('test', $obj->getBar());
167+
}
168+
150169
public function testConstructorWithObjectDenormalize()
151170
{
152171
$data = new \stdClass();
@@ -556,3 +575,30 @@ public function otherMethod()
556575
throw new \RuntimeException('Dummy::otherMethod() should not be called');
557576
}
558577
}
578+
579+
class ObjectConstructorArgsWithDefaultValueDummy
580+
{
581+
protected $foo;
582+
protected $bar;
583+
584+
public function __construct($foo = array(), $bar)
585+
{
586+
$this->foo = $foo;
587+
$this->bar = $bar;
588+
}
589+
590+
public function getFoo()
591+
{
592+
return $this->foo;
593+
}
594+
595+
public function getBar()
596+
{
597+
return $this->bar;
598+
}
599+
600+
public function otherMethod()
601+
{
602+
throw new \RuntimeException('Dummy::otherMethod() should not be called');
603+
}
604+
}

Tests/Normalizer/PropertyNormalizerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ public function testConstructorDenormalize()
151151
$this->assertEquals('bar', $obj->getBar());
152152
}
153153

154+
public function testConstructorDenormalizeWithNullArgument()
155+
{
156+
$obj = $this->normalizer->denormalize(
157+
array('foo' => null, 'bar' => 'bar'),
158+
__NAMESPACE__.'\PropertyConstructorDummy', '
159+
any'
160+
);
161+
$this->assertNull($obj->getFoo());
162+
$this->assertEquals('bar', $obj->getBar());
163+
}
164+
154165
/**
155166
* @dataProvider provideCallbacks
156167
*/

0 commit comments

Comments
 (0)