Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for an additional address line #49

Merged
merged 1 commit into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ $parcel = new \Mvdnbrk\DhlParcel\Resources\Parcel([
'sender' => [
'company_name' => 'Your Company Name',
'street' => 'Pakketstraat',
'additional_address_line' => 'Industrie 9999',
'number' => '99',
'postal_code' => '9999AA',
'city' => 'Amsterdam',
Expand Down
10 changes: 10 additions & 0 deletions src/Resources/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class Address extends BaseResource
*/
public $street;

/**
* @var string
*/
public $additional_address_line;

/**
* @var int|string
*/
Expand Down Expand Up @@ -120,6 +125,11 @@ public function toArray()
->put('addition', $this->number_suffix)
->forget('number_suffix');
})
->when(! empty($this->additional_address_line), function ($collection) {
return $collection
->put('additionalAddressLine', $this->additional_address_line)
->forget('additional_address_line');
})
->put('postalCode', $this->postal_code)
->put('countryCode', $this->cc)
->forget('postal_code')
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/Resources/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ private function validParams($overrides = [])
{
return array_merge([
'street' => 'Poststraat',
'additional_address_line' => 'Industrie 9999',
'number' => '1',
'number_suffix' => 'A',
'postal_code' => '1234AA',
Expand All @@ -25,6 +26,7 @@ public function creating_a_valid_address_resource()
{
$address = new Address([
'street' => 'Poststraat',
'additional_address_line' => 'Industrie 9999',
'number' => '1',
'number_suffix' => 'A',
'postal_code' => '1234AA',
Expand All @@ -34,6 +36,7 @@ public function creating_a_valid_address_resource()
]);

$this->assertEquals('Poststraat', $address->street);
$this->assertEquals('Industrie 9999', $address->additional_address_line);
$this->assertEquals('1', $address->number);
$this->assertEquals('A', $address->number_suffix);
$this->assertEquals('1234AA', $address->postal_code);
Expand Down Expand Up @@ -110,6 +113,7 @@ public function to_array()
{
$attributes = [
'street' => 'Poststraat',
'additional_address_line' => 'Industrie 9999',
'number' => '1',
'number_suffix' => 'A',
'postal_code' => '1234AA',
Expand All @@ -125,10 +129,12 @@ public function to_array()
$this->assertIsArray($array);
$this->assertFalse($array['isBusiness']);
$this->assertEquals('Poststraat', $array['street']);
$this->assertEquals('Industrie 9999', $array['additionalAddressLine']);
$this->assertEquals('1', $array['number']);
$this->assertEquals('A', $array['addition']);
$this->assertEquals('1234AA', $array['postalCode']);
$this->assertEquals('NL', $array['countryCode']);
$this->assertArrayNotHasKey('additional_address_line', $array);
$this->assertArrayNotHasKey('number_suffix', $array);
$this->assertArrayNotHasKey('postal_code', $array);
$this->assertArrayNotHasKey('cc', $array);
Expand All @@ -137,5 +143,10 @@ public function to_array()
$array = $address->toArray();
$this->assertArrayNotHasKey('addition', $array);
$this->assertArrayNotHasKey('number_suffix', $array);

$address->additional_address_line = null;
$array = $address->toArray();
$this->assertArrayNotHasKey('additionalAddressLine', $array);
$this->assertArrayNotHasKey('additional_address_line', $array);
}
}