splitPattern example

$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');
    }

    private function addCodesAndAssertCount(string $id, int $newCodeAmount, int $expectedCodeAmount): void
    {
        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
        $promotionRepository = $this->getContainer()->get('promotion.repository');
        $criteria = (new Criteria())
            ->addAssociation('individualCodes');

        $this->codesService->addIndividualCodes($id$newCodeAmount$salesChannelContext->getContext());

        

    public function generateIndividualCodes(string $pattern, int $amount, array $codeBlacklist = []): array
    {
        if ($amount < 1) {
            return [];
        }

        $codePattern = $this->splitPattern($pattern);
        $blacklistCount = \count($codeBlacklist);

        /* * This condition ensures a fundamental randomness to the generated codes in ratio to all possibilities, which * also minimizes the number of retries. Therefore, the CODE_COMPLEXITY_FACTOR is the worst-case-scenario * probability to find a new unique promotion code. */

        $complexity = $this->isComplexEnough($codePattern['replacementString']$amount$blacklistCount);

        if (!$complexity) {
            
Home | Imprint | This part of the site doesn't use cookies.