NotBlank example


        $expectedOperators = [
            Rule::OPERATOR_EQ,
            Rule::OPERATOR_NEQ,
            Rule::OPERATOR_EMPTY,
        ];

        $ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('operator', $ruleConstraints, 'Constraint operator not found in Rule');
        $operators = $ruleConstraints['operator'];
        static::assertEquals(new NotBlank()$operators[0]);
        static::assertEquals(new Choice($expectedOperators)$operators[1]);

        $this->rule->assign(['operator' => Rule::OPERATOR_EQ]);
        static::assertArrayHasKey('streetName', $ruleConstraints, 'Constraint streetName not found in Rule');
        $streetName = $ruleConstraints['streetName'];
        static::assertEquals(new NotBlank()$streetName[0]);
        static::assertEquals(new Type('string')$streetName[1]);
    }

    /** * @dataProvider getMatchValues */
#[Route(path: '/store-api/account/change-profile', name: 'store-api.account.change-profile', methods: ['POST'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true])]     public function change(RequestDataBag $data, SalesChannelContext $context, CustomerEntity $customer): SuccessResponse
    {
        $validation = $this->customerProfileValidationFactory->update($context);

        if ($data->has('accountType') && empty($data->get('accountType'))) {
            $data->remove('accountType');
        }

        if ($data->get('accountType') === CustomerEntity::ACCOUNT_TYPE_BUSINESS) {
            $validation->add('company', new NotBlank());
            $billingAddress = $customer->getDefaultBillingAddress();
            if ($billingAddress) {
                $this->addVatIdsValidation($validation$billingAddress);
            }
        } else {
            $data->set('company', '');
            $data->set('vatIds', null);
        }

        /** @var ?RequestDataBag $vatIds */
        $vatIds = $data->get('vatIds');
        

class AffiliateCodeRuleTest extends TestCase
{
    public function testGetConstraints(): void
    {
        $constraints = (new AffiliateCodeRule())->getConstraints();

        static::assertArrayHasKey('affiliateCode', $constraints, 'Constraint affiliateCode not found in Rule');
        static::assertEquals($constraints['affiliateCode'][
            new NotBlank(),
            new Type(['type' => 'string']),
        ]);
    }

    public function testName(): void
    {
        $rule = new AffiliateCodeRule();
        static::assertSame('customerAffiliateCode', $rule->getName());
    }

    public function testGetConfig(): void
    {
Rule::OPERATOR_EMPTY,
            Rule::OPERATOR_GTE,
            Rule::OPERATOR_LTE,
            Rule::OPERATOR_GT,
            Rule::OPERATOR_LT,
        ];

        $ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('operator', $ruleConstraints, 'Constraint operator not found in Rule');
        $operators = $ruleConstraints['operator'];
        static::assertEquals(new NotBlank()$operators[0]);
        static::assertEquals(new Choice($expectedOperators)$operators[1]);

        $this->rule->assign(['operator' => Rule::OPERATOR_EQ]);
        static::assertArrayHasKey('zipCodes', $ruleConstraints, 'Constraint zipCodes not found in Rule');
        $zipCodes = $ruleConstraints['zipCodes'];
        static::assertEquals(new NotBlank()$zipCodes[0]);
        static::assertEquals(new ArrayOfType('string')$zipCodes[1]);
    }

    /** * @dataProvider getMatchValuesNumeric */
$expectsClosure($definition$contextMock);
    }

    public static function systemConfigDataProvider(): \Generator
    {
        yield 'is required' => [
            true,
            function DDataValidationDefinition $definition, SalesChannelContext $context): void {
                static::assertEquals($definition->getProperties()[
                    'salutationId' => [
                        new NotBlank(),
                        new EntityExists(['entity' => 'salutation', 'context' => $context->getContext()]),
                    ],
                    'email' => [new NotBlank()new Email()],
                    'subject' => [new NotBlank()],
                    'comment' => [new NotBlank()],
                    'firstName' => [
                        new NotBlank(),
                        new Regex(['pattern' => ContactFormValidationFactory::DOMAIN_NAME_REGEX, 'match' => false]),
                    ],
                    'lastName' => [
                        new NotBlank(),
                        

    }

    /** * @return iterable<string, array<int|string|array<int, Constraint>|bool|null>> */
    public static function encodeProvider(): iterable
    {
        $minPasswordLength = 8;

        $notBlankConstraints = [
            new NotBlank(),
            new Type('string'),
        ];

        $minLengthConstraints = [
            new NotBlank(),
            new Type('string'),
            new Length(['min' => $minPasswordLength]),
        ];

        yield 'with null value without min length required' => [
            PasswordField::FOR_ADMIN,
            

    private function buildConstraintsWithConfigs(array $elementConfig): array
    {
        /** @var array<string, callable(mixed): Constraint> $constraints */
        $constraints = [
            'minLength' => fn (mixed $ruleValue) => new Assert\Length(['min' => $ruleValue]),
            'maxLength' => fn (mixed $ruleValue) => new Assert\Length(['max' => $ruleValue]),
            'min' => fn (mixed $ruleValue) => new Assert\Range(['min' => $ruleValue]),
            'max' => fn (mixed $ruleValue) => new Assert\Range(['max' => $ruleValue]),
            'dataType' => fn (mixed $ruleValue) => new Assert\Type($ruleValue),
            'required' => fn (mixed $ruleValue) => new Assert\NotBlank(),
        ];

        $constraintsResult = [];

        foreach ($constraints as $ruleName => $constraint) {
            if (!\array_key_exists($ruleName$elementConfig)) {
                continue;
            }

            $ruleValue = $elementConfig[$ruleName];

            
$event,
            ReviewFormEvent::EVENT_NAME
        );

        return new NoContentResponse();
    }

    private function validate(DataBag $data, Context $context): void
    {
        $definition = new DataValidationDefinition('product.create_rating');

        $definition->add('name', new NotBlank());
        $definition->add('title', new NotBlank()new Length(['min' => 5]));
        $definition->add('content', new NotBlank()new Length(['min' => 40]));

        $definition->add('points', new GreaterThanOrEqual(1)new LessThanOrEqual(5));

        if ($data->get('id')) {
            $criteria = new Criteria();
            $criteria->addFilter(new EqualsFilter('customerId', $data->get('customerId')));
            $criteria->addFilter(new EqualsFilter('id', $data->get('id')));

            $definition->add('id', new EntityExists([
                

        $builder->addEventListener(FormEvents::PRE_SUBMIT, function DFormEvent $event) {
            $data = $event->getData();
            array_walk_recursive($datafunction D&$item) {
                $item = strip_tags((string) $item);
            });
            $event->setData($data);
        });

        if ($this->config->get('shopSalutationRequired')) {
            $builder->add('salutation', SalutationType::class[
                'constraints' => [new NotBlank(['message' => null])],
            ]);
        }

        $builder->add('firstname', TextType::class[
            'constraints' => [new NotBlank(['message' => null])],
        ]);

        $builder->add('lastname', TextType::class[
            'constraints' => [new NotBlank(['message' => null])],
        ]);

        
Rule::OPERATOR_GTE,
            Rule::OPERATOR_NEQ,
            Rule::OPERATOR_GT,
            Rule::OPERATOR_LT,
            Rule::OPERATOR_EMPTY,
        ];

        $ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('operator', $ruleConstraints, 'Constraint operator not found in Rule');
        $operators = $ruleConstraints['operator'];
        static::assertEquals(new NotBlank()$operators[0]);
        static::assertEquals(new Choice($expectedOperators)$operators[1]);

        $this->rule->assign(['operator' => Rule::OPERATOR_EQ]);
        static::assertArrayHasKey('daysPassed', $ruleConstraints, 'Constraint daysPassed not found in Rule');
        $daysPassed = $ruleConstraints['daysPassed'];
        static::assertEquals(new NotBlank()$daysPassed[0]);
        static::assertEquals(new Type('numeric')$daysPassed[1]);
    }

    /** * @dataProvider getMatchValues */
return self::TYPE;
    }

    public function getPriority(): int
    {
        return self::SORTING_PRIORITY;
    }

    public static function getConstraints(): array
    {
        return [
            'price' => [new NotBlank()new Type('numeric')],
            'quantity' => [new Type('int')],
            'isCalculated' => [new Type('bool')],
        ];
    }

    public function getReferencePriceDefinition(): ?ReferencePriceDefinition
    {
        return $this->referencePriceDefinition;
    }

    public function getListPrice(): ?float
    {

        $builder->addEventListener(FormEvents::PRE_SUBMIT, function DFormEvent $event) {
            $data = $event->getData();
            array_walk_recursive($datafunction D&$item) {
                $item = strip_tags($item);
            });
            $event->setData($data);
        });

        if ($this->config->get('shopSalutationRequired')) {
            $builder->add('salutation', SalutationType::class[
                'constraints' => [new NotBlank(['message' => null])],
            ]);
        }

        $builder->add('title', TextType::class);

        $builder->add('firstname', TextType::class[
            'constraints' => [new NotBlank(['message' => null])],
        ]);

        $builder->add('lastname', TextType::class[
            'constraints' => [new NotBlank(['message' => null])],
        ]);
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Type;

#[Package('business-ops')] class RuleConstraints
{
    /** * @return array<int, Constraint> */
    public static function float(): array
    {
        return [new NotBlank()new Type('numeric')];
    }

    /** * @return array<int, Constraint> */
    public static function int(): array
    {
        return [new NotBlank()new Type('int')];
    }

    /** * @return array<int, Constraint> */

    public function validate(User $user)
    {
        $this->validationContext = $this->validator->startContext();

        $this->validateField('username', $user->getUsername()[
            new UserName([
                'userId' => $user->getId(),
            ]),
            new NoUrl(),
        ]);
        $this->validateField('name', $user->getName()[new NotBlank()new NoUrl()]);
        $this->validateField('role', $user->getRole()[new NotBlank()]);
        $this->validateField('email', $user->getEmail()[
            new UserEmail([
                'userId' => $user->getId(),
            ]),
        ]);

        if ($this->validationContext->getViolations()->count()) {
            throw new ValidationException($this->validationContext->getViolations());
        }
    }

    

        $expectedOperators = [
            Rule::OPERATOR_EQ,
            Rule::OPERATOR_NEQ,
            Rule::OPERATOR_EMPTY,
        ];

        $ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('operator', $ruleConstraints, 'Constraint operator not found in Rule');
        $operators = $ruleConstraints['operator'];
        static::assertEquals(new NotBlank()$operators[0]);
        static::assertEquals(new Choice($expectedOperators)$operators[1]);

        $this->rule->assign(['operator' => Rule::OPERATOR_EQ]);
        static::assertArrayHasKey('streamIds', $ruleConstraints, 'Constraint streamIds not found in Rule');
        $streamIds = $ruleConstraints['streamIds'];
        static::assertEquals(new NotBlank()$streamIds[0]);
        static::assertEquals(new ArrayOfUuid()$streamIds[1]);
    }

    /** * @param array<string> $streamIds */
Home | Imprint | This part of the site doesn't use cookies.