コード例 #1
0
 public function testIgnoredAttributes()
 {
     $this->normalizer->setIgnoredAttributes(array('foo', 'bar', 'camelCase'));
     $obj = new PropertyDummy();
     $obj->foo = 'foo';
     $obj->setBar('bar');
     $this->assertEquals(array(), $this->normalizer->normalize($obj, 'any'));
 }
コード例 #2
0
 /**
  * @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');
 }
コード例 #3
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));
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 public function testNoTraversableSupport()
 {
     $this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
 }
コード例 #6
0
 public function testNoStaticPropertySupport()
 {
     $this->assertFalse($this->normalizer->supportsNormalization(new StaticPropertyDummy()));
 }
コード例 #7
0
 public function testDenormalizeNonExistingAttribute()
 {
     $this->assertEquals(new PropertyDummy(), $this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__ . '\\PropertyDummy'));
 }
コード例 #8
0
 public function benchSymfonyPropertyNormalizer()
 {
     $normalizer = new PropertyNormalizer();
     $normalizer->setCallbacks(array('createdAt' => function (\DateTime $date) {
         return $date->format(\DateTime::RFC3339);
     }));
     $normalizer->setIgnoredAttributes(['user', 'password']);
     $normalizers = array($normalizer);
     $encoders = array(new JsonEncoder());
     $symfony = new Serializer($normalizers, $encoders);
     return $symfony->serialize($this->data, 'json');
 }