Skip to content

Commit d0bc066

Browse files
authored
Merge pull request #1 from peter279k/test_enhancement
Test enhancement
2 parents a6da491 + 90032d2 commit d0bc066

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
language: php
22
dist: trusty
33
php:
4-
- '5.6'
5-
- '7.0'
64
- '7.1'
75
- '7.2'
8-
- 'hhvm'
6+
- '7.3'
97
install:
108
- composer update
119
script:
1210
- ./vendor/bin/phpunit --coverage-clover ./tests/Logs/clover.xml
1311
after_script:
14-
- php vendor/bin/php-coveralls -v
12+
- php vendor/bin/php-coveralls -v

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"homepage": "https://github.com/divineomega/php-postcodes",
77
"license": "LGPL-3.0-only",
88
"require": {
9-
"php": ">=5.5.9",
9+
"php": "^7.1",
1010
"guzzlehttp/guzzle": "~6.0",
1111
"fzaninotto/faker": "^1.6",
1212
"ext-json": "*"
1313
},
1414
"require-dev": {
15-
"phpunit/phpunit": "^5.7",
15+
"phpunit/phpunit": "^7.0 || ^8.0",
1616
"fzaninotto/faker": "^1.6",
1717
"php-coveralls/php-coveralls": "^2.0"
1818
},

tests/Unit/BasicUsageTest.php

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,48 @@
88

99
final class BasicUsageTest extends TestCase
1010
{
11-
public function testValidation()
11+
public function validationProvider()
1212
{
13-
$postcodes = ['ST163DP', 'TN30YA', 'ST78PP', 'CM233WE', 'E16AW', 'E106QX', 'ST16 3DP', 'st16 3dp'];
13+
return [
14+
['ST163DP'],
15+
['TN30YA'],
16+
['ST78PP'],
17+
['CM233WE'],
18+
['E16AW'],
19+
['E106QX'],
20+
['ST16 3DP'],
21+
['st16 3dp'],
22+
];
23+
}
1424

15-
foreach ($postcodes as $postcode) {
16-
$this->assertTrue(Validator::validatePostcode($postcode));
17-
}
25+
/**
26+
* @dataProvider validationProvider
27+
*/
28+
public function testValidation($postcode)
29+
{
30+
$this->assertTrue(Validator::validatePostcode($postcode));
1831
}
1932

20-
public function testValidationFailure()
33+
public function validationFailureProvider()
2134
{
22-
$postcodes = ['ST163DPA', 'XF2P90', 'Ollie', 'cake', 'ST16 3DPA', 'KT18 5DN', 'AB15 4YR', 'B62 8RS'];
35+
return [
36+
['ST163DPA'],
37+
['XF2P90'],
38+
['Ollie'],
39+
['cake'],
40+
['ST16 3DPA'],
41+
['KT18 5DN'],
42+
['AB15 4YR'],
43+
['B62 8RS'],
44+
];
45+
}
2346

24-
foreach ($postcodes as $postcode) {
25-
$this->assertFalse(Validator::validatePostcode($postcode));
26-
}
47+
/**
48+
* @dataProvider validationFailureProvider
49+
*/
50+
public function testValidationFailure($postcode)
51+
{
52+
$this->assertFalse(Validator::validatePostcode($postcode));
2753
}
2854

2955
public function testGeneration()
@@ -39,9 +65,9 @@ public function testGeneration()
3965
}
4066
}
4167

42-
public function testOutwardAndInwardCodes()
68+
public function outwardAndInwardCodesProvider()
4369
{
44-
$postcodeTestItems = [
70+
return [
4571
[
4672
'postcode' => 'ST163DP',
4773
'outward' => 'ST16',
@@ -88,24 +114,30 @@ public function testOutwardAndInwardCodes()
88114
'inward' => '6AW',
89115
],
90116
];
117+
}
91118

92-
foreach ($postcodeTestItems as $postcodeTestItem) {
93-
$this->assertEquals($postcodeTestItem['outward'], Tokenizer::outward($postcodeTestItem['postcode']));
94-
$this->assertEquals($postcodeTestItem['inward'], Tokenizer::inward($postcodeTestItem['postcode']));
95-
}
119+
/**
120+
* @dataProvider outwardAndInwardCodesProvider
121+
*/
122+
public function testOutwardAndInwardCodes($postcode, $outward, $inward)
123+
{
124+
$this->assertEquals($outward, Tokenizer::outward($postcode));
125+
$this->assertEquals($inward, Tokenizer::inward($postcode));
96126
}
97127

98128
public function testOutwardCodeWithInvalidPostcode()
99129
{
100130
$this->expectException(InvalidPostcodeException::class);
131+
$this->expectExceptionMessage('Post code provided is not valid');
101132

102-
$outward = Tokenizer::outward('ST163DPA');
133+
Tokenizer::outward('ST163DPA');
103134
}
104135

105136
public function testInwardCodeWithInvalidPostcode()
106137
{
107138
$this->expectException(InvalidPostcodeException::class);
139+
$this->expectExceptionMessage('Post code provided is not valid');
108140

109-
$outward = Tokenizer::inward('ST163DPA');
141+
Tokenizer::inward('ST163DPA');
110142
}
111143
}

0 commit comments

Comments
 (0)