-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom exception for invalid postcodes, fix to tokenizer, add uni…
…t tests
- Loading branch information
Jordan Hall
committed
Mar 9, 2018
1 parent
afb0c8e
commit 406cae4
Showing
7 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage_clover: tests/Logs/clover.xml | ||
json_path: tests/Logs/coveralls-upload.json | ||
service_name: travis-ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: php | ||
dist: trusty | ||
php: | ||
- '5.6' | ||
- '7.0' | ||
- '7.1' | ||
- 'hhvm' | ||
install: | ||
- composer update | ||
script: | ||
- ./vendor/bin/phpunit --coverage-clover ./tests/Logs/clover.xml | ||
after_script: | ||
- php vendor/bin/php-coveralls -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Unit Tests"> | ||
<directory suffix="Test.php">./tests/Unit</directory> | ||
<directory suffix="Test.php">./tests/Integration</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
<exclude> | ||
<directory suffix=".php">src/Examples</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
<php> | ||
|
||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
namespace RapidWeb\Postcodes\Exceptions; | ||
|
||
class InvalidPostcodeException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use RapidWeb\Postcodes\Utils\Validator; | ||
use RapidWeb\Postcodes\Utils\Generator; | ||
use RapidWeb\Postcodes\Utils\Tokenizer; | ||
use RapidWeb\Postcodes\Exceptions\InvalidPostcodeException; | ||
|
||
final class BasicUsageTest extends TestCase | ||
{ | ||
public function testValidation() | ||
{ | ||
$postcodes = ['ST163DP', 'TN30YA', 'ST78PP', 'CM233WE', 'E16AW', 'E106QX']; | ||
|
||
foreach($postcodes as $postcode) { | ||
$this->assertTrue(Validator::validatePostcode($postcode)); | ||
} | ||
} | ||
|
||
public function testValidationFailure() | ||
{ | ||
$postcodes = ['ST163DPA', 'XF2P90', 'Ollie', 'cake']; | ||
|
||
foreach($postcodes as $postcode) { | ||
$this->assertFalse(Validator::validatePostcode($postcode)); | ||
} | ||
} | ||
|
||
public function testGeneration() | ||
{ | ||
$postcodes = []; | ||
|
||
for ($i=0; $i < 100; $i++) { | ||
$postcodes[] = Generator::generatePostcode(); | ||
} | ||
|
||
foreach($postcodes as $postcode) { | ||
$this->assertTrue(Validator::validatePostcode($postcode)); | ||
} | ||
} | ||
|
||
public function testOutwardAndInwardCodes() | ||
{ | ||
$postcodeTestItems = [ | ||
[ | ||
'postcode' => 'ST163DP', | ||
'outward' => 'ST16', | ||
'inward' => '3DP' | ||
], | ||
[ | ||
'postcode' => 'TN30YA', | ||
'outward' => 'TN3', | ||
'inward' => '0YA' | ||
], | ||
[ | ||
'postcode' => 'ST78PP', | ||
'outward' => 'ST7', | ||
'inward' => '8PP' | ||
], | ||
[ | ||
'postcode' => 'CM233WE', | ||
'outward' => 'CM23', | ||
'inward' => '3WE' | ||
], | ||
[ | ||
'postcode' => 'E16AW', | ||
'outward' => 'E1', | ||
'inward' => '6AW' | ||
], | ||
[ | ||
'postcode' => 'E106QX', | ||
'outward' => 'E10', | ||
'inward' => '6QX' | ||
] | ||
]; | ||
|
||
foreach($postcodeTestItems as $postcodeTestItem) { | ||
$this->assertEquals($postcodeTestItem['outward'], Tokenizer::outward($postcodeTestItem['postcode'])); | ||
$this->assertEquals($postcodeTestItem['inward'], Tokenizer::inward($postcodeTestItem['postcode'])); | ||
} | ||
} | ||
|
||
public function testOutwardCodeWithInvalidPostcode() | ||
{ | ||
$this->expectException(InvalidPostcodeException::class); | ||
|
||
$outward = Tokenizer::outward('ST163DPA'); | ||
} | ||
|
||
public function testInwardCodeWithInvalidPostcode() | ||
{ | ||
$this->expectException(InvalidPostcodeException::class); | ||
|
||
$outward = Tokenizer::inward('ST163DPA'); | ||
} | ||
} |