Serializer example

use Symfony\Component\Serializer\Serializer;

/** * @internal * * @covers \Shopware\Core\Framework\MessageQueue\SendEmailMessageJsonSerializer */
class SendEmailMessageJsonSerializerTest extends TestCase
{
    public function testSerialize(): void
    {
        $serializer = new Serializer(
            [
                new SendEmailMessageJsonSerializer(),
            ],
            [
                new JsonEncoder(null),
            ]
        );
        $withoutSerializer = new Serializer([new ObjectNormalizer()][new JsonEncoder(null)]);

        $sendMail = new SendEmailMessage(
            new RawMessage('test'),
            
static::assertInstanceOf(SyncOperation::class$operations[0]);

                $operation = $operations[0];
                static::assertSame('delete-mapping', $operation->getKey());
                static::assertSame('product', $operation->getEntity());
                static::assertSame('delete', $operation->getAction());
                static::assertEquals($criteria$operation->getCriteria());

                return new SyncResult([]);
            });

        $controller = new SyncController($servicenew Serializer([][new JsonEncoder()]));

        $controller->sync($request, Context::createDefaultContext());
    }
}
static::assertEquals('foo', $offset->getLanguageId());
        static::assertEquals(['bar']$offset->getLanguages());
        static::assertTrue($offset->hasNextLanguage());
        $offset->selectNextLanguage();
        static::assertEquals('bar', $offset->getLanguageId());
        static::assertFalse($offset->hasNextLanguage());
    }

    public function testSerialize(): void
    {
        $serialize = new Serializer(
            [
                new ObjectNormalizer(),
            ],
            [
                new JsonEncoder(null),
            ]
        );

        $before = new IndexerOffset(
            ['foo', 'bar'],
            ['product', 'product_manufacturer'],
            (
'reference' => 1.0,
                'price' => new PriceCollection(),
            ])
        );

        $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();
        
$cart = new Cart($this->ids->get('cart'));
        $source = new Source('https://shopware.com', $this->ids->get('shop-id'), '1.0.0');
        $payload = new TaxProviderPayload($cart$salesChannelContext);
        $payload->setSource($source);

        $definitionInstanceRegistry = static::createMock(DefinitionInstanceRegistry::class);
        $definitionInstanceRegistry
            ->method('getByEntityClass')
            ->willReturn(new TaxProviderDefinition());

        $entityEncoder = new JsonEntityEncoder(
            new Serializer([new StructNormalizer()][new JsonEncoder()])
        );

        $appPayloadServiceHelper = new AppPayloadServiceHelper(
            $definitionInstanceRegistry,
            $entityEncoder,
            static::createMock(ShopIdProvider::class)
        );

        $array = $appPayloadServiceHelper->encode($payload);

        static::assertSame(['source' => $source, 'cart' => $cart, 'context' => []]$array);
    }
$definitionInstanceRegistry = static::createMock(DefinitionInstanceRegistry::class);
        $definitionInstanceRegistry
            ->method('getByEntityClass')
            ->willReturn(new TaxProviderDefinition());

        $shopIdProvider = static::createMock(ShopIdProvider::class);
        $shopIdProvider
            ->method('getShopId')
            ->willReturn($this->ids->get('shop-id'));

        $entityEncoder = new JsonEntityEncoder(
            new Serializer([new StructNormalizer()][new JsonEncoder()])
        );

        $appPayloadServiceHelper = new AppPayloadServiceHelper(
            $definitionInstanceRegistry,
            $entityEncoder,
            $shopIdProvider
        );

        $url = 'https://example.com/provide-tax';
        $context = new Context(new SystemSource());
        $responseContent = \json_encode([
            
$versionContext = $context->createWithVersionId(Uuid::randomHex());

        static::assertNotNull($versionContext->getExtension('foo'));
    }

    public function testExtensionsAreStripped(): void
    {
        $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
        $discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory);

        $normalizers = [new StructNormalizer()new ObjectNormalizer($classMetadataFactory, null, null, null, $discriminator)new ArrayDenormalizer()];
        $serializer = new Serializer($normalizers[new JsonEncoder()]);

        $context = Context::createDefaultContext();

        $context->addExtension('foo', new ArrayEntity());

        $serialized = $serializer->serialize($context, 'json');
        $deserialized = $serializer->deserialize($serialized, Context::class, 'json');

        static::assertInstanceOf(Context::class$deserialized);

        static::assertEmpty($deserialized->getVars()['extensions']);
    }
static::assertInstanceOf(MailTemplateEntity::class$mailTemplate);

        $criteria = new Criteria([TestDefaults::SALES_CHANNEL]);
        $criteria->setLimit(1);
        $salesChannel = $this->getContainer()
            ->get('sales_channel.repository')
            ->search($criteria$context)
            ->first();
        static::assertInstanceOf(SalesChannelEntity::class$salesChannel);

        $entityEncoder = new JsonEntityEncoder(
            new Serializer([new StructNormalizer()][new JsonEncoder()])
        );
        $orderDefinition = $this->getContainer()->get(OrderDefinition::class);
        $orderDecode = $entityEncoder->encode(new Criteria()$orderDefinition$order, '/api');
        array_walk_recursive($orderDecodestatic function D&$value): void {
            if ($value instanceof \stdClass) {
                $value = json_decode((string) json_encode($value), true, 512, \JSON_THROW_ON_ERROR);
            }
        });

        $salesChannelDefinition = $this->getContainer()->get(SalesChannelDefinition::class);
        $salesChannelDecode = $entityEncoder->encode(new Criteria()$salesChannelDefinition$salesChannel, '/api');
        
Home | Imprint | This part of the site doesn't use cookies.