Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Jul 4, 2016
1 parent 4884a2e commit f361e52
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
Expand Up @@ -335,7 +335,7 @@ protected function instantiateComplexObject(array &$data, $class, array &$contex
if ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) {
$parameterData = $data[$key];
if (null !== $constructorParameter->getClass()) {
$parameterData = $this->serializer->deserialize($parameterData, $constructorParameter->getClass()->getName(), null, $context);
$parameterData = $this->serializer->deserialize($parameterData, $constructorParameter->getClass()->getName(), $format, $context);
}

// Don't run set for a parameter passed to the constructor
Expand Down
@@ -0,0 +1,43 @@
<?php

namespace Symfony\Component\Serializer\Tests\Fixtures;

use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @author Théo FIDRY <theo.fidry@gmail.com>
*/
class DenormalizerDecoratorSerializer implements SerializerInterface
{
private $normalizer;

/**
* @param NormalizerInterface|DenormalizerInterface $normalizer
*/
public function __construct($normalizer)
{
if (false === $normalizer instanceof NormalizerInterface && false === $normalizer instanceof DenormalizerInterface) {
throw new \InvalidArgumentException();
}

$this->normalizer = $normalizer;
}

/**
* {@inheritdoc}
*/
public function serialize($data, $format, array $context = array())
{
return $this->normalizer->normalize($data, $format, $context);
}

/**
* {@inheritdoc}
*/
public function deserialize($data, $type, $format, array $context = array())
{
return $this->normalizer->denormalize($data, $type, $format, $context);
}
}
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy;
use Symfony\Component\Serializer\Tests\Fixtures\DenormalizerDecoratorSerializer;
use Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy;
use Symfony\Component\Serializer\Tests\Fixtures\SiblingHolder;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
Expand Down Expand Up @@ -167,12 +168,16 @@ public function testConstructorWithObjectTypeHintDenormalize()
),
);

$obj = $this->normalizer->denormalize($data, DummyWithConstructorObject::class);
$normalizer = new ObjectNormalizer();
$serializer = new DenormalizerDecoratorSerializer($normalizer);
$normalizer->setSerializer($serializer);

$obj = $normalizer->denormalize($data, DummyWithConstructorObject::class);
$this->assertInstanceOf(DummyWithConstructorObject::class, $obj);
$this->assertEquals(10, $obj->getId);
$this->assertEquals(10, $obj->getId());
$this->assertInstanceOf(ObjectInner::class, $obj->getInner());
$this->assertEquals('foo', $obj->getInner()->foo);
$this->assertEquals('bar', $obj->getInner()->bar);
$this->assertEquals('oof', $obj->getInner()->foo);
$this->assertEquals('rab', $obj->getInner()->bar);
}

public function testGroupsNormalize()
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Serializer/composer.json
Expand Up @@ -16,12 +16,12 @@
}
],
"require": {
"php": ">=5.5.9"
"php": ">=5.5.9",
"symfony/property-access": "^3.1"
},
"require-dev": {
"symfony/yaml": "~2.8|~3.0",
"symfony/config": "~2.8|~3.0",
"symfony/property-access": "~2.8|~3.0",
"symfony/http-foundation": "~2.8|~3.0",
"symfony/cache": "~3.1",
"symfony/property-info": "~2.8|~3.0",
Expand Down

0 comments on commit f361e52

Please sign in to comment.