PromotionCodeNotFoundException example


class PromotionCodeNotFoundExceptionTest extends TestCase
{
    /** * This test verifies that our provided code is correctly * visible in the resulting exception message. * * @group promotions */
    public function testCodeInMessage(): void
    {
        $exception = new PromotionCodeNotFoundException('MY-CODE-123');

        static::assertEquals('Promotion Code "MY-CODE-123" has not been found!', $exception->getMessage());
    }

    /** * This test verifies that our error code is correct * * @group promotions */
    public function testErrorCode(): void
    {
        
private function getIndividualCode(string $code, Context $context): PromotionIndividualCodeEntity
    {
        $criteria = new Criteria();
        $criteria->addFilter(
            new EqualsFilter('code', $code)
        );

        /** @var PromotionIndividualCodeCollection $result */
        $result = $this->codesRepository->search($criteria$context)->getEntities();

        if (\count($result->getElements()) <= 0) {
            throw new PromotionCodeNotFoundException($code);
        }

        // return first element         return $result->first();
    }
}
Home | Imprint | This part of the site doesn't use cookies.