AbstractObjectNormalizerTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Serializer\Tests\Normalizer;
  11. use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
  12. class AbstractObjectNormalizerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testDenormalize()
  15. {
  16. $normalizer = new AbstractObjectNormalizerDummy();
  17. $normalizedData = $normalizer->denormalize(array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'), __NAMESPACE__.'\Dummy');
  18. $this->assertSame('foo', $normalizedData->foo);
  19. $this->assertNull($normalizedData->bar);
  20. $this->assertSame('baz', $normalizedData->baz);
  21. }
  22. }
  23. class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
  24. {
  25. protected function extractAttributes($object, $format = null, array $context = array())
  26. {
  27. }
  28. protected function getAttributeValue($object, $attribute, $format = null, array $context = array())
  29. {
  30. }
  31. protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
  32. {
  33. $object->$attribute = $value;
  34. }
  35. protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array())
  36. {
  37. return in_array($attribute, array('foo', 'baz'));
  38. }
  39. }
  40. class Dummy
  41. {
  42. public $foo;
  43. public $bar;
  44. public $baz;
  45. }