|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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 Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; |
| 15 | + |
| 16 | +class AbstractObjectNormalizerTest extends \PHPUnit_Framework_TestCase |
| 17 | +{ |
| 18 | + public function testDenormalize() |
| 19 | + { |
| 20 | + $normalizer = new AbstractObjectNormalizerDummy(); |
| 21 | + $normalizedData = $normalizer->denormalize(array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'), __NAMESPACE__.'\Dummy'); |
| 22 | + |
| 23 | + $this->assertSame('foo', $normalizedData->foo); |
| 24 | + $this->assertNull($normalizedData->bar); |
| 25 | + $this->assertSame('baz', $normalizedData->baz); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer |
| 30 | +{ |
| 31 | + protected function extractAttributes($object, $format = null, array $context = array()) |
| 32 | + { |
| 33 | + } |
| 34 | + |
| 35 | + protected function getAttributeValue($object, $attribute, $format = null, array $context = array()) |
| 36 | + { |
| 37 | + } |
| 38 | + |
| 39 | + protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array()) |
| 40 | + { |
| 41 | + $object->$attribute = $value; |
| 42 | + } |
| 43 | + |
| 44 | + protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array()) |
| 45 | + { |
| 46 | + return in_array($attribute, array('foo', 'baz')); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +class Dummy |
| 51 | +{ |
| 52 | + public $foo; |
| 53 | + public $bar; |
| 54 | + public $baz; |
| 55 | +} |
0 commit comments