PaymentMethodRule example


class PaymentMethodRuleTest extends TestCase
{
    public function testNameReturnsKnownName(): void
    {
        $rule = new PaymentMethodRule();

        static::assertSame('paymentMethod', $rule->getName());
    }

    public function testGetApiAlias(): void
    {
        $rule = new PaymentMethodRule();

        static::assertSame('rule_paymentMethod', $rule->getApiAlias());
    }

    

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

    public function testValidateWithMissingPaymentMethodIds(): void
    {
        try {
            $this->conditionRepository->create([
                [
                    'type' => (new PaymentMethodRule())->getName(),
                    'ruleId' => Uuid::randomHex(),
                ],
            ]$this->context);
            static::fail('Exception was not thrown');
        } catch (WriteException $stackException) {
            $exceptions = iterator_to_array($stackException->getErrors());
            static::assertCount(2, $exceptions);
            static::assertSame('/0/value/paymentMethodIds', $exceptions[0]['source']['pointer']);
            static::assertSame(NotBlank::IS_BLANK_ERROR, $exceptions[0]['code']);

            static::assertSame('/0/value/operator', $exceptions[1]['source']['pointer']);
            
Home | Imprint | This part of the site doesn't use cookies.