use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy;
+use Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy;
use Symfony\Component\Serializer\Tests\Fixtures\PropertyCircularReferenceDummy;
use Symfony\Component\Serializer\Tests\Fixtures\PropertySiblingHolder;
$this->assertEquals('bar', $obj->getBar());
}
- /**
- * @group legacy
- */
- public function testLegacyDenormalizeOnCamelCaseFormat()
- {
- $this->normalizer->setCamelizedAttributes(array('camel_case'));
- $obj = $this->normalizer->denormalize(
- array('camel_case' => 'value'),
- __NAMESPACE__.'\PropertyDummy'
- );
- $this->assertEquals('value', $obj->getCamelCase());
- }
-
- /**
- * @group legacy
- */
- public function testLegacyCamelizedAttributesNormalize()
- {
- $obj = new PropertyCamelizedDummy('dunglas.fr');
- $obj->fooBar = 'les-tilleuls.coop';
- $obj->bar_foo = 'lostinthesupermarket.fr';
-
- $this->normalizer->setCamelizedAttributes(array('kevin_dunglas'));
- $this->assertEquals($this->normalizer->normalize($obj), array(
- 'kevin_dunglas' => 'dunglas.fr',
- 'fooBar' => 'les-tilleuls.coop',
- 'bar_foo' => 'lostinthesupermarket.fr',
- ));
-
- $this->normalizer->setCamelizedAttributes(array('foo_bar'));
- $this->assertEquals($this->normalizer->normalize($obj), array(
- 'kevinDunglas' => 'dunglas.fr',
- 'foo_bar' => 'les-tilleuls.coop',
- 'bar_foo' => 'lostinthesupermarket.fr',
- ));
- }
-
- /**
- * @group legacy
- */
- public function testLegacyCamelizedAttributesDenormalize()
- {
- $obj = new PropertyCamelizedDummy('dunglas.fr');
- $obj->fooBar = 'les-tilleuls.coop';
- $obj->bar_foo = 'lostinthesupermarket.fr';
-
- $this->normalizer->setCamelizedAttributes(array('kevin_dunglas'));
- $this->assertEquals($this->normalizer->denormalize(array(
- 'kevin_dunglas' => 'dunglas.fr',
- 'fooBar' => 'les-tilleuls.coop',
- 'bar_foo' => 'lostinthesupermarket.fr',
- ), __NAMESPACE__.'\PropertyCamelizedDummy'), $obj);
-
- $this->normalizer->setCamelizedAttributes(array('foo_bar'));
- $this->assertEquals($this->normalizer->denormalize(array(
- 'kevinDunglas' => 'dunglas.fr',
- 'foo_bar' => 'les-tilleuls.coop',
- 'bar_foo' => 'lostinthesupermarket.fr',
- ), __NAMESPACE__.'\PropertyCamelizedDummy'), $obj);
- }
-
- public function testNameConverterSupport()
- {
- $this->normalizer = new PropertyNormalizer(null, new CamelCaseToSnakeCaseNameConverter());
- $obj = $this->normalizer->denormalize(
- array('camel_case' => 'camelCase'),
- __NAMESPACE__.'\PropertyDummy'
- );
- $this->assertEquals('camelCase', $obj->getCamelCase());
- }
-
public function testConstructorDenormalize()
{
$obj = $this->normalizer->denormalize(
/**
* @expectedException \Symfony\Component\Serializer\Exception\LogicException
- * @expectedExceptionMessage Cannot normalize attribute "bar" because injected serializer is not a normalizer
+ * @expectedExceptionMessage Cannot normalize attribute "bar" because the injected serializer is not a normalizer
*/
public function testUnableToNormalizeObjectAttribute()
{
{
$this->assertFalse($this->normalizer->supportsNormalization(new StaticPropertyDummy()));
}
+
+ public function testMaxDepth()
+ {
+ $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
+ $this->normalizer = new PropertyNormalizer($classMetadataFactory);
+ $serializer = new Serializer(array($this->normalizer));
+ $this->normalizer->setSerializer($serializer);
+
+ $level1 = new MaxDepthDummy();
+ $level1->foo = 'level1';
+
+ $level2 = new MaxDepthDummy();
+ $level2->foo = 'level2';
+ $level1->child = $level2;
+
+ $level3 = new MaxDepthDummy();
+ $level3->foo = 'level3';
+ $level2->child = $level3;
+
+ $result = $serializer->normalize($level1, null, array(PropertyNormalizer::ENABLE_MAX_DEPTH => true));
+
+ $expected = array(
+ 'foo' => 'level1',
+ 'child' => array(
+ 'foo' => 'level2',
+ 'child' => array(
+ 'child' => null,
+ 'bar' => null,
+ ),
+ 'bar' => null,
+ ),
+ 'bar' => null,
+ );
+
+ $this->assertEquals($expected, $result);
+ }
}
class PropertyDummy