X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fserializer%2FTests%2FNormalizer%2FPropertyNormalizerTest.php;fp=vendor%2Fsymfony%2Fserializer%2FTests%2FNormalizer%2FPropertyNormalizerTest.php;h=29c2127a27973d088ebe6c3d6c06e054b0ac8982;hp=73b5f689c1d901d5e8f0daf0bcbeefb2b8a7f45a;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/symfony/serializer/Tests/Normalizer/PropertyNormalizerTest.php b/vendor/symfony/serializer/Tests/Normalizer/PropertyNormalizerTest.php index 73b5f689c..29c2127a2 100644 --- a/vendor/symfony/serializer/Tests/Normalizer/PropertyNormalizerTest.php +++ b/vendor/symfony/serializer/Tests/Normalizer/PropertyNormalizerTest.php @@ -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 +{ +}