Skip to content

Commit

Permalink
Fix tokenizer returning lower case outward/inward codes, and testing …
Browse files Browse the repository at this point in the history
…against lower case postcodes
  • Loading branch information
Jordan Hall committed Mar 9, 2018
1 parent c947830 commit bf3e41c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/Utils/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ public static function outward($postcode)
{
self::sanityCheck($postcode);

$postcodeStart = trim(substr($postcode, 0, -3));

return $postcodeStart;
return strtoupper(trim(substr($postcode, 0, -3)));
}

public static function inward($postcode)
{
self::sanityCheck($postcode);

$postcodeEnd = trim(substr($postcode, -3, 3));

return $postcodeEnd;
return strtoupper(trim(substr($postcode, -3, 3)));
}

private static function sanityCheck($postcode)
Expand Down
7 changes: 6 additions & 1 deletion tests/Unit/BasicUsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class BasicUsageTest extends TestCase
{
public function testValidation()
{
$postcodes = ['ST163DP', 'TN30YA', 'ST78PP', 'CM233WE', 'E16AW', 'E106QX', 'ST16 3DP'];
$postcodes = ['ST163DP', 'TN30YA', 'ST78PP', 'CM233WE', 'E16AW', 'E106QX', 'ST16 3DP', 'st16 3dp'];

foreach ($postcodes as $postcode) {
$this->assertTrue(Validator::validatePostcode($postcode));
Expand Down Expand Up @@ -82,6 +82,11 @@ public function testOutwardAndInwardCodes()
'outward' => 'E1',
'inward' => '6AW',
],
[
'postcode' => 'e1 6aw',
'outward' => 'E1',
'inward' => '6AW',
],
];

foreach ($postcodeTestItems as $postcodeTestItem) {
Expand Down

0 comments on commit bf3e41c

Please sign in to comment.