addCodesAndAssertCount example

'individualCodePattern' => $pattern,
        ];
        $promotionRepository = $this->getContainer()->get('promotion.repository');
        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        $this->createPromotionWithCustomData($data$promotionRepository$salesChannelContext);

        // 1000 possible codes -> 500 valid codes         $this->codesService->replaceIndividualCodes($id$pattern, 100, $salesChannelContext->getContext());

        $this->addCodesAndAssertCount($id, 200, 300);
        $this->addCodesAndAssertCount($id, 200, 500);

        $this->expectExceptionMessage('The amount of possible codes is too low for the current pattern. Make sure your pattern is sufficiently complex.');
        $this->addCodesAndAssertCount($id, 1, 501);
    }

    public function testSplitPatternWithInvalidCodeThrowsInvalidCodePattern(): void
    {
        static::expectException(PromotionException::class);

        $this->codesService->splitPattern('PREFIX_%foo_SUFFIX');
    }
Home | Imprint | This part of the site doesn't use cookies.