Skip to content

Commit

Permalink
Add address line 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
vacho authored and bojanz committed Mar 8, 2023
1 parent 13be3c2 commit 96552c2
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 212 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The [address interface](https://github.com/commerceguys/addressing/blob/master/s
- Sorting code
- Address line 1
- Address line 2
- Address line 3
- Organization
- Given name (First name)
- Additional name (Middle name / Patronymic)
Expand Down
29 changes: 29 additions & 0 deletions src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class Address implements ImmutableAddressInterface
*/
protected string $addressLine2;

/**
* The third line of the address block.
*
* @var string
*/
protected string $addressLine3;

/**
* The organization.
*
Expand Down Expand Up @@ -111,6 +118,7 @@ class Address implements ImmutableAddressInterface
* @param string $sortingCode The sorting code
* @param string $addressLine1 The first line of the address block.
* @param string $addressLine2 The second line of the address block.
* @param string $addressLine3 The third line of the address block.
* @param string $organization The organization.
* @param string $givenName The given name.
* @param string $additionalName The additional name.
Expand All @@ -126,6 +134,7 @@ public function __construct(
?string $sortingCode = '',
?string $addressLine1 = '',
?string $addressLine2 = '',
?string $addressLine3 = '',
?string $organization = '',
?string $givenName = '',
?string $additionalName = '',
Expand All @@ -140,6 +149,7 @@ public function __construct(
$this->sortingCode = $sortingCode;
$this->addressLine1 = $addressLine1;
$this->addressLine2 = $addressLine2;
$this->addressLine3 = $addressLine3;
$this->organization = $organization;
$this->givenName = $givenName;
$this->additionalName = $additionalName;
Expand Down Expand Up @@ -299,6 +309,25 @@ public function withAddressLine2(string $addressLine2): ImmutableAddressInterfac
return $new;
}

/**
* {@inheritdoc}
*/
public function getAddressLine3(): ?string
{
return $this->addressLine3;
}

/**
* {@inheritdoc}
*/
public function withAddressLine3(string $addressLine3): ImmutableAddressInterface|Address
{
$new = clone $this;
$new->addressLine3 = $addressLine3;

return $new;
}

/**
* {@inheritdoc}
*/
Expand Down
1 change: 1 addition & 0 deletions src/AddressFormat/AddressField.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class AddressField extends AbstractEnum
public const SORTING_CODE = 'sortingCode';
public const ADDRESS_LINE1 = 'addressLine1';
public const ADDRESS_LINE2 = 'addressLine2';
public const ADDRESS_LINE3 = 'addressLine3';
public const ORGANIZATION = 'organization';
public const GIVEN_NAME = 'givenName';
public const ADDITIONAL_NAME = 'additionalName';
Expand Down
1 change: 1 addition & 0 deletions src/AddressFormat/AddressFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function getLocale(): ?string
* %organization
* %addressLine1
* %addressLine2
* %addressLine3
* %locality %administrativeArea %postalCode
* </code>
*
Expand Down
1 change: 1 addition & 0 deletions src/AddressFormat/AddressFormatHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class AddressFormatHelper
* [organization],
* [addressLine1],
* [addressLine2],
* [addressLine3],
* [locality, administrativeArea, postalCode]
* ]
* @throws \ReflectionException
Expand Down
414 changes: 207 additions & 207 deletions src/AddressFormat/AddressFormatRepository.php

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/AddressInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public function getAddressLine1(): ?string;
*/
public function getAddressLine2(): ?string;

/**
* Gets the third line of address block.
*/
public function getAddressLine3(): ?string;

/**
* Gets the organization.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/ImmutableAddressInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function withAddressLine1(string $addressLine1): ImmutableAddressInterfac
*/
public function withAddressLine2(string $addressLine2): ImmutableAddressInterface;

/**
* Returns an instance with the specified third line of address block.
*/
public function withAddressLine3(string $addressLine3): ImmutableAddressInterface;

