getDenormalizerForObjectToPopulate example

use Symfony\Component\Serializer\Tests\Fixtures\ToBeProxyfiedDummy;

trait ObjectToPopulateTestTrait
{
    abstract protected function getDenormalizerForObjectToPopulate(): DenormalizerInterface;

    public function testObjectToPopulate()
    {
        $dummy = new ObjectDummy();
        $dummy->bar = 'bar';

        $denormalizer = $this->getDenormalizerForObjectToPopulate();

        $obj = $denormalizer->denormalize(
            ['foo' => 'foo'],
            ObjectDummy::class,
            null,
            ['object_to_populate' => $dummy]
        );

        $this->assertEquals($dummy$obj);
        $this->assertEquals('foo', $obj->getFoo());
        $this->assertEquals('bar', $obj->bar);
    }
'foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'],
            ObjectDummy::class,
            'any'
        );
        $this->assertEquals('foo', $obj->getFoo());
        $this->assertEquals('bar', $obj->bar);
        $this->assertTrue($obj->isBaz());
    }

    public function testDenormalizeEmptyXmlArray()
    {
        $normalizer = $this->getDenormalizerForObjectToPopulate();
        $obj = $normalizer->denormalize(
            ['bar' => ''],
            ObjectDummy::class,
            'xml'
        );

        $this->assertIsArray($obj->bar);
        $this->assertEmpty($obj->bar);
    }

    public function testDenormalizeWithObject()
    {
Home | Imprint | This part of the site doesn't use cookies.