Skip to content

Commit

Permalink
Test enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Apr 12, 2019
1 parent a6da491 commit 90032d2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 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 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 90032d2

Please sign in to comment.