/**
* Returns an instance with the specified organization.
*/
Expand Down
6 changes: 4 additions & 2 deletions tests/AddressFormat/AddressFormatHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ final class AddressFormatHelperTest extends TestCase
*/
public function testGetGroupedFields(): void
{
$format = "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality, %postalCode";
$format = "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%addressLine3\n%locality, %postalCode";
$expectedGroupedFields = [
[AddressField::GIVEN_NAME, AddressField::FAMILY_NAME],
[AddressField::ORGANIZATION],
[AddressField::ADDRESS_LINE1],
[AddressField::ADDRESS_LINE2],
[AddressField::ADDRESS_LINE3],
[AddressField::LOCALITY, AddressField::POSTAL_CODE],
];
$this->assertEquals($expectedGroupedFields, AddressFormatHelper::getGroupedFields($format));
Expand All @@ -37,6 +38,7 @@ public function testGetGroupedFields(): void
[AddressField::GIVEN_NAME, AddressField::FAMILY_NAME],
[AddressField::ADDRESS_LINE1],
[AddressField::ADDRESS_LINE2],
[AddressField::ADDRESS_LINE3],
[AddressField::POSTAL_CODE],
];
$this->assertEquals($expectedGroupedFields, AddressFormatHelper::getGroupedFields($format, $fieldOverrides));
Expand All @@ -49,7 +51,7 @@ public function testGetRequiredFields(): void
{
$addressFormat = new AddressFormat([
'country_code' => 'US',
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality, %administrativeArea %postalCode",
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%addressLine3\n%locality, %administrativeArea %postalCode",
'required_fields' => [
AddressField::ADMINISTRATIVE_AREA,
AddressField::LOCALITY,
Expand Down
5 changes: 3 additions & 2 deletions tests/AddressFormat/AddressFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testInvalidSubdivision(): void
$this->expectException(\InvalidArgumentException::class);
$definition = [
'country_code' => 'US',
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%dependentLocality",
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%addressLine3\n%dependentLocality",
'required_fields' => [AddressField::ADDRESS_LINE1],
'dependent_locality_type' => 'WRONG',
];
Expand Down Expand Up @@ -69,7 +69,7 @@ public function testValid(): void
$definition = [
'country_code' => 'US',
'locale' => 'en',
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality, %administrativeArea %postalCode",
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%addressLine3\n%locality, %administrativeArea %postalCode",
// The local format is made up, US doesn't have one usually.
'local_format' => '%postalCode\n%addressLine1\n%organization\n%givenName %familyName',
'required_fields' => [
Expand Down Expand Up @@ -114,6 +114,7 @@ public function testValid(): void
AddressField::POSTAL_CODE,
AddressField::ADDRESS_LINE1,
AddressField::ADDRESS_LINE2,
AddressField::ADDRESS_LINE3,
AddressField::ORGANIZATION,
AddressField::GIVEN_NAME,
AddressField::FAMILY_NAME,
Expand Down
13 changes: 12 additions & 1 deletion tests/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class AddressTest extends TestCase
*/
public function testConstructor(): void
{
$address = new Address('US', 'CA', 'Mountain View', 'MV', '94043', '94044', '1600 Amphitheatre Parkway', 'Google Bldg 41', 'Google Inc.', 'John', '', 'Smith', 'en');
$address = new Address('US', 'CA', 'Mountain View', 'MV', '94043', '94044', '1600 Amphitheatre Parkway', 'Google Bldg 41', 'Office 35', 'Google Inc.', 'John', '', 'Smith', 'en');
$this->assertEquals('US', $address->getCountryCode());
$this->assertEquals('CA', $address->getAdministrativeArea());
$this->assertEquals('Mountain View', $address->getLocality());
Expand All @@ -24,6 +24,7 @@ public function testConstructor(): void
$this->assertEquals('94044', $address->getSortingCode());
$this->assertEquals('1600 Amphitheatre Parkway', $address->getAddressLine1());
$this->assertEquals('Google Bldg 41', $address->getAddressLine2());
$this->assertEquals('Office 35', $address->getAddressLine3());
$this->assertEquals('Google Inc.', $address->getOrganization());
$this->assertEquals('John', $address->getGivenName());
$this->assertEquals('Smith', $address->getFamilyName());
Expand Down Expand Up @@ -112,6 +113,16 @@ public function testAddressLine2(): void
$this->assertEquals('Google Bldg 41', $address->getAddressLine2());
}

/**
* @covers ::getAddressLine3
* @covers ::withAddressLine3
*/
public function testAddressLine3(): void
{
$address = (new Address())->withAddressLine3('Office 35');
$this->assertEquals('Office 35', $address->getAddressLine3());
}

/**
* @covers ::getOrganization
* @covers ::withOrganization
Expand Down
2 changes: 2 additions & 0 deletions tests/Formatter/PostalLabelFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function testJapanAddressShippedFromFrance(): void
->withLocality('Some City')
->withAddressLine1('Address Line 1')
->withAddressLine2('Address Line 2')
->withAddressLine2('Address Line 3')
->withPostalCode('04')
->withLocale('ja');

Expand All @@ -112,6 +113,7 @@ public function testJapanAddressShippedFromFrance(): void
'北海道Some City',
'Address Line 1',
'Address Line 2',
'Address Line 3',
];
$formattedAddress = $this->formatter->format($address, [
'locale' => 'fr',
Expand Down

0 comments on commit 96552c2

Please sign in to comment.