/**
  * @expectedException \Symfony\Component\Serializer\Exception\LogicException
  * @expectedExceptionMessage Cannot normalize attribute "bar" because injected serializer is not a normalizer
  */
 public function testUnableToNormalizeObjectAttribute()
 {
     $serializer = $this->getMock('Symfony\\Component\\Serializer\\SerializerInterface');
     $this->normalizer->setSerializer($serializer);
     $obj = new PropertyDummy();
     $object = new \stdClass();
     $obj->setBar($object);
     $this->normalizer->normalize($obj, 'any');
 }
Exemplo n.º 2
0
 public function testCircularReferenceHandler()
 {
     $serializer = new Serializer(array($this->normalizer));
     $this->normalizer->setSerializer($serializer);
     $this->normalizer->setCircularReferenceHandler(function ($obj) {
         return get_class($obj);
     });
     $obj = new PropertyCircularReferenceDummy();
     $expected = array('me' => 'Symfony\\Component\\Serializer\\Tests\\Fixtures\\PropertyCircularReferenceDummy');
     $this->assertEquals($expected, $this->normalizer->normalize($obj));
 }
 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);
 }
 protected function setUp()
 {
     $this->normalizer = new PropertyNormalizer();
     $this->normalizer->setSerializer($this->getMock('Symfony\\Component\\Serializer\\Serializer'));
 }