StructEncoder example


        );

        $registry = new StaticDefinitionInstanceRegistry(
            [SalesChannelProductDefinition::class],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        $serializer = new Serializer([new StructNormalizer()][new JsonEncoder()]);

        $encoded = (new StructEncoder($this->getChainRegistry($registry)$serializer))->encode($productnew ResponseFields(null));

        static::assertArrayNotHasKey('cheapestPrice', $encoded);
        static::assertArrayHasKey('name', $encoded);
        static::assertEquals('test', $encoded['name']);
    }

    public function testNoneMappedFieldsAreNotExposed(): void
    {
        $product = new ExtendedProductEntity();
        $product->internalSetEntityData('product', new FieldVisibility([]));

        
$registry->method('has')
            ->willReturn(true);

        $definition = new MyEntityDefinition();
        $definition->compile(
            $this->getContainer()->get(DefinitionInstanceRegistry::class)
        );

        $registry->method('getByEntityName')
            ->willReturn($definition);

        $encoder = new StructEncoder(
            $registry,
            $this->getContainer()->get('serializer')
        );

        $encoded = $encoder->encode($entitynew ResponseFields(null));

        static::assertArrayHasKey('name', $encoded);
        static::assertArrayNotHasKey('description', $encoded);
        static::assertArrayHasKey('translated', $encoded);

        static::assertArrayHasKey('name', $encoded['translated']);
        
Home | Imprint | This part of the site doesn't use cookies.