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'); } }