ObjectInner example


trait IgnoredAttributesTestTrait
{
    abstract protected function getNormalizerForIgnoredAttributes(): NormalizerInterface;

    abstract protected function getDenormalizerForIgnoredAttributes(): DenormalizerInterface;

    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(
            [
                

trait AttributesTestTrait
{
    abstract protected function getNormalizerForAttributes(): NormalizerInterface;

    abstract protected function getDenormalizerForAttributes(): DenormalizerInterface;

    public function testAttributesNormalize()
    {
        $normalizer = $this->getNormalizerForAttributes();

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

        $objectDummy = new ObjectDummy();
        $objectDummy->setFoo('foo');
        $objectDummy->setBaz(true);
        $objectDummy->setObject($objectInner);

        $context = ['attributes' => ['foo', 'baz', 'object' => ['foo']]];
        $this->assertEquals(
            [
                
$denormalizer = $this->getDenormalizerForObjectToPopulate();
        $denormalizer->denormalize(['foo' => 'bar'], ToBeProxyfiedDummy::class, null, $context);

        $this->assertSame('bar', $proxyDummy->getFoo());
    }

    public function testObjectToPopulateNoMatch()
    {
        $this->markTestSkipped('something broken here!');
        $denormalizer = $this->getDenormalizerForObjectToPopulate();

        $objectToPopulate = new ObjectInner();
        $objectToPopulate->foo = 'foo';

        $outer = $denormalizer->denormalize([
            'foo' => 'foo',
            'inner' => [
                'bar' => 'bar',
            ],
        ], ObjectOuter::class, null, ['object_to_popuplate' => $objectToPopulate]);

        $this->assertInstanceOf(ObjectOuter::class$outer);
        $inner = $outer->getInner();
        
public function testNormalizeObjectWithUninitializedProperties()
    {
        $obj = new Php74Dummy();
        $this->assertEquals(
            ['initializedProperty' => 'defaultValue'],
            $this->normalizer->normalize($obj, 'any')
        );
    }

    public function testNormalizeObjectWithUnsetProperties()
    {
        $obj = new ObjectInner();
        unset($obj->foo);
        $this->assertEquals(
            ['bar' => null],
            $this->normalizer->normalize($obj, 'any')
        );
    }

    public function testNormalizeObjectWithLazyProperties()
    {
        $obj = new LazyObjectInner();
        unset($obj->foo);
        
Home | Imprint | This part of the site doesn't use cookies.