Skip to content

Commit

Permalink
Fix hanging newline (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
JapSeyz committed Jan 31, 2025
1 parent 34a1e65 commit 3342ef5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
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

0 comments on commit 3342ef5

Please sign in to comment.