NotNull example

static::assertSame($expectedValue$isActiveCustomerRule->match($scope));
    }

    public function testConstrains(): void
    {
        $actualConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('isActive', $actualConstraints, 'Constrains not found in rule, given "isActive"');

        $isActiveConstraint = $actualConstraints['isActive'];

        static::assertEquals(new NotNull()$isActiveConstraint[0]);
        static::assertEquals(new Type('bool')$isActiveConstraint[1]);
    }

    public function testReturnsFalseWhenProvidingIncorrectScope(): void
    {
        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $lineItem = new LineItem('random-id', 'line-item');

        $isActiveCustomerRule = new IsActiveRule(true);

        $scope = new LineItemScope($lineItem$salesChannelContext);

        
$decoded[$key] = $decodedValue;
        }

        return $decoded;
    }

    protected function getConstraints(Field $field): array
    {
        return [
            new Type('array'),
            new NotNull(),
        ];
    }

    protected function validateMapping(
        JsonField $field,
        array $data,
        WriteParameterBag $parameters
    ): array {
        if (\array_key_exists('_class', $data)) {
            unset($data['_class']);
        }

        
$this->rule->assign(['isSet' => true]);
        static::assertFalse($this->rule->match($ruleScope));
    }

    public function testConstraint(): void
    {
        $constraints = (new OrderTrackingCodeRule())->getConstraints();

        static::assertArrayHasKey('isSet', $constraints);
        static::assertEquals([
            'isSet' => [new NotNull()new Type(['type' => 'bool'])],
        ]$constraints);
    }

    public function testGetConfig(): void
    {
        $rule = new OrderTrackingCodeRule(true);
        $config = $rule->getConfig();

        static::assertEquals([
            'operatorSet' => null,
            'fields' => [
                [
'operatorSet' => null,
        ]$config->getData());
    }

    public function testGetConstraints(): void
    {
        $rule = new OrderCreatedByAdminRule();
        $constraints = $rule->getConstraints();

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

    public function testMatchWithWrongRuleScope(): void
    {
        $scope = $this->createMock(TestRuleScope::class);

        $match = $this->rule->match($scope);

        static::assertFalse($match);
    }
return false;
        }

        return true;
    }

    public function getConstraints(): array
    {
        return [
            'fromDate' => [new NotBlank()new DateTimeConstraint(['format' => \DateTime::ATOM])],
            'toDate' => [new NotBlank()new DateTimeConstraint(['format' => \DateTime::ATOM])],
            'useTime' => [new NotNull()new Type('bool')],
        ];
    }
}

        $constraints = [
            new Type('string'),
            new Length(['max' => $field->getMaxLength()]),
        ];

        if (!$field->is(AllowEmptyString::class)) {
            $constraints[] = new NotBlank();
        }

        if ($field->is(AllowEmptyString::class) && $field->is(Required::class)) {
            $constraints[] = new NotNull();
        }

        return $constraints;
    }
}


    public function decode(Field $field, mixed $value): ?\DateTimeInterface
    {
        return $value === null ? null : new \DateTimeImmutable($value);
    }

    protected function getConstraints(Field $field): array
    {
        return [
            new Type(\DateTimeInterface::class),
            new NotNull(),
        ];
    }
}
 catch (\Throwable $e) {
            throw DataAbstractionLayerException::invalidDateIntervalFormat($value$e);
        }

        return $dateInterval;
    }

    protected function getConstraints(Field $field): array
    {
        return [
            new Type(\DateInterval::class),
            new NotNull(),
        ];
    }
}
if ($this->isDifferent) {
            return $billingAddress->getId() !== $shippingAddress->getId();
        }

        return $billingAddress->getId() === $shippingAddress->getId();
    }

    public function getConstraints(): array
    {
        return [
            'isDifferent' => [new NotNull()new Type('bool')],
        ];
    }

    public function getConfig(): RuleConfig
    {
        return (new RuleConfig())
            ->booleanField('isDifferent');
    }
}


    public function decode(Field $field, mixed $value): ?\DateTimeInterface
    {
        return $value === null ? null : new \DateTimeImmutable($value);
    }

    protected function getConstraints(Field $field): array
    {
        return [
            new Type(\DateTimeInterface::class),
            new NotNull(),
        ];
    }
}
protected function getConstraints(Field $field): array
    {
        $constraints = [
            new Type('string'),
        ];

        if (!$field->is(AllowEmptyString::class)) {
            $constraints[] = new NotBlank();
        }

        if ($field->is(AllowEmptyString::class) && $field->is(Required::class)) {
            $constraints[] = new NotNull();
        }

        return $constraints;
    }
}
return [new NotBlank()new ArrayOfType('string')];
    }

    /** * @return array<int, Constraint> */
    public static function bool(bool $notNull = false): array
    {
        $constraint = [];

        if ($notNull) {
            $constraint[] = new NotNull();
        }

        $constraint[] = new Type('bool');

        return $constraint;
    }

    /** * @return array<int, Constraint> */
    public static function uuids(): array
    {

class CustomerCreatedByAdminRuleTest extends TestCase
{
    public function testGetConstraints(): void
    {
        $rule = new CustomerCreatedByAdminRule();
        $constraints = $rule->getConstraints();

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

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

    public function testGetConfig(): void
    {

    public function isNotBlank(): self
    {
        $this->addConstraint(new NotBlank());

        return $this;
    }

    public function isNotNull(): self
    {
        $this->addConstraint(new NotNull());

        return $this;
    }

    public function isBool(): self
    {
        $this->addConstraint(new Type('bool'));

        return $this;
    }

    

class CustomerLoggedInRuleTest extends TestCase
{
    public function testGetConstraints(): void
    {
        $rule = new CustomerLoggedInRule();
        $constraints = $rule->getConstraints();

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

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

    public function testGetConfig(): void
    {
Home | Imprint | This part of the site doesn't use cookies.