Skip to content

Commit

Permalink
Add support for an additional address line (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorry84 authored Aug 7, 2020
1 parent 8db5e69 commit 71e4208
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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);
}
}

0 comments on commit 71e4208

Please sign in to comment.