Esempio n. 1
0
 public function testGroupsNormalize()
 {
     $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
     $this->normalizer = new PropertyNormalizer($classMetadataFactory);
     $this->normalizer->setSerializer($this->serializer);
     $obj = new GroupDummy();
     $obj->setFoo('foo');
     $obj->setBar('bar');
     $obj->setFooBar('fooBar');
     $obj->setSymfony('symfony');
     $obj->setKevin('kevin');
     $obj->setCoopTilleuls('coopTilleuls');
     $this->assertEquals(array('bar' => 'bar'), $this->normalizer->normalize($obj, null, array('groups' => array('c'))));
     // The PropertyNormalizer is not able to hydrate properties from parent classes
     $this->assertEquals(array('symfony' => 'symfony', 'foo' => 'foo', 'fooBar' => 'fooBar', 'bar' => 'bar'), $this->normalizer->normalize($obj, null, array('groups' => array('a', 'c'))));
 }
 public function testGroupsNormalizeWithNameConverter()
 {
     $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
     $this->normalizer = new ObjectNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
     $this->normalizer->setSerializer($this->serializer);
     $obj = new GroupDummy();
     $obj->setFooBar('@dunglas');
     $obj->setSymfony('@coopTilleuls');
     $obj->setCoopTilleuls('les-tilleuls.coop');
     $this->assertEquals(array('bar' => null, 'foo_bar' => '@dunglas', 'symfony' => '@coopTilleuls'), $this->normalizer->normalize($obj, null, array(ObjectNormalizer::GROUPS => array('name_converter'))));
 }
 public function testGroupsNormalize()
 {
     $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
     $this->normalizer = new GetSetMethodNormalizer($classMetadataFactory);
     $this->normalizer->setSerializer($this->serializer);
     $obj = new GroupDummy();
     $obj->setFoo('foo');
     $obj->setBar('bar');
     $obj->setFooBar('fooBar');
     $obj->setSymfony('symfony');
     $obj->setKevin('kevin');
     $obj->setCoopTilleuls('coopTilleuls');
     $this->assertEquals(array('bar' => 'bar'), $this->normalizer->normalize($obj, null, array('groups' => array('c'))));
     $this->assertEquals(array('symfony' => 'symfony', 'foo' => 'foo', 'fooBar' => 'fooBar', 'bar' => 'bar', 'kevin' => 'kevin', 'coopTilleuls' => 'coopTilleuls'), $this->normalizer->normalize($obj, null, array('groups' => array('a', 'c'))));
 }