Skip to content
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
6 changes: 5 additions & 1 deletion src/Adamlc/AddressFormat/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Adamlc\AddressFormat\Exceptions\LocaleNotSupportedException;
use Adamlc\AddressFormat\Exceptions\LocaleParseErrorException;
use Adamlc\AddressFormat\Exceptions\LocaleMissingFormatException;
use function array_filter;
use function explode;
use function trim;

/**
* Use this call to format a street address according to different locales
Expand Down Expand Up @@ -135,7 +137,9 @@ protected function normalize($address, $html = false)
$separator = $html ? '<br>' : "\n";
$parts = explode($separator, $address);

$parts = array_filter($parts, 'strlen');
$parts = array_filter($parts, function ($part) {
return ! empty(trim($part));
});
$parts = array_map('trim', $parts);

$address = implode($separator, $parts);
Expand Down
31 changes: 27 additions & 4 deletions tests/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ public function testLocaleWithInvalidMetaData()
$this->container->setLocale('_Invalid');
}

/**
* Test setting a single attribute
*
* @return void
*/
public function testSettingASingleAttribute()
{
$this->container->clearAttributes();
$this->container->setLocale('ES');

$this->container->setAttribute('RECIPIENT', '');
$this->container->setAttribute('ORGANIZATION', '');
$this->container->setAttribute('STREET_ADDRESS', '');
$this->container->setAttribute('POSTAL_CODE', '');
$this->container->setAttribute('LOCALITY', '');
$this->container->setAttribute('RECIPIENT', 'Jesper Jacobsen');

$this->assertEquals(
$this->container->formatAddress(),
"Jesper Jacobsen"
);
}

/**
* Test setting a valid attribute
*
Expand Down Expand Up @@ -308,10 +331,10 @@ public function testArrayAccess()
}

/**
* Check that an exception is thrown for validAddressPieces by invlidate locale
*
* @return void
*/
* Check that an exception is thrown for validAddressPieces by invlidate locale
*
* @return void
*/
public function testValidAddressPiecesLocaleMissingFormatException()
{
//Clear any previously set attributes
Expand Down