WriteCommandQueue example


        $this->serializer = $this->getContainer()->get(JsonFieldSerializer::class);
        $this->field = new JsonField('data', 'data');

        $definition = $this->registerDefinition(JsonDefinition::class);
        $this->existence = new EntityExistence($definition->getEntityName()[], false, false, false, []);

        $this->parameters = new WriteParameterBag(
            $definition,
            WriteContext::createFromContext(Context::createDefaultContext()),
            '',
            new WriteCommandQueue()
        );
    }

    public static function encodeProvider(): array
    {
        return [
            [new JsonField('data', 'data')['foo' => 'bar'], Json::encode(['foo' => 'bar'])],
            [new JsonField('data', 'data')['foo' => 1], Json::encode(['foo' => 1])],
            [new JsonField('data', 'data')['foo' => 5.3], Json::encode(['foo' => 5.3])],
            [new JsonField('data', 'data')['foo' => ['bar' => 'baz']], Json::encode(['foo' => ['bar' => 'baz']])],

            [

        ]$data);
    }

    private function normalize(array $data): array
    {
        $field = new TranslatedField('description');
        $bag = new WriteParameterBag(
            $this->getContainer()->get(ProductDefinition::class),
            $this->writeContext,
            '',
            new WriteCommandQueue()
        );

        return $this->serializer->normalize($field$data$bag);
    }
}
$this->serializer = $this->getContainer()->get(ConfigJsonFieldSerializer::class);
        $this->field = new ConfigJsonField('data', 'data');
        $this->field->addFlags(new ApiAware()new Required());

        $definition = $this->registerDefinition(JsonDefinition::class);
        $this->existence = new EntityExistence($definition->getEntityName()[], false, false, false, []);

        $this->parameters = new WriteParameterBag(
            $definition,
            WriteContext::createFromContext(Context::createDefaultContext()),
            '',
            new WriteCommandQueue()
        );
    }

    public static function serializerProvider(): array
    {
        return [
            [['string']],
            [[11234]],
            [[11234.123243]],
            [[
                [
                    


    private function encode(array $data): string
    {
        $field = new PriceField('test', 'test');
        $existence = new EntityExistence('test', ['someId' => true], true, false, false, []);
        $keyPair = new KeyValuePair('someId', $data, false);
        $bag = new WriteParameterBag(
            $this->getContainer()->get(ProductDefinition::class),
            WriteContext::createFromContext(Context::createDefaultContext()),
            '',
            new WriteCommandQueue()
        );

        $data = iterator_to_array($this->serializer->encode($field$existence$keyPair$bag), true);

        return $data['test'];
    }
}
$this->serializer = $this->getContainer()->get(DateTimeFieldSerializer::class);
        $this->field = new DateTimeField('date', 'date');
        $this->field->addFlags(new ApiAware()new Required());

        $definition = $this->registerDefinition(DateTimeDefinition::class);
        $this->existence = new EntityExistence($definition->getEntityName()[], false, false, false, []);

        $this->parameters = new WriteParameterBag(
            $definition,
            WriteContext::createFromContext(Context::createDefaultContext()),
            '',
            new WriteCommandQueue()
        );
    }

    public static function serializerProvider(): array
    {
        return [
            [
                new \DateTime('2020-05-15 00:00:00', new \DateTimeZone('UTC')),
                new \DateTime('2020-05-15 00:00:00', new \DateTimeZone('UTC')),
            ],
            [
                
/** * @dataProvider serializerProvider */
    public function testSerializer(PriceDefinitionInterface $definition): void
    {
        $serializer = $this->getContainer()->get(PriceDefinitionFieldSerializer::class);

        $encoded = $serializer->encode(
            new PriceDefinitionField('test', 'test'),
            new EntityExistence('', [], false, false, false, []),
            new KeyValuePair('test', $definition, true),
            new WriteParameterBag($this->getContainer()->get(CurrencyDefinition::class), WriteContext::createFromContext(Context::createDefaultContext()), '', new WriteCommandQueue())
        );

        $encoded = iterator_to_array($encoded);

        static::assertArrayHasKey('test', $encoded);
        static::assertIsString($encoded['test']);

        $decoded = $serializer->decode(
            new PriceDefinitionField('test', 'test'),
            $encoded['test']
        );

        
 {
    }

    // TODO: prefetch     /** * @param SyncOperation[] $operations * * @throw InvalidSyncOperationException */
    public function sync(array $operations, WriteContext $context): WriteResult
    {
        $commandQueue = new WriteCommandQueue();

        $context->setLanguages(
            $this->languageLoader->loadLanguages()
        );

        $writes = [];
        $notFound = [];
        $deletes = [];

        foreach ($operations as $operation) {
            if (!$operation instanceof SyncOperation) {
                
$this->serializer = $this->getContainer()->get(DateFieldSerializer::class);
        $this->field = new DateField('date', 'date');
        $this->field->addFlags(new ApiAware()new Required());

        $definition = $this->registerDefinition(DateDefinition::class);
        $this->existence = new EntityExistence($definition->getEntityName()[], false, false, false, []);

        $this->parameters = new WriteParameterBag(
            $definition,
            WriteContext::createFromContext(Context::createDefaultContext()),
            '',
            new WriteCommandQueue()
        );
    }

    public static function serializerProvider(): array
    {
        return [
            [
                [
                    new \DateTime('2020-05-15 00:00:00', new \DateTimeZone('UTC')),
                    new \DateTime('2020-05-15 00:00:00', new \DateTimeZone('UTC')),
                ],
            ],

            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        $context = Context::createDefaultContext($scope);

        $parameters = new WriteParameterBag(
            $registry->get(WebhookDefinition::class),
            WriteContext::createFromContext($context),
            '',
            new WriteCommandQueue(),
            new PrimaryKeyBag()
        );

        $extractor->extract($data$parameters);

        if ($valid) {
            static::assertCount(0, $parameters->getContext()->getExceptions()->getExceptions());

            return;
        }

        
$passwordFieldHandler = new PasswordFieldSerializer(
            $this->getContainer()->get(ValidatorInterface::class),
            $this->getContainer()->get(DefinitionInstanceRegistry::class),
            $this->getContainer()->get(SystemConfigService::class)
        );

        $payload = $passwordFieldHandler->encode($field$existence$kvPairnew WriteParameterBag(
            $this->getContainer()->get(UserDefinition::class),
            WriteContext::createFromContext(Context::createDefaultContext()),
            '',
            new WriteCommandQueue()
        ));

        $payload = iterator_to_array($payload);
        static::assertEquals($kvPair->getValue()$payload['password']);
    }

    public function testEncoding(): void
    {
        $field = new PasswordField('password', 'password');
        $existence = new EntityExistence($this->getContainer()->get(UserDefinition::class)->getEntityName()[], false, false, false, []);
        $kvPair = new KeyValuePair('password', 'shopware', true);

        


    public function testEncodeThrowExceptionOnWrongField(): void
    {
        $field = new JsonField('variant_listing_config', 'variantListingConfig');
        $existence = new EntityExistence('test', ['someId' => 'foo'], true, false, false, []);
        $keyPair = new KeyValuePair('someId', null, false);
        $bag = new WriteParameterBag(
            new ProductDefinition(),
            WriteContext::createFromContext(Context::createDefaultContext()),
            '',
            new WriteCommandQueue()
        );

        try {
            iterator_to_array($this->serializer->encode($field$existence$keyPair$bag));
            static::fail('encode with incorrect field');
        } catch (DataAbstractionLayerException $e) {
            static::assertSame(DataAbstractionLayerException::INVALID_FIELD_SERIALIZER_CODE, $e->getErrorCode());
        }
    }

    /** * @throws \JsonException */

    private function encode(?array $data = null, ?Field $field = null): ?string
    {
        $field ??= new FlowTemplateConfigField('config', 'config');
        $existence = new EntityExistence('config', ['someId' => true], true, false, false, []);
        $keyPair = new KeyValuePair('someId', $data, false);
        $bag = new WriteParameterBag(
            $this->createMock(FlowTemplateDefinition::class),
            WriteContext::createFromContext(Context::createDefaultContext()),
            '',
            new WriteCommandQueue()
        );

        $data = iterator_to_array($this->serializer->encode($field$existence$keyPair$bag));

        return $data['config'] ?? null;
    }
}
$rule->assign(['operator' => Rule::OPERATOR_EQ]);

        $this->ruleConditionRegistry->method('getRuleInstance')->willReturn(new LineItemListPriceRule());

        $definition = new PercentagePriceDefinition(10, $rule);
        $writeContext = WriteContext::createFromContext(Context::createDefaultContext());

        iterator_to_array($this->fieldSerializer->encode(
            new PriceDefinitionField('test', 'test'),
            new EntityExistence('', [], false, false, false, []),
            new KeyValuePair('test', $definition, true),
            new WriteParameterBag($this->createMock(CurrencyDefinition::class)$writeContext, '', new WriteCommandQueue())
        ));
    }

    public function testEncodeDecodeWithEmptyOperatorCondition(): void
    {
        $rule = new LineItemListPriceRule();
        $rule->assign(['operator' => Rule::OPERATOR_EMPTY]);

        $this->ruleConditionRegistry->method('getRuleInstance')->willReturn(new LineItemListPriceRule());
        $this->ruleConditionRegistry->method('has')->willReturn(true);
        $this->ruleConditionRegistry->method('getRuleClass')->willReturn(LineItemListPriceRule::class);

        

    final public static function encodePrimaryKey(EntityDefinition $definition, array $primaryKey, Context $context): array
    {
        $fields = $definition->getPrimaryKeys();

        $mapped = [];

        $existence = new EntityExistence($definition->getEntityName()[], true, false, false, []);

        $params = new WriteParameterBag($definition, WriteContext::createFromContext($context), '', new WriteCommandQueue());

        foreach ($fields as $field) {
            if ($field instanceof VersionField || $field instanceof ReferenceVersionField) {
                $value = $context->getVersionId();
            } else {
                $value = $primaryKey[$field->getPropertyName()];
            }

            $kvPair = new KeyValuePair($field->getPropertyName()$value, true);

            $encoded = $field->getSerializer()->encode($field$existence$kvPair$params);

            

        $this->serializer = $this->getContainer()->get(EmailFieldSerializer::class);
        $this->field = (new EmailField('email', 'email'))->addFlags(new ApiAware()new Required());

        $definition = $this->registerDefinition(EmailDefinition::class);
        $this->existence = new EntityExistence($definition->getEntityName()[], false, false, false, []);

        $this->parameters = new WriteParameterBag(
            $definition,
            WriteContext::createFromContext(Context::createDefaultContext()),
            '',
            new WriteCommandQueue()
        );
    }

    public function testRequiredValidationThrowsError(): void
    {
        $this->field->compile($this->getContainer()->get(DefinitionInstanceRegistry::class));

        $kvPair = new KeyValuePair('email', null, true);

        /** @var WriteConstraintViolationException|null $exception */
        $exception = null;

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