From 996084185805efc060c17d9d501dd497a730935b Mon Sep 17 00:00:00 2001 From: Recca Tsai Date: Mon, 6 Jun 2016 01:03:54 +0800 Subject: [PATCH] first commit --- .editorconfig | 13 +++ .gitattributes | 12 ++ .gitignore | 8 ++ .nitpick.json | 5 + .php_cs | 82 +++++++++++++ .travis.yml | 14 +++ LICENSE | 22 ++++ README.md | 19 ++++ composer.json | 23 ++++ gulpfile.js | 20 ++++ package.json | 9 ++ phpcs.xml | 20 ++++ phpunit.xml | 25 ++++ ruleset.xml | 29 +++++ src/Twzipcode.php | 247 ++++++++++++++++++++++++++++++++++++++++ src/twzipcode.json | 104 +++++++++++++++++ tests/TwzipcodeTest.php | 42 +++++++ tests/bootstrap.php | 28 +++++ 18 files changed, 722 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .nitpick.json create mode 100644 .php_cs create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 composer.json create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 phpcs.xml create mode 100644 phpunit.xml create mode 100644 ruleset.xml create mode 100644 src/Twzipcode.php create mode 100644 src/twzipcode.json create mode 100644 tests/TwzipcodeTest.php create mode 100644 tests/bootstrap.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ed1247a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..7bf58c2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,12 @@ +* text=auto + +/build export-ignore +/tests export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.nitpick.json export-ignore +.php_cs export-ignore +.travis.yml export-ignore +phpunit.php export-ignore +phpunit.xml export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87688c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/vendor +/resources/assets/vendor +/node_modules +composer.phar +composer.lock +.php_cs.cache +.DS_Store +Thumbs.db diff --git a/.nitpick.json b/.nitpick.json new file mode 100644 index 0000000..3881d8d --- /dev/null +++ b/.nitpick.json @@ -0,0 +1,5 @@ +{ + "ignore": [ + "tests/*" + ] +} diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..cf9a3af --- /dev/null +++ b/.php_cs @@ -0,0 +1,82 @@ +finder(DefaultFinder::create()->in(__DIR__)) + ->fixers($fixers) + ->level(FixerInterface::NONE_LEVEL) + ->setUsingCache(true); diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8bbf6c1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: php + +php: + - 5.5.9 + - 5.5 + - 5.6 + - 7.0 + - hhvm + +sudo: false + +install: travis_retry composer install --no-interaction --prefer-source + +script: vendor/bin/phpunit --verbose diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..85ef55f --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Recca Tsai + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..2bc146a --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# TWZIPCODE + +[![Latest Stable Version](https://poser.pugx.org/recca0120/twzipcode/v/stable)](https://packagist.org/packages/recca0120/twzipcode) +[![Total Downloads](https://poser.pugx.org/recca0120/twzipcode/downloads)](https://packagist.org/packages/recca0120/twzipcode) +[![Latest Unstable Version](https://poser.pugx.org/recca0120/twzipcode/v/unstable)](https://packagist.org/packages/recca0120/twzipcode) +[![License](https://poser.pugx.org/recca0120/twzipcode/license)](https://packagist.org/packages/recca0120/twzipcode) +[![Monthly Downloads](https://poser.pugx.org/recca0120/twzipcode/d/monthly)](https://packagist.org/packages/recca0120/twzipcode) +[![Daily Downloads](https://poser.pugx.org/recca0120/twzipcode/d/daily)](https://packagist.org/packages/recca0120/twzipcode) + +用來獲取台灣的區碼 + +```php +$twzipcode = new Twzipcode('北 縣 萬里鄉中正路100號'); +$twzipcode->getZipcode(); // 207 +$twzipcode->getCounty(); // 新北市 +$twzipcode->getDistrict(); // 萬里區 +$twzipcode->getAddress(); // 新北市萬里區中正路100號 +$twzipcode->getShortAddress(); // 中正路100號 +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..4215bf3 --- /dev/null +++ b/composer.json @@ -0,0 +1,23 @@ +{ + "name": "recca0120/twzipcode", + "description": "twzipcode", + "keywords": ["twzipcode"], + "license": "MIT", + "type": "library", + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "mockery/mockery": "0.9.*", + "nesbot/carbon": "~1.20", + "phpunit/phpunit": "~4.0" + }, + "autoload": { + "psr-4": { + "Recca0120\\Twzipcode\\": "src" + } + }, + "config": { + "preferred-install": "dist" + } +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..69cb5f1 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,20 @@ +var elixir = require('laravel-elixir'); +var path = require('path'); + +/* + |-------------------------------------------------------------------------- + | Elixir Asset Management + |-------------------------------------------------------------------------- + | + | Elixir provides a clean, fluent API for defining some basic Gulp tasks + | for your Laravel application. By default, we are compiling the Sass + | file for our application, as well as publishing vendor resources. + | + */ + +elixir(function(mix) { + mix.phpUnit([ + 'src/**/*.php', + 'tests/**/*' + ], path.normalize('vendor/bin/phpunit') + ' --verbose'); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..d1a29a5 --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "private": true, + "devDependencies": { + "gulp": "^3.9.1" + }, + "dependencies": { + "laravel-elixir": "^6.0.0-2" + } +} diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..bb63b97 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,20 @@ + + + + + + + + *.blade.php + *.twig.php + bootstrap/ + node_modules/ + public/build/ + public/css/ + public/js/ + public/vendor/ + resources/assets/ + resources/views/ + storage/ + vendor/ + diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..6859d87 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,25 @@ + + + + + ./tests + + + + + ./src + + + diff --git a/ruleset.xml b/ruleset.xml new file mode 100644 index 0000000..88a68d6 --- /dev/null +++ b/ruleset.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + 1 + + + + + + 1 + + + + + + diff --git a/src/Twzipcode.php b/src/Twzipcode.php new file mode 100644 index 0000000..7d96613 --- /dev/null +++ b/src/Twzipcode.php @@ -0,0 +1,247 @@ +originalAddress = $address; + + $parsed = $this->parse($this->normalizeAddress($address)); + $this->zipcode = $parsed['zipcode']; + $this->county = $parsed['county']; + $this->district = $parsed['district']; + $this->shortAddress = $parsed['shortAddress']; + $this->address = $parsed['address']; + } + + private function parse($address) + { + $county = null; + $district = null; + $zipcode = null; + $shortAddress = null; + $twzipcodeData = static::getTwzipcodeData(); + if (preg_match('/'.implode('|', array_keys($twzipcodeData)).'/', $address, $countyMatch)) { + $county = $countyMatch[0]; + $districts = $twzipcodeData[$county]; + $shortAddress = preg_replace('/^'.$county.'/', '', $address); + if (preg_match('/'.implode('|', array_keys($districts)).'/', $address, $districtMatch)) { + $district = $districtMatch[0]; + $zipcode = $districts[$district]; + $shortAddress = preg_replace('/^'.$district.'/', '', $shortAddress); + } + } + + return compact('county', 'district', 'zipcode', 'shortAddress', 'address'); + } + + public static function getTwzipcodeData() + { + if (is_null(static::$twzipcodeData) === true) { + static::$twzipcodeData = json_decode(file_get_contents(__DIR__.'/twzipcode.json'), true); + } + + return static::$twzipcodeData; + } + + private function normalizeAddress($address) + { + $address = str_replace([' ', ' '], '', $address); + $address = preg_replace('/^\d+/', '', $address); + $address = $this->normalizeCounty($address); + $address = $this->normalizeDistrict($address); + + return $address; + } + + private function normalizeCounty($address) + { + $newName = [ + '臺北' => '台北', + '台北縣' => '新北市', + '北市' => '台北市', + '北縣' => '新北市', + '臺南' => '台南', + '台南縣' => '台南市', + '南市' => '台南市', + '南縣' => '台南市', + '臺中' => '台中', + '台中縣' => '台中市', + '中市' => '台中市', + '中縣' => '台中市', + '高雄縣' => '高雄市', + '高縣' => '高雄市', + '高市' => '高雄市', + // '台東市' => '臺東市', + '臺東縣' => '台東縣', + ]; + + return preg_replace_callback('/^('.implode('|', array_keys($newName)).')/', function ($m) use ($newName) { + return $newName[$m[1]]; + }, $address); + } + + private function normalizeDistrict($address) + { + $newName = [ + '萬里鄉' => '萬里區', + '金山鄉' => '金山區', + '板橋市' => '板橋區', + '汐止市' => '汐止區', + '深坑鄉' => '深坑區', + '石碇鄉' => '石碇區', + '瑞芳鎮' => '瑞芳區', + '平溪鄉' => '平溪區', + '雙溪鄉' => '雙溪區', + '貢寮鄉' => '貢寮區', + '新店市' => '新店區', + '坪林鄉' => '坪林區', + '烏來鄉' => '烏來區', + '永和市' => '永和區', + '中和市' => '中和區', + '土城市' => '土城區', + '三峽鎮' => '三峽區', + '樹林市' => '樹林區', + '鶯歌鎮' => '鶯歌區', + '三重市' => '三重區', + '新莊市' => '新莊區', + '泰山鄉' => '泰山區', + '林口鄉' => '林口區', + '蘆洲市' => '蘆洲區', + '五股鄉' => '五股區', + '八里鄉' => '八里區', + '淡水鎮' => '淡水區', + '三芝鄉' => '三芝區', + '石門鄉' => '石門區', + '大雅鄉' => '大雅區', + '太平市' => '太平區', + '大里市' => '大里區', + '霧峰鄉' => '霧峰區', + '烏日鄉' => '烏日區', + '豐原市' => '豐原區', + '后里鄉' => '后里區', + '石岡鄉' => '石岡區', + '東勢鎮' => '東勢區', + '和平鄉' => '和平區', + '新社鄉' => '新社區', + '潭子鄉' => '潭子區', + '大雅鄉' => '大雅區', + '神岡鄉' => '神岡區', + '霧峰鄉' => '霧峰區', + '大肚鄉' => '大肚區', + '沙鹿鎮' => '沙鹿區', + '龍井鄉' => '龍井區', + '梧棲鎮' => '梧棲區', + '清水鎮' => '清水區', + '大甲鎮' => '大甲區', + '外埔鄉' => '外埔區', + '大安鄉' => '大安區', + '永康市' => '永康區', + '歸仁鄉' => '歸仁區', + '新化鎮' => '新化區', + '左鎮鄉' => '左鎮區', + '玉井鄉' => '玉井區', + '楠西鄉' => '楠西區', + '南化鄉' => '南化區', + '仁德鄉' => '仁德區', + '關廟鄉' => '關廟區', + '龍崎鄉' => '龍崎區', + '官田鄉' => '官田區', + '麻豆鎮' => '麻豆區', + '佳里鎮' => '佳里區', + '西港鄉' => '西港區', + '七股鄉' => '七股區', + '將軍鄉' => '將軍區', + '學甲鎮' => '學甲區', + '北門鄉' => '北門區', + '新營市' => '新營區', + '後壁鄉' => '後壁區', + '白河鎮' => '白河區', + '東山鄉' => '東山區', + '六甲鄉' => '六甲區', + '下營鄉' => '下營區', + '柳營鄉' => '柳營區', + '鹽水鎮' => '鹽水區', + '善化鎮' => '善化區', + '大內鄉' => '大內區', + '山上鄉' => '山上區', + '新市鄉' => '新市區', + '安定鄉' => '安定區', + '仁武鄉' => '仁武區', + '大社鄉' => '大社區', + '岡山鎮' => '岡山區', + '路竹鄉' => '路竹區', + '阿蓮鄉' => '阿蓮區', + '田寮鄉' => '田寮區', + '燕巢鄉' => '燕巢區', + '橋頭鄉' => '橋頭區', + '梓官鄉' => '梓官區', + '彌陀鄉' => '彌陀區', + '永安鄉' => '永安區', + '湖內鄉' => '湖內區', + '鳳山市' => '鳳山區', + '大寮鄉' => '大寮區', + '林園鄉' => '林園區', + '鳥松鄉' => '鳥松區', + '九曲堂' => '九曲區', + '大樹鄉' => '大樹區', + '旗山鎮' => '旗山區', + '美濃鎮' => '美濃區', + '六龜鄉' => '六龜區', + '內門鄉' => '內門區', + '杉林鄉' => '杉林區', + '甲仙鄉' => '甲仙區', + '桃源鄉' => '桃源區', + '那瑪夏鄉' => '那瑪夏區', + '茂林鄉' => '茂林區', + '茄萣鄉' => '茄萣區', + + '台西鄉' => '臺西鄉', + '霧台鄉' => '霧臺鄉', + '台東市' => '臺東市', + ]; + + return strtr($address, $newName); + } + + public function getZipcode() + { + return $this->zipcode; + } + + public function getCounty() + { + return $this->county; + } + + public function getDistrict() + { + return $this->district; + } + + public function getShortAddress() + { + return $this->shortAddress; + } + + public function getAddress() + { + return $this->address; + } +} diff --git a/src/twzipcode.json b/src/twzipcode.json new file mode 100644 index 0000000..4b7511e --- /dev/null +++ b/src/twzipcode.json @@ -0,0 +1,104 @@ + +{ + "基隆市": {"仁愛區": "200", "信義區": "201", "中正區": "202", "中山區": "203", "安樂區": "204", "暖暖區": "205", "七堵區": "206"}, + "台北市": {"中正區": "100", "大同區": "103", "中山區": "104", "松山區": "105", "大安區": "106", "萬華區": "108", "信義區": "110", "士林區": "111", "北投區": "112", "內湖區": "114", "南港區": "115", "文山區": "116"}, + "新北市": { + "萬里區": "207", "金山區": "208", "板橋區": "220", "汐止區": "221", "深坑區": "222", "石碇區": "223", + "瑞芳區": "224", "平溪區": "226", "雙溪區": "227", "貢寮區": "228", "新店區": "231", "坪林區": "232", + "烏來區": "233", "永和區": "234", "中和區": "235", "土城區": "236", "三峽區": "237", "樹林區": "238", + "鶯歌區": "239", "三重區": "241", "新莊區": "242", "泰山區": "243", "林口區": "244", "蘆洲區": "247", + "五股區": "248", "八里區": "249", "淡水區": "251", "三芝區": "252", "石門區": "253" + }, + "宜蘭縣": { + "宜蘭市": "260", "頭城鎮": "261", "礁溪鄉": "262", "壯圍鄉": "263", "員山鄉": "264", "羅東鎮": "265", + "三星鄉": "266", "大同鄉": "267", "五結鄉": "268", "冬山鄉": "269", "蘇澳鎮": "270", "南澳鄉": "272", + "釣魚台列嶼": "290" + }, + "新竹市": {"東區": "300", "北區": "300", "香山區": "300"}, + "新竹縣": { + "竹北市": "302", "湖口鄉": "303", "新豐鄉": "304", "新埔鎮": "305", "關西鎮": "306", "芎林鄉": "307", + "寶山鄉": "308", "竹東鎮": "310", "五峰鄉": "311", "橫山鄉": "312", "尖石鄉": "313", "北埔鄉": "314", + "峨嵋鄉": "315" + }, + "桃園縣": { + "中壢市": "320", "平鎮市": "324", "龍潭鄉": "325", "楊梅鎮": "326", "新屋鄉": "327", "觀音鄉": "328", + "桃園市": "330", "龜山鄉": "333", "八德市": "334", "大溪鎮": "335", "復興鄉": "336", "大園鄉": "337", + "蘆竹鄉": "338" + }, + "苗栗縣": { + "竹南鎮": "350", "頭份鎮": "351", "三灣鄉": "352", "南庄鄉": "353", "獅潭鄉": "354", "後龍鎮": "356", + "通霄鎮": "357", "苑裡鎮": "358", "苗栗市": "360", "造橋鄉": "361", "頭屋鄉": "362", "公館鄉": "363", + "大湖鄉": "364", "泰安鄉": "365", "銅鑼鄉": "366", "三義鄉": "367", "西湖鄉": "368", "卓蘭鎮": "369" + }, + "台中市": { + "中區": "400", "東區": "401", "南區": "402", "西區": "403", "北區": "404", "北屯區": "406", "西屯區": "407", "南屯區": "408", + "太平區": "411", "大里區": "412", "霧峰區": "413", "烏日區": "414", "豐原區": "420", "后里區": "421", + "石岡區": "422", "東勢區": "423", "和平區": "424", "新社區": "426", "潭子區": "427", "大雅區": "428", + "神岡區": "429", "大肚區": "432", "沙鹿區": "433", "龍井區": "434", "梧棲區": "435", "清水區": "436", + "大甲區": "437", "外埔區": "438", "大安區": "439" + }, + "彰化縣": { + "彰化市": "500", "芬園鄉": "502", "花壇鄉": "503", "秀水鄉": "504", "鹿港鎮": "505", "福興鄉": "506", + "線西鄉": "507", "和美鎮": "508", "伸港鄉": "509", "員林鎮": "510", "社頭鄉": "511", "永靖鄉": "512", + "埔心鄉": "513", "溪湖鎮": "514", "大村鄉": "515", "埔鹽鄉": "516", "田中鎮": "520", "北斗鎮": "521", + "田尾鄉": "522", "埤頭鄉": "523", "溪州鄉": "524", "竹塘鄉": "525", "二林鎮": "526", "大城鄉": "527", + "芳苑鄉": "528", "二水鄉": "530" + }, + "南投縣": { + "南投市": "540", "中寮鄉": "541", "草屯鎮": "542", "國姓鄉": "544", "埔里鎮": "545", "仁愛鄉": "546", + "名間鄉": "551", "集集鎮": "552", "水里鄉": "553", "魚池鄉": "555", "信義鄉": "556", "竹山鎮": "557", + "鹿谷鄉": "558" + }, + "嘉義市": {"東區": "600", "西區": "600"}, + "嘉義縣": { + "番路鄉": "602", "梅山鄉": "603", "竹崎鄉": "604", "阿里山": "605", "中埔鄉": "606", "大埔鄉": "607", + "水上鄉": "608", "鹿草鄉": "611", "太保市": "612", "朴子市": "613", "東石鄉": "614", "六腳鄉": "615", + "新港鄉": "616", "民雄鄉": "621", "大林鎮": "622", "溪口鄉": "623", "義竹鄉": "624", "布袋鎮": "625" + }, + "雲林縣": { + "斗南鎮": "630", "大埤鄉": "631", "虎尾鎮": "632", "土庫鎮": "633", "褒忠鄉": "634", "東勢鄉": "635", + "臺西鄉": "636", "崙背鄉": "637", "麥寮鄉": "638", "斗六市": "640", "林內鄉": "643", "古坑鄉": "646", + "莿桐鄉": "647", "西螺鎮": "648", "二崙鄉": "649", "北港鎮": "651", "水林鄉": "652", "口湖鄉": "653", + "四湖鄉": "654", "元長鄉": "655" + }, + "台南市": { + "中西區": "700", "東區": "701", "南區": "702", "北區": "704", "安平區": "708", "安南區": "709", + "永康區": "710", "歸仁區": "711", "新化區": "712", "左鎮區": "713", "玉井區": "714", "楠西區": "715", + "南化區": "716", "仁德區": "717", "關廟區": "718", "龍崎區": "719", "官田區": "720", "麻豆區": "721", + "佳里區": "722", "西港區": "723", "七股區": "724", "將軍區": "725", "學甲區": "726", "北門區": "727", + "新營區": "730", "後壁區": "731", "白河區": "732", "東山區": "733", "六甲區": "734", "下營區": "735", + "柳營區": "736", "鹽水區": "737", "善化區": "741", "大內區": "742", "山上區": "743", "新市區": "744", + "安定區": "745" + }, + "高雄市": { + "新興區": "800", "前金區": "801", "苓雅區": "802", "鹽埕區": "803", "鼓山區": "804", "旗津區": "805", + "前鎮區": "806", "三民區": "807", "楠梓區": "811", "小港區": "812", "左營區": "813", + "仁武區": "814", "大社區": "815", "岡山區": "820", "路竹區": "821", "阿蓮區": "822", "田寮鄉": "823", + "燕巢區": "824", "橋頭區": "825", "梓官區": "826", "彌陀區": "827", "永安區": "828", "湖內鄉": "829", + "鳳山區": "830", "大寮區": "831", "林園區": "832", "鳥松區": "833", "大樹區": "840", "旗山區": "842", + "美濃區": "843", "六龜區": "844", "內門區": "845", "杉林區": "846", "甲仙區": "847", "桃源區": "848", + "那瑪夏區": "849", "茂林區": "851", "茄萣區": "852" + }, + "屏東縣": { + "屏東市": "900", "三地門": "901", "霧臺鄉": "902", "瑪家鄉": "903", "九如鄉": "904", "里港鄉": "905", + "高樹鄉": "906", "鹽埔鄉": "907", "長治鄉": "908", "麟洛鄉": "909", "竹田鄉": "911", "內埔鄉": "912", + "萬丹鄉": "913", "潮州鎮": "920", "泰武鄉": "921", "來義鄉": "922", "萬巒鄉": "923", "崁頂鄉": "924", + "新埤鄉": "925", "南州鄉": "926", "林邊鄉": "927", "東港鎮": "928", "琉球鄉": "929", "佳冬鄉": "931", + "新園鄉": "932", "枋寮鄉": "940", "枋山鄉": "941", "春日鄉": "942", "獅子鄉": "943", "車城鄉": "944", + "牡丹鄉": "945", "恆春鎮": "946", "滿州鄉": "947" + }, + "台東縣": { + "臺東市": "950", "綠島鄉": "951", "蘭嶼鄉": "952", "延平鄉": "953", "卑南鄉": "954", "鹿野鄉": "955", + "關山鎮": "956", "海端鄉": "957", "池上鄉": "958", "東河鄉": "959", "成功鎮": "961", "長濱鄉": "962", + "太麻里鄉": "963", "金峰鄉": "964", "大武鄉": "965", "達仁鄉": "966" + }, + "花蓮縣": { + "花蓮市": "970", "新城鄉": "971", "秀林鄉": "972", "吉安鄉": "973", "壽豐鄉": "974", "鳳林鎮": "975", + "光復鄉": "976", "豐濱鄉": "977", "瑞穗鄉": "978", "萬榮鄉": "979", "玉里鎮": "981", "卓溪鄉": "982", + "富里鄉": "983" + }, + "金門縣": {"金沙鎮": "890", "金湖鎮": "891", "金寧鄉": "892", "金城鎮": "893", "烈嶼鄉": "894", "烏坵鄉": "896"}, + "連江縣": {"南竿鄉": "209", "北竿鄉": "210", "莒光鄉": "211", "東引鄉": "212"}, + "澎湖縣": {"馬公市": "880", "西嶼鄉": "881", "望安鄉": "882", "七美鄉": "883", "白沙鄉": "884", "湖西鄉": "885"}, + "南海諸島": {"東沙": "817", "南沙": "819"} +} diff --git a/tests/TwzipcodeTest.php b/tests/TwzipcodeTest.php new file mode 100644 index 0000000..64f1374 --- /dev/null +++ b/tests/TwzipcodeTest.php @@ -0,0 +1,42 @@ +assertSame($twzipcode->getZipcode(), '207'); + $this->assertSame($twzipcode->getCounty(), '新北市'); + $this->assertSame($twzipcode->getDistrict(), '萬里區'); + $this->assertSame($twzipcode->getAddress(), '新北市萬里區中正路100號'); + $this->assertSame($twzipcode->getShortAddress(), '中正路100號'); + } + + public function test_taichung() + { + $twzipcode = new Twzipcode('中縣 大里 市中正路100號'); + $this->assertSame($twzipcode->getZipcode(), '412'); + $this->assertSame($twzipcode->getCounty(), '台中市'); + $this->assertSame($twzipcode->getDistrict(), '大里區'); + $this->assertSame($twzipcode->getAddress(), '台中市大里區中正路100號'); + $this->assertSame($twzipcode->getShortAddress(), '中正路100號'); + } + + public function test_taitung() + { + $twzipcode = new Twzipcode('台東縣 台東 市中正路100號'); + $this->assertSame($twzipcode->getZipcode(), '950'); + $this->assertSame($twzipcode->getCounty(), '台東縣'); + $this->assertSame($twzipcode->getDistrict(), '臺東市'); + $this->assertSame($twzipcode->getAddress(), '台東縣臺東市中正路100號'); + $this->assertSame($twzipcode->getShortAddress(), '中正路100號'); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..2f769b6 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,28 @@ +