Skip to content

Commit bf3e41c

Browse files
author
Jordan Hall
committed
Fix tokenizer returning lower case outward/inward codes, and testing against lower case postcodes
1 parent c947830 commit bf3e41c

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/Utils/Tokenizer.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ public static function outward($postcode)
1010
{
1111
self::sanityCheck($postcode);
1212

13-
$postcodeStart = trim(substr($postcode, 0, -3));
14-
15-
return $postcodeStart;
13+
return strtoupper(trim(substr($postcode, 0, -3)));
1614
}
1715

1816
public static function inward($postcode)
1917
{
2018
self::sanityCheck($postcode);
2119

22-
$postcodeEnd = trim(substr($postcode, -3, 3));
23-
24-
return $postcodeEnd;
20+
return strtoupper(trim(substr($postcode, -3, 3)));
2521
}
2622

2723
private static function sanityCheck($postcode)

tests/Unit/BasicUsageTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ final class BasicUsageTest extends TestCase
1010
{
1111
public function testValidation()
1212
{
13-
$postcodes = ['ST163DP', 'TN30YA', 'ST78PP', 'CM233WE', 'E16AW', 'E106QX', 'ST16 3DP'];
13+
$postcodes = ['ST163DP', 'TN30YA', 'ST78PP', 'CM233WE', 'E16AW', 'E106QX', 'ST16 3DP', 'st16 3dp'];
1414

1515
foreach ($postcodes as $postcode) {
1616
$this->assertTrue(Validator::validatePostcode($postcode));
@@ -82,6 +82,11 @@ public function testOutwardAndInwardCodes()
8282
'outward' => 'E1',
8383
'inward' => '6AW',
8484
],
85+
[
86+
'postcode' => 'e1 6aw',
87+
'outward' => 'E1',
88+
'inward' => '6AW',
89+
],
8590
];
8691

8792
foreach ($postcodeTestItems as $postcodeTestItem) {

0 commit comments

Comments
 (0)