BillingZipCodeRule example

/** * @covers \Shopware\Core\Checkout\Customer\Rule\BillingZipCodeRule * * @internal */
#[Package('business-ops')] class BillingZipCodeRuleTest extends TestCase
{
    public function testEqualsWithSingleCode(): void
    {
        $rule = (new BillingZipCodeRule())->assign(['zipCodes' => ['ABC123']]);

        $cart = new Cart('test');

        $context = $this->createMock(SalesChannelContext::class);

        $billing = new CustomerAddressEntity();
        $billing->setZipcode('ABC123');

        $customer = new CustomerEntity();
        $customer->setDefaultBillingAddress($billing);

        
private EntityRepository $conditionRepository;

    private Context $context;

    private BillingZipCodeRule $rule;

    protected function setUp(): void
    {
        $this->ruleRepository = $this->getContainer()->get('rule.repository');
        $this->conditionRepository = $this->getContainer()->get('rule_condition.repository');
        $this->context = Context::createDefaultContext();
        $this->rule = new BillingZipCodeRule();
    }

    public function testValidateWithMissingZipCodes(): void
    {
        // reset from previous tests         $this->getContainer()->get(BillingZipCodeRule::class)->assign(['operator' => Rule::OPERATOR_EQ, 'zipCodes' => null]);

        $conditionId = Uuid::randomHex();

        try {
            $this->conditionRepository->create([
                [
Home | Imprint | This part of the site doesn't use cookies.