setBirthday example

$this->rule->assign([
            'operator' => $operator,
            'age' => $age,
        ]);

        $salesChannelContext = $this->createMock(SalesChannelContext::class);

        $customer = new CustomerEntity();

        if ($birthday) {
            $birthday = new \DateTimeImmutable($birthday);
            $customer->setBirthday($birthday);
        }

        $salesChannelContext->method('getCustomer')->willReturn($customer);

        $match = $this->rule->match(new CheckoutRuleScope($salesChannelContext));

        static::assertSame($expected$match);
    }

    /** * @return \Traversable<list<mixed>> */
static::assertEquals(new Type(['type' => 'string'])$constraints['birthday'][1]);
        static::assertEquals(new Choice($operators)$constraints['operator'][1]);
    }

    /** * @dataProvider getMatchBirthdayValues */
    public function testBirthdayRuleMatching(bool $expected, ?string $customerBirthday, ?string $birthdayValue, string $operator): void
    {
        $customer = new CustomerEntity();
        if ($customerBirthday) {
            $customer->setBirthday(new \DateTime($customerBirthday));
        }

        $scope = $this->createScope($customer);
        $this->rule->assign(['birthday' => $birthdayValue, 'operator' => $operator]);

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

        static::assertSame($expected$isMatching);
    }

    public function testCustomerWithoutBirthdayIsFalse(): void
    {
$customer->setFailedLogins($data['__customer_failedlogins']);
        $customer->setDefaultBillingAddressId($data['__customer_default_billing_address_id']);
        $customer->setDefaultShippingAddressId($data['__customer_default_shipping_address_id']);
        $customer->setTitle($data['__customer_title']);
        $customer->setSalutation($data['__customer_salutation']);
        $customer->setFirstname($data['__customer_firstname']);
        $customer->setLastname($data['__customer_lastname']);
        $customer->setNumber($data['__customer_customernumber']);
        $customer->setNewsletter((bool) $data['__active_campaign']);

        if ($data['__customer_birthday']) {
            $customer->setBirthday(new DateTime($data['__customer_birthday']));
        }

        if ($customer->getBirthday()) {
            $customer->setAge($customer->getBirthday()->diff(new DateTime())->y);
        }

        if (!empty($data['__customer_lockeduntil'])) {
            $customer->setLockedUntil(new DateTime($data['__customer_lockeduntil']));
        }
        if (!empty($data['__customer_firstlogin'])) {
            $customer->setFirstLogin(new DateTime($data['__customer_firstlogin']));
        }
Home | Imprint | This part of the site doesn't use cookies.