MatchAllLineItemsRule example


        $this->ruleRepository = $this->getContainer()->get('rule.repository');
        $this->conditionRepository = $this->getContainer()->get('rule_condition.repository');
        $this->context = Context::createDefaultContext();
    }

    public function testValidateWithInvalidRulesType(): void
    {
        try {
            $this->conditionRepository->create([
                [
                    'type' => (new MatchAllLineItemsRule())->getName(),
                    'ruleId' => Uuid::randomHex(),
                    'value' => [
                        'rules' => ['Rule'],
                    ],
                ],
            ]$this->context);
            static::fail('Exception was not thrown');
        } catch (WriteException $stackException) {
            $exceptions = iterator_to_array($stackException->getErrors());
            static::assertCount(1, $exceptions);
            static::assertSame('/0/value/rules', $exceptions[0]['source']['pointer']);
            

    public function testIfMatchesWithMatchAllLineItemsRule(
        array $lineItems,
        string $operator,
        bool $expected
    ): void {
        $this->rule->assign([
            'operator' => $operator,
            'amount' => 100,
        ]);
        $allLineItemsRule = new MatchAllLineItemsRule([], null, 'product');
        $allLineItemsRule->addRule($this->rule);

        $lineItemCollection = new LineItemCollection($lineItems);

        $cart = $this->createCart($lineItemCollection);

        $match = $allLineItemsRule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        
Home | Imprint | This part of the site doesn't use cookies.