Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / serializer / Tests / SerializerTest.php
index 73feb76d451e6924a6f6a4eba0d82f238902162a..f7f8594cb12bcc166829ac8d566bbc37b171df0e 100644 (file)
@@ -13,6 +13,10 @@ namespace Symfony\Component\Serializer\Tests;
 
 use PHPUnit\Framework\TestCase;
 use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
+use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
+use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
+use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
+use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
 use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
 use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
 use Symfony\Component\Serializer\Serializer;
@@ -313,6 +317,35 @@ class SerializerTest extends TestCase
             $serializer->deserialize($jsonData, __NAMESPACE__.'\Model[]', 'json')
         );
     }
+
+    public function testNormalizerAware()
+    {
+        $normalizerAware = $this->getMockBuilder(NormalizerAwareInterface::class)->getMock();
+        $normalizerAware->expects($this->once())
+            ->method('setNormalizer')
+            ->with($this->isInstanceOf(NormalizerInterface::class));
+
+        new Serializer(array($normalizerAware));
+    }
+
+    public function testDenormalizerAware()
+    {
+        $denormalizerAware = $this->getMockBuilder(DenormalizerAwareInterface::class)->getMock();
+        $denormalizerAware->expects($this->once())
+            ->method('setDenormalizer')
+            ->with($this->isInstanceOf(DenormalizerInterface::class));
+
+        new Serializer(array($denormalizerAware));
+    }
+
+    public function testDeserializeObjectConstructorWithObjectTypeHint()
+    {
+        $jsonData = '{"bar":{"value":"baz"}}';
+
+        $serializer = new Serializer(array(new ObjectNormalizer()), array('json' => new JsonEncoder()));
+
+        $this->assertEquals(new Foo(new Bar('baz')), $serializer->deserialize($jsonData, Foo::class, 'json'));
+    }
 }
 
 class Model
@@ -358,3 +391,23 @@ class Model
         return array('title' => $this->title, 'numbers' => $this->numbers);
     }
 }
+
+class Foo
+{
+    private $bar;
+
+    public function __construct(Bar $bar)
+    {
+        $this->bar = $bar;
+    }
+}
+
+class Bar
+{
+    private $value;
+
+    public function __construct($value)
+    {
+        $this->value = $value;
+    }
+}