From 90032d29a210f4055cc707815425074ea8faa894 Mon Sep 17 00:00:00 2001 From: peter279k Date: Sat, 13 Apr 2019 02:12:08 +0800 Subject: [PATCH 1/2] Test enhancement --- .travis.yml | 6 ++-- composer.json | 4 +-- tests/Unit/BasicUsageTest.php | 68 +++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4ee7185..8a04540 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 \ No newline at end of file + - php vendor/bin/php-coveralls -v diff --git a/composer.json b/composer.json index 5789e1d..4b6a9e2 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/tests/Unit/BasicUsageTest.php b/tests/Unit/BasicUsageTest.php index 02b8827..df65a07 100644 --- a/tests/Unit/BasicUsageTest.php +++ b/tests/Unit/BasicUsageTest.php @@ -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() @@ -39,9 +65,9 @@ public function testGeneration() } } - public function testOutwardAndInwardCodes() + public function outwardAndInwardCodesProvider() { - $postcodeTestItems = [ + return [ [ 'postcode' => 'ST163DP', 'outward' => 'ST16', @@ -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'); } } From 78db46062c25fd6cea93d0d3d6b3ec599476ef2b Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Fri, 21 Jun 2019 10:16:15 +0100 Subject: [PATCH 2/2] Make example postcodes consistent --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ed7456..f9d0f37 100644 --- a/README.md +++ b/README.md @@ -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 ```