/**
  * {@inheritdoc}
  */
 public function getAbbreviation(AddressInterface $address)
 {
     if (null !== $address->getProvinceName()) {
         return $address->getProvinceName();
     }
     if (null === $address->getProvinceCode()) {
         return '';
     }
     $province = $this->provinceRepository->findOneBy(['code' => $address->getProvinceCode()]);
     Assert::notNull($province, sprintf('Province with code "%s" not found.', $address->getProvinceCode()));
     return $province->getAbbreviation() ?: $province->getName();
 }
 function it_ignores_leading_and_trailing_spaces_or_letter_cases(AddressInterface $firstAddress, AddressInterface $secondAddress)
 {
     $firstAddress->getCity()->willReturn('TOOWOOMBA');
     $firstAddress->getStreet()->willReturn('Ryans Dr     ');
     $firstAddress->getCompany()->willReturn('   Burger');
     $firstAddress->getPostcode()->willReturn(' 4350 ');
     $firstAddress->getLastName()->willReturn('jones ');
     $firstAddress->getFirstName()->willReturn('mIa');
     $firstAddress->getPhoneNumber()->willReturn(' 999');
     $firstAddress->getCountryCode()->willReturn('au');
     $firstAddress->getProvinceCode()->willReturn(null);
     $firstAddress->getProvinceName()->willReturn('qUEENSLAND');
     $secondAddress->getCity()->willReturn('Toowoomba');
     $secondAddress->getStreet()->willReturn('Ryans Dr');
     $secondAddress->getCompany()->willReturn('Burger');
     $secondAddress->getPostcode()->willReturn('4350');
     $secondAddress->getLastName()->willReturn('Jones');
     $secondAddress->getFirstName()->willReturn('Mia');
     $secondAddress->getPhoneNumber()->willReturn('999');
     $secondAddress->getCountryCode()->willReturn('AU');
     $secondAddress->getProvinceCode()->willReturn(null);
     $secondAddress->getProvinceName()->willReturn('Queensland');
     $this->equal($firstAddress, $secondAddress)->shouldReturn(true);
 }
 function it_gets_province_name_form_address_if_its_abbreviation_is_not_set(AddressInterface $address)
 {
     $address->getProvinceName()->willReturn('Ulster');
     $this->getAbbreviation($address)->shouldReturn('Ulster');
 }
Beispiel #4
0
 /**
  * @param AddressInterface $address
  *
  * @return array
  */
 private function normalizeAddress(AddressInterface $address)
 {
     return array_map(function ($value) {
         return trim(strtolower($value));
     }, [$address->getCity(), $address->getCompany(), $address->getCountryCode(), $address->getFirstName(), $address->getLastName(), $address->getPhoneNumber(), $address->getPostcode(), $address->getProvinceCode(), $address->getProvinceName(), $address->getStreet()]);
 }