ShippingZipCodeRule example

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

        $cart = new Cart('test');

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

        $location = ShippingLocation::createFromAddress($address);

        $context
            ->method('getShippingLocation')
            ->willReturn($location);

        
private EntityRepository $conditionRepository;

    private Context $context;

    private ShippingZipCodeRule $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 ShippingZipCodeRule();
    }

    public function testValidateWithMissingZipCodes(): void
    {
        // reset from previous tests         $this->getContainer()->get(ShippingZipCodeRule::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.