Exemple #1
0
 /**
  * @param  Address $address
  * @param  bool    $addCountry
  * @return string[]
  */
 public function formatAddress(Address $address, $addCountry = true)
 {
     $countryCode = $address->getCountryCode();
     $lines = [];
     $currentLine = '';
     foreach ($this->getFormatSubStrings($countryCode) as $part) {
         if ($part === "\n") {
             $normalizedLine = $this->removeAllRedundantSpaces($currentLine);
             if (strlen($normalizedLine) > 0) {
                 $lines[] = $normalizedLine;
             }
             $currentLine = '';
             continue;
         }
         if ($part[0] === '%') {
             $flag = $part[1];
             $field = static::$fieldMap[$flag];
             $value = $address->{'get' . ucfirst($field)}();
             if ($value !== null) {
                 $currentLine .= $value;
             }
             continue;
         }
         $currentLine .= $part;
     }
     $normalizedLine = $this->removeAllRedundantSpaces($currentLine);
     if (strlen($normalizedLine) > 0) {
         $lines[] = $normalizedLine;
     }
     if ($addCountry && $countryCode !== 'ZZ') {
         $lines[] = $this->getJsonValue($countryCode, 'name');
     }
     return $lines;
 }
 /**
  * @covers ::formatAddress
  */
 public function testFormatAddressThrowsExceptionOnInvalidFormat()
 {
     $this->setExpectedException('RuntimeException', 'Unrecognized character "]" in format pattern "%]"');
     $address = new Address();
     $address->setCountryCode('FR');
     $addressService = new AddressService($this->options);
     $addressService->formatAddress($address);
 }
Exemple #3
0
 /**
  * @covers ::setCountryCode
  * @covers ::getCountryCode
  */
 public function testSetGetCountryCode()
 {
     $this->address->setCountryCode('foo');
     $this->assertSame('foo', $this->address->getCountryCode());
 }