createScope example


        $order = new OrderEntity();
        $tagCollection = new TagCollection();
        $orderTagIds = array_filter(\is_array($givenIdentifier) ? $givenIdentifier : [$givenIdentifier]);
        foreach ($orderTagIds as $orderTagId) {
            $tag = new TagEntity();
            $tag->setId($orderTagId);
            $tagCollection->add($tag);
        }
        $order->setTags($tagCollection);

        $scope = $this->createScope($order);
        $this->rule->assign(['identifiers' => $ruleIdentifiers, 'operator' => $operator]);

        $match = $this->rule->match($scope);
        if ($isMatching) {
            static::assertTrue($match);
        } else {
            static::assertFalse($match);
        }
    }

    public static function getMatchValues(): \Generator
    {
/** * @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 = new CustomerEntity();

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

        static::assertFalse($match);
    }

    /** * @dataProvider getCaseTestMatchValues */
    public function testMatch(OrderCreatedByAdminRule $rule, OrderEntity $order, bool $isMatching): void
    {
        $scope = $this->createScope($order);
        $match = $rule->match($scope);
        static::assertEquals($match$isMatching);
    }

    public static function getCaseTestMatchValues(): \Generator
    {
        yield 'Condition is not created by admin => Not match because order created by admin' => [
            new OrderCreatedByAdminRule(false),
            (new OrderEntity())->assign(['createdById' => Uuid::randomHex()]),
            false,
        ];

        

        $customer = new CustomerEntity();

        /** @var list<string> $customerIdentifiers */
        $customerIdentifiers = array_filter(\is_array($givenIdentifier) ? $givenIdentifier : [$givenIdentifier]);
        $customer->setTagIds($customerIdentifiers);

        if ($noCustomer) {
            $customer = null;
        }

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

        $match = $this->rule->match($scope);
        if ($isMatching) {
            static::assertTrue($match);
        } else {
            static::assertFalse($match);
        }
    }

    /** * @return \Traversable<list<mixed>> */
Home | Imprint | This part of the site doesn't use cookies.