[Serializer] AbstractNormalizer::instantiateObject avoid null
rejection
This commit is contained in:
parent
58efb98c6f
commit
d546080d20
@ -59,8 +59,8 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
/**
|
/**
|
||||||
* Sets the {@link ClassMetadataFactoryInterface} to use.
|
* Sets the {@link ClassMetadataFactoryInterface} to use.
|
||||||
*
|
*
|
||||||
* @param ClassMetadataFactoryInterface|null $classMetadataFactory
|
* @param ClassMetadataFactoryInterface|null $classMetadataFactory
|
||||||
* @param NameConverterInterface|null $nameConverter
|
* @param NameConverterInterface|null $nameConverter
|
||||||
*/
|
*/
|
||||||
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null)
|
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null)
|
||||||
{
|
{
|
||||||
@ -324,7 +324,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
|
|
||||||
$allowed = $allowedAttributes === false || in_array($paramName, $allowedAttributes);
|
$allowed = $allowedAttributes === false || in_array($paramName, $allowedAttributes);
|
||||||
$ignored = in_array($paramName, $this->ignoredAttributes);
|
$ignored = in_array($paramName, $this->ignoredAttributes);
|
||||||
if ($allowed && !$ignored && isset($data[$key])) {
|
if ($allowed && !$ignored && array_key_exists($key, $data)) {
|
||||||
$params[] = $data[$key];
|
$params[] = $data[$key];
|
||||||
// don't run set for a parameter passed to the constructor
|
// don't run set for a parameter passed to the constructor
|
||||||
unset($data[$key]);
|
unset($data[$key]);
|
||||||
|
@ -193,6 +193,16 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($obj->isBaz());
|
$this->assertTrue($obj->isBaz());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructorDenormalizeWithNullArgument()
|
||||||
|
{
|
||||||
|
$obj = $this->normalizer->denormalize(
|
||||||
|
array('foo' => 'foo', 'bar' => null, 'baz' => true),
|
||||||
|
__NAMESPACE__.'\GetConstructorDummy', 'any');
|
||||||
|
$this->assertEquals('foo', $obj->getFoo());
|
||||||
|
$this->assertNull($obj->getBar());
|
||||||
|
$this->assertTrue($obj->isBaz());
|
||||||
|
}
|
||||||
|
|
||||||
public function testConstructorDenormalizeWithMissingOptionalArgument()
|
public function testConstructorDenormalizeWithMissingOptionalArgument()
|
||||||
{
|
{
|
||||||
$obj = $this->normalizer->denormalize(
|
$obj = $this->normalizer->denormalize(
|
||||||
|
@ -137,6 +137,16 @@ class ObjectNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($obj->isBaz());
|
$this->assertTrue($obj->isBaz());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructorDenormalizeWithNullArgument()
|
||||||
|
{
|
||||||
|
$obj = $this->normalizer->denormalize(
|
||||||
|
array('foo' => 'foo', 'bar' => null, 'baz' => true),
|
||||||
|
__NAMESPACE__.'\ObjectConstructorDummy', 'any');
|
||||||
|
$this->assertEquals('foo', $obj->getFoo());
|
||||||
|
$this->assertNull($obj->bar);
|
||||||
|
$this->assertTrue($obj->isBaz());
|
||||||
|
}
|
||||||
|
|
||||||
public function testConstructorDenormalizeWithMissingOptionalArgument()
|
public function testConstructorDenormalizeWithMissingOptionalArgument()
|
||||||
{
|
{
|
||||||
$obj = $this->normalizer->denormalize(
|
$obj = $this->normalizer->denormalize(
|
||||||
|
@ -151,6 +151,17 @@ class PropertyNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('bar', $obj->getBar());
|
$this->assertEquals('bar', $obj->getBar());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructorDenormalizeWithNullArgument()
|
||||||
|
{
|
||||||
|
$obj = $this->normalizer->denormalize(
|
||||||
|
array('foo' => null, 'bar' => 'bar'),
|
||||||
|
__NAMESPACE__.'\PropertyConstructorDummy', '
|
||||||
|
any'
|
||||||
|
);
|
||||||
|
$this->assertNull($obj->getFoo());
|
||||||
|
$this->assertEquals('bar', $obj->getBar());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideCallbacks
|
* @dataProvider provideCallbacks
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user