setInner example



    public function testAttributesContextDenormalize()
    {
        $normalizer = $this->getDenormalizerForAttributes();

        $objectInner = new ObjectInner();
        $objectInner->foo = 'innerFoo';

        $objectOuter = new ObjectOuter();
        $objectOuter->bar = 'bar';
        $objectOuter->setInner($objectInner);

        $context = ['attributes' => ['bar', 'inner' => ['foo']]];
        $this->assertEquals($objectOuter$normalizer->denormalize(
            [
                'foo' => 'foo',
                'bar' => 'bar',
                'date' => '2017-02-03',
                'inner' => ['foo' => 'innerFoo', 'bar' => 'innerBar'],
            ], ObjectOuter::class, null, $context));
    }

    
public function testIgnoredAttributesNormalize()
    {
        $normalizer = $this->getNormalizerForIgnoredAttributes();

        $objectInner = new ObjectInner();
        $objectInner->foo = 'innerFoo';
        $objectInner->bar = 'innerBar';

        $objectOuter = new ObjectOuter();
        $objectOuter->foo = 'foo';
        $objectOuter->bar = 'bar';
        $objectOuter->setInner($objectInner);

        $context = ['ignored_attributes' => ['bar']];
        $this->assertEquals(
            [
                'foo' => 'foo',
                'inner' => ['foo' => 'innerFoo'],
                'date' => null,
                'inners' => null,
            ],
            $normalizer->normalize($objectOuter, null, $context)
        );

        
Home | Imprint | This part of the site doesn't use cookies.