function it_matches_all_zones_by_scope_when_one_zone_for_address_is_defined(RepositoryInterface $repository, AddressInterface $address, ZoneMemberInterface $memberCountry, ZoneInterface $zoneCountry) { $repository->findBy(['scope' => 'shipping'])->willReturn([$zoneCountry]); $address->getCountryCode()->willReturn('US'); $memberCountry->getCode()->willReturn('US'); $zoneCountry->getType()->willReturn(ZoneInterface::TYPE_COUNTRY); $zoneCountry->getMembers()->willReturn([$memberCountry]); $memberCountry->getBelongsTo()->willReturn($zoneCountry); $this->matchAll($address, 'shipping')->shouldReturn([$zoneCountry]); }
/** * @param AddressInterface $address * @param ZoneMemberInterface $member * * @return bool * * @throws \InvalidArgumentException */ protected function addressBelongsToZoneMember(AddressInterface $address, ZoneMemberInterface $member) { switch ($type = $member->getBelongsTo()->getType()) { case ZoneInterface::TYPE_PROVINCE: return null !== $address->getProvinceCode() && $address->getProvinceCode() === $member->getCode(); case ZoneInterface::TYPE_COUNTRY: return null !== $address->getCountryCode() && $address->getCountryCode() === $member->getCode(); case ZoneInterface::TYPE_ZONE: $zone = $this->getZoneByCode($member->getCode()); return $this->addressBelongsToZone($address, $zone); default: throw new \InvalidArgumentException(sprintf('Unexpected zone type "%s".', $type)); } }