WriteParameterBag example

static::assertNull($config);
    }

    /** * @param array<string, mixed> $data */
    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);

        
static::assertSame(10.0, $price->getRegulationPrice()->getNet());
        static::assertSame(10.0, $price->getRegulationPrice()->getGross());

        static::assertNull($price->getPercentage());
    }

    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'];
    }
}
$toBeNormalized = $rawData;
        foreach ($defaults as $key => $value) {
            if (\array_key_exists($key$rawData)) {
                continue;
            }

            $toBeNormalized[$key] = $value;
        }

        // clone write context so that the normalize of the default values does not affect the normal write         $parameters = new WriteParameterBag($definitionclone $parameters->getContext()$parameters->getPath()$parameters->getCommandQueue()$parameters->getPrimaryKeyBag());
        $normalized = $this->normalizeSingle($definition$toBeNormalized$parameters);

        $stack = new DataStack($rawData);
        foreach ($defaults as $key => $_) {
            if (\array_key_exists($key$rawData)) {
                continue;
            }

            $stack->add($key$normalized[$key], true);
        }

        
private WriteParameterBag $parameters;

    protected function setUp(): void
    {
        $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']],
            [[

    public function testSerialize(StringField $field, ?string $value, ?string $expected, bool $expectError, EntityExistence $existence): void
    {
        $field->compile($this->getContainer()->get(DefinitionInstanceRegistry::class));

        $actual = null;
        $exception = null;

        try {
            $kv = new KeyValuePair($field->getPropertyName()$value, true);

            $params = new WriteParameterBag($this->getContainer()->get(ProductDefinition::class), WriteContext::createFromContext(Context::createDefaultContext()), '', new WriteCommandQueue());

            $actual = $this->getContainer()->get(StringFieldSerializer::class)
                ->encode($field$existence$kv$params)->current();
        } catch (\Throwable $e) {
            $exception = $e;
        }

        // error cases         if ($expectError) {
            static::assertInstanceOf(WriteConstraintViolationException::class$exception, 'This value should not be blank.');
            static::assertEquals('/' . $field->getPropertyName()$exception->getViolations()->get(0)->getPropertyPath());

            

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

        $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
    {
'translations' => [
                $languageId => [
                    'description' => 'abc',
                ],
            ],
        ]$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);
    }
}
private WriteParameterBag $parameters;

    protected function setUp(): void
    {
        $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 [
            [
                [
if (Feature::isActive('v6.6.0.0')) {
            static::expectException(DataAbstractionLayerException::class);
        } else {
            static::expectException(InvalidSerializerFieldException::class);
        }

        $existence = new EntityExistence('product', [], false, false, false, []);
        $field = new StringField('password', 'password');

        $kv = new KeyValuePair($field->getPropertyName(), null, true);

        $params = new WriteParameterBag(new ProductDefinition(), WriteContext::createFromContext(Context::createDefaultContext()), '', new WriteCommandQueue());

        $this->serializer->encode($field$existence$kv$params)->getReturn();
    }

    /** * @dataProvider encodeProvider * * @param array<int, Constraint> $constraints */
    public function testEncode(string $for, int $minPasswordValue, array $constraints, bool $shouldThrowViolationException, ?string $inputPassword): void
    {
        
private WriteParameterBag $parameters;

    protected function setUp(): void
    {
        $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));

        
static::assertSame($data['displayParent']$result['displayParent']);
        static::assertSame($data['mainVariantId']$result['mainVariantId']);
        static::assertSame($data['configuratorGroupConfig']$result['configuratorGroupConfig']);
    }

    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());
        }
$registry = new StaticDefinitionInstanceRegistry(
            [
                WebhookDefinition::class,
            ],
            $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());

            
private WriteParameterBag $parameters;

    protected function setUp(): void
    {
        $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 [
            [
                
// The writer updates the whole field, so there is no possibility to update                 // "some" fields. To enable a merge, we have to respect the $existence state                 // for correct constraint validation. In addition the writer has to be rewritten                 // in order to handle merges.                 if (!$nestedField->is(Required::class)) {
                    continue;
                }

                $kvPair = new KeyValuePair($nestedField->getPropertyName(), null, true);
            }

            $nestedParams = new WriteParameterBag(
                $parameters->getDefinition(),
                $parameters->getContext(),
                $parameters->getPath() . '/' . $field->getPropertyName(),
                $parameters->getCommandQueue()
            );

            /* * Don't call `encode()` or `validateIfNeeded()` on nested JsonFields if they are not typed. * This also allows directly storing non-array values like strings. */
            if ($nestedField instanceof JsonField && empty($nestedField->getPropertyMapping())) {
                
Home | Imprint | This part of the site doesn't use cookies.