Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / serializer / Tests / Normalizer / AbstractObjectNormalizerTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Serializer\Tests\Normalizer;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
16
17 class AbstractObjectNormalizerTest extends TestCase
18 {
19     public function testDenormalize()
20     {
21         $normalizer = new AbstractObjectNormalizerDummy();
22         $normalizedData = $normalizer->denormalize(array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'), __NAMESPACE__.'\Dummy');
23
24         $this->assertSame('foo', $normalizedData->foo);
25         $this->assertNull($normalizedData->bar);
26         $this->assertSame('baz', $normalizedData->baz);
27     }
28
29     /**
30      * @group legacy
31      */
32     public function testInstantiateObjectDenormalizer()
33     {
34         $data = array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz');
35         $class = __NAMESPACE__.'\Dummy';
36         $context = array();
37
38         $normalizer = new AbstractObjectNormalizerDummy();
39
40         $this->assertInstanceOf(__NAMESPACE__.'\Dummy', $normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), array()));
41     }
42 }
43
44 class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
45 {
46     protected function extractAttributes($object, $format = null, array $context = array())
47     {
48     }
49
50     protected function getAttributeValue($object, $attribute, $format = null, array $context = array())
51     {
52     }
53
54     protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
55     {
56         $object->$attribute = $value;
57     }
58
59     protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array())
60     {
61         return in_array($attribute, array('foo', 'baz'));
62     }
63
64     public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, $format = null)
65     {
66         return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format);
67     }
68 }
69
70 class Dummy
71 {
72     public $foo;
73     public $bar;
74     public $baz;
75 }