Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DivineOmega/php-postcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Hall committed Oct 25, 2019
2 parents 605e389 + 78db460 commit 0c576ca
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
language: php
dist: trusty
php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- 'hhvm'
- '7.3'
install:
- composer update
script:
- ./vendor/bin/phpunit --coverage-clover ./tests/Logs/clover.xml
after_script:
- php vendor/bin/php-coveralls -v
- php vendor/bin/php-coveralls -v
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ $postcode = \DivineOmega\Postcodes\Utils\Generator::generatePostcode();
> The first part of the Postcode eg PO1 is called the outward code as it identifies the town or district to which the letter is to be sent for further sorting. The second part of the postcode eg 1EB is called the inward code.
```php
$outwardCode = \DivineOmega\Postcodes\Utils\Tokenizer::outward('ST163JR'); // Returns ST16
$inwardCode = \DivineOmega\Postcodes\Utils\Tokenizer::inward('ST163JR'); // Returns 3JR
$outwardCode = \DivineOmega\Postcodes\Utils\Tokenizer::outward('ST163DP'); // Returns ST16
$inwardCode = \DivineOmega\Postcodes\Utils\Tokenizer::inward('ST163DP'); // Returns 3DP
```
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"homepage": "https://github.com/divineomega/php-postcodes",
"license": "LGPL-3.0-only",
"require": {
"php": ">=5.5.9",
"php": "^7.1",
"guzzlehttp/guzzle": "~6.0",
"fzaninotto/faker": "^1.6",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"phpunit/phpunit": "^7.0 || ^8.0",
"fzaninotto/faker": "^1.6",
"php-coveralls/php-coveralls": "^2.0"
},
Expand Down
68 changes: 50 additions & 18 deletions tests/Unit/BasicUsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,48 @@

final class BasicUsageTest extends TestCase
{
public function testValidation()
public function validationProvider()
{
$postcodes = ['ST163DP', 'TN30YA', 'ST78PP', 'CM233WE', 'E16AW', 'E106QX', 'ST16 3DP', 'st16 3dp'];
return [
['ST163DP'],
['TN30YA'],
['ST78PP'],
['CM233WE'],
['E16AW'],
['E106QX'],
['ST16 3DP'],
['st16 3dp'],
];
}

foreach ($postcodes as $postcode) {
$this->assertTrue(Validator::validatePostcode($postcode));
}
/**
* @dataProvider validationProvider
*/
public function testValidation($postcode)
{
$this->assertTrue(Validator::validatePostcode($postcode));
}

public function testValidationFailure()
public function validationFailureProvider()
{
$postcodes = ['ST163DPA', 'XF2P90', 'Ollie', 'cake', 'ST16 3DPA', 'KT18 5DN', 'AB15 4YR', 'B62 8RS'];
return [
['ST163DPA'],
['XF2P90'],
['Ollie'],
['cake'],
['ST16 3DPA'],
['KT18 5DN'],
['AB15 4YR'],
['B62 8RS'],
];
}

foreach ($postcodes as $postcode) {
$this->assertFalse(Validator::validatePostcode($postcode));
}
/**
* @dataProvider validationFailureProvider
*/
public function testValidationFailure($postcode)
{
$this->assertFalse(Validator::validatePostcode($postcode));
}

public function testGeneration()
Expand All @@ -39,9 +65,9 @@ public function testGeneration()
}
}

public function testOutwardAndInwardCodes()
public function outwardAndInwardCodesProvider()
{
$postcodeTestItems = [
return [
[
'postcode' => 'ST163DP',
'outward' => 'ST16',
Expand Down Expand Up @@ -88,24 +114,30 @@ public function testOutwardAndInwardCodes()
'inward' => '6AW',
],
];
}

foreach ($postcodeTestItems as $postcodeTestItem) {
$this->assertEquals($postcodeTestItem['outward'], Tokenizer::outward($postcodeTestItem['postcode']));
$this->assertEquals($postcodeTestItem['inward'], Tokenizer::inward($postcodeTestItem['postcode']));
}
/**
* @dataProvider outwardAndInwardCodesProvider
*/
public function testOutwardAndInwardCodes($postcode, $outward, $inward)
{
$this->assertEquals($outward, Tokenizer::outward($postcode));
$this->assertEquals($inward, Tokenizer::inward($postcode));
}

public function testOutwardCodeWithInvalidPostcode()
{
$this->expectException(InvalidPostcodeException::class);
$this->expectExceptionMessage('Post code provided is not valid');

$outward = Tokenizer::outward('ST163DPA');
Tokenizer::outward('ST163DPA');
}

public function testInwardCodeWithInvalidPostcode()
{
$this->expectException(InvalidPostcodeException::class);
$this->expectExceptionMessage('Post code provided is not valid');

$outward = Tokenizer::inward('ST163DPA');
Tokenizer::inward('ST163DPA');
}
}

0 comments on commit 0c576ca

Please sign in to comment.