Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / serializer / Tests / Normalizer / PropertyNormalizerTest.php
index 73b5f689c1d901d5e8f0daf0bcbeefb2b8a7f45a..29c2127a27973d088ebe6c3d6c06e054b0ac8982 100644 (file)
@@ -20,6 +20,7 @@ use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
 use Symfony\Component\Serializer\Serializer;
 use Symfony\Component\Serializer\SerializerInterface;
 use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy;
+use Symfony\Component\Serializer\Tests\Fixtures\GroupDummyChild;
 use Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy;
 use Symfony\Component\Serializer\Tests\Fixtures\PropertyCircularReferenceDummy;
 use Symfony\Component\Serializer\Tests\Fixtures\PropertySiblingHolder;
@@ -65,6 +66,35 @@ class PropertyNormalizerTest extends TestCase
         $this->assertEquals('bar', $obj->getBar());
     }
 
+    public function testNormalizeWithParentClass()
+    {
+        $group = new GroupDummyChild();
+        $group->setBaz('baz');
+        $group->setFoo('foo');
+        $group->setBar('bar');
+        $group->setKevin('Kevin');
+        $group->setCoopTilleuls('coop');
+        $this->assertEquals(
+            array('foo' => 'foo', 'bar' => 'bar', 'kevin' => 'Kevin',
+                  'coopTilleuls' => 'coop', 'fooBar' => null, 'symfony' => null, 'baz' => 'baz', ),
+            $this->normalizer->normalize($group, 'any')
+        );
+    }
+
+    public function testDenormalizeWithParentClass()
+    {
+        $obj = $this->normalizer->denormalize(
+            array('foo' => 'foo', 'bar' => 'bar', 'kevin' => 'Kevin', 'baz' => 'baz'),
+            GroupDummyChild::class,
+            'any'
+        );
+        $this->assertEquals('foo', $obj->getFoo());
+        $this->assertEquals('bar', $obj->getBar());
+        $this->assertEquals('Kevin', $obj->getKevin());
+        $this->assertEquals('baz', $obj->getBaz());
+        $this->assertNull($obj->getSymfony());
+    }
+
     public function testConstructorDenormalize()
     {
         $obj = $this->normalizer->denormalize(
@@ -147,12 +177,14 @@ class PropertyNormalizerTest extends TestCase
             'bar' => 'bar',
         ), $this->normalizer->normalize($obj, null, array(PropertyNormalizer::GROUPS => array('c'))));
 
-        // The PropertyNormalizer is not able to hydrate properties from parent classes
+        // The PropertyNormalizer is also able to hydrate properties from parent classes
         $this->assertEquals(array(
             'symfony' => 'symfony',
             'foo' => 'foo',
             'fooBar' => 'fooBar',
             'bar' => 'bar',
+            'kevin' => 'kevin',
+            'coopTilleuls' => 'coopTilleuls',
         ), $this->normalizer->normalize($obj, null, array(PropertyNormalizer::GROUPS => array('a', 'c'))));
     }
 
@@ -409,6 +441,11 @@ class PropertyNormalizerTest extends TestCase
 
         $this->assertEquals($expected, $result);
     }
+
+    public function testInheritedPropertiesSupport()
+    {
+        $this->assertTrue($this->normalizer->supportsNormalization(new PropertyChildDummy()));
+    }
 }
 
 class PropertyDummy
@@ -477,3 +514,12 @@ class StaticPropertyDummy
 {
     private static $property = 'value';
 }
+
+class PropertyParentDummy
+{
+    private $foo = 'bar';
+}
+
+class PropertyChildDummy extends PropertyParentDummy
+{
+}