diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8567aab..a7f325c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ '7.1','7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php: [ '7.1','7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] stability: [ prefer-stable ] name: PHP ${{ matrix.php }} - ${{ matrix.stability }} diff --git a/composer.json b/composer.json index 8a27241..bf6420d 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,13 @@ { "name": "recca0120/twzipcode", "description": "twzipcode", - "keywords": ["twzipcode"], + "keywords": [ + "twzipcode" + ], "license": "MIT", "type": "library", "require": { - "php": ">=5.5.9", + "php": ">=7.1", "ext-zlib": "*", "recca0120/lodash": "^1.1" }, diff --git a/resources/converter.php b/resources/converter.php index 542523b..c4fb615 100644 --- a/resources/converter.php +++ b/resources/converter.php @@ -20,11 +20,11 @@ $contents = preg_replace("/^\xEF\xBB\xBF/", '', $contents); $contents = trim(str_replace('Zip5,City,Area,Road,Scope', '', $contents)); - $zip = new ZipArchive(); + $zip = new ZipArchive; $zip->open($file, ZipArchive::OVERWRITE); $zip->addFromString(pathinfo($file, PATHINFO_FILENAME).'.csv', $contents); $zip->close(); } -(new File())->loadFile($file); +(new File)->loadFile($file); echo 'benchmark: '.(microtime(true) - $start)."\n"; diff --git a/src/Address.php b/src/Address.php index b4934dd..7720179 100644 --- a/src/Address.php +++ b/src/Address.php @@ -6,73 +6,38 @@ class Address { - /** - * NO. - * - * @var int - */ - const NO = 0; + public const NO = 0; - /** - * SUBNO. - * - * @var int - */ - const SUBNO = 1; + public const SUBNO = 1; - /** - * NAME. - * - * @var int - */ - const NAME = 2; + public const NAME = 2; - /** - * UNIT. - * - * @var int - */ - const UNIT = 3; + public const UNIT = 3; - /** - * $normalizer. - * - * @var Normalizer - */ + /** @var Normalizer */ public $normalizer; - /** - * @var Tricky - */ + /** @var Tricky */ public $tricky; - /** - * $tokens. - * - * @var JArray - */ + /** @var JArray */ public $tokens = []; /** - * __construct. - * * @param static|array $address */ public function __construct($address = '') { - $this->tricky = new Tricky(); + $this->tricky = new Tricky; if (empty($address) === false) { $this->set($address); } } /** - * set. - * * @param static|string $address - * @return $this */ - public function set($address) + public function set($address): self { $this->normalizer = (new Normalizer($address))->normalize()->normalizeAddress(); $this->tokens = $this->tokenize(); @@ -80,12 +45,7 @@ public function set($address) return $this; } - /** - * tokenize. - * - * @return array - */ - private function tokenize() + private function tokenize(): array { $units = [static::NO => 'no', static::SUBNO => 'subno', static::NAME => 'name', static::UNIT => 'unit']; @@ -109,33 +69,17 @@ private function tokenize() return $tokens; } - /** - * __toString. - * - * @return string - */ public function __toString() { return $this->normalizer->value(); } - /** - * tokens. - * - * @return JArray - */ - public function tokens() + public function tokens(): JArray { return new JArray($this->tokens); } - /** - * getPoint. - * - * @param string $index - * @return Point - */ - public function getPoint($index) + public function getPoint(string $index): Point { if (isset($this->tokens[$index]) === false) { return new Point(0, 0); @@ -148,21 +92,16 @@ public function getPoint($index) ); } - /** - * flat. - * - * @param int $length - * @param int $offset - * @return string - */ - public function flat($length = null, $offset = 0) + public function flat(?int $length = null, int $offset = 0): string { $tokens = $this->tokens(); $length = $length ?: $tokens->length(); $end = $offset + $length; - return (string) $tokens->slice($offset, $end)->map(function ($token) { - return implode('', $token); - })->join(''); + return (string) $tokens->slice($offset, $end) + ->map(function ($token) { + return implode('', $token); + }) + ->join(''); } } diff --git a/src/Contracts/Storage.php b/src/Contracts/Storage.php index a2e3c4d..cab2208 100644 --- a/src/Contracts/Storage.php +++ b/src/Contracts/Storage.php @@ -6,41 +6,13 @@ interface Storage { - /** - * zip3. - * - * @return string - */ - public function zip3(Address $address); + public function zip3(Address $address): ?string; - /** - * rules. - * - * @param string $zip3 - * @return JString - */ - public function rules($zip3); + public function rules(string $zip3): array; - /** - * load. - * - * @param string $source - * @return $this - */ - public function load($source); + public function load(string $source): self; - /** - * loadFile. - * - * @param string $file - * @return $this - */ - public function loadFile($file = null); + public function loadFile(?string $file = null): self; - /** - * flush. - * - * @return $this - */ - public function flush(); + public function flush(): self; } diff --git a/src/Normalizer.php b/src/Normalizer.php index 9fdcd19..5b03931 100644 --- a/src/Normalizer.php +++ b/src/Normalizer.php @@ -6,12 +6,7 @@ class Normalizer extends JString { - /** - * normalizeAddress. - * - * @return static - */ - public function normalizeAddress() + public function normalizeAddress(): self { return $this ->replace([ @@ -48,34 +43,19 @@ public function normalizeAddress() ]); } - /** - * normalize. - * - * @return static - */ - public function normalize() + public function normalize(): self { return $this->trim()->regularize()->digitize(); } - /** - * digitize. - * - * @return static - */ - public function digitize() + public function digitize(): self { return $this->replace('/[一二三四五六七八九十百千]+(?=[段路街巷弄號樓])/u', function ($m) { return (new static($m[0]))->chineseToNumber(); }); } - /** - * regularize. - * - * @return static - */ - public function regularize() + public function regularize(): self { return $this ->toHalfCase() diff --git a/src/Point.php b/src/Point.php index 349e68a..c6c3573 100644 --- a/src/Point.php +++ b/src/Point.php @@ -4,49 +4,22 @@ class Point { - /** - * $x. - * - * @var int - */ public $x = 0; - /** - * $y. - * - * @var int - */ public $y = 0; - /** - * __construct. - * - * @param int $x - * @param int $y - */ - public function __construct($x = 0, $y = 0) + public function __construct(int $x = 0, int $y = 0) { $this->x = $x; $this->y = $y; } - /** - * empty. - * - * @return bool - */ - public function isEmpty() + public function isEmpty(): bool { return $this->x === 0 && $this->y === 0; } - /** - * compare. - * - * @param string $operator - * @return bool - */ - public function compare(self $point, $operator = '=') + public function compare(self $point, string $operator = '='): bool { $sum = $this->x * 10 + $this->y; $sum2 = $point->x * 10 + $point->y; diff --git a/src/Rule.php b/src/Rule.php index 39b42f5..aeff159 100644 --- a/src/Rule.php +++ b/src/Rule.php @@ -7,40 +7,19 @@ class Rule { - /** - * $zip3. - * - * @var string - */ - public $zip3; + /** @var string */ + private $zip3; - /** - * $zip5. - * - * @var string - */ - public $zip5; + /** @var string */ + private $zip5; - /** - * $address. - * - * @var Address - */ - public $address; + /** @var Address */ + private $address; - /** - * $tokens. - * - * @var array - */ - public $tokens; + /** @var array */ + private $tokens; - /** - * __construct. - * - * @param string $rule - */ - public function __construct($rule) + public function __construct(string $rule) { if (preg_match('/^(\d+),?(.*)/', $rule, $m)) { $this->zip5 = $m[1]; @@ -53,45 +32,27 @@ public function __construct($rule) }); } - /** - * zip5. - * - * @return string - */ - public function zip5() + public function zip5(): string { return $this->zip5; } - /** - * zip. - * - * @return string - */ - public function zip() + public function zip(): string { return $this->zip3(); } - /** - * zip3. - * - * @return string - */ - public function zip3() + public function zip3(): string { return $this->zip3; } /** - * match. - * * @param Address|string $address - * @return bool */ - public function match($address) + public function match($address): bool { - $ruleAddressTokens = $this->address->tokens(); + $ruleAddressTokens = $this->address()->tokens(); $address = $this->normalizeAddress( is_a($address, Address::class) === true ? $address : new Address($address), $ruleAddressTokens @@ -123,16 +84,16 @@ public function match($address) ($token === '以上' && $addressPoint->compare($left, '>=') === false) || ($token === '以下' && $addressPoint->compare($left, '<=') === false) || ($token === '至' && ( - ($right->compare($addressPoint, '<=') && $addressPoint->compare($left, '<=')) || - ($currentTokens->includes('含附號全') === true && ($addressPoint->x === $left->x)) - ) === false) || + ($right->compare($addressPoint, '<=') && $addressPoint->compare($left, '<=')) || + ($currentTokens->includes('含附號全') === true && ($addressPoint->x === $left->x)) + ) === false) || ($token === '含附號' && ($addressPoint->x === $left->x) === false) || ($token === '附號全' && ($addressPoint->x === $left->x && $addressPoint->y > 0) === false) || ($token === '及以上附號' && $addressPoint->compare($left, '>=') === false) || ($token === '含附號以下' && ( - $addressPoint->compare($left, '<=') || - $addressPoint->x === $left->x - ) === false) + $addressPoint->compare($left, '<=') || + $addressPoint->x === $left->x + ) === false) ) { return false; } @@ -141,23 +102,17 @@ public function match($address) return true; } - /** - * tokens. - * - * @return JArray - */ - public function tokens() + public function tokens(): JArray { return new JArray($this->tokens); } - /** - * tokenize. - * - * @param string $rule - * @return array - */ - private function tokenize($rule, Closure $addressResolver) + public function address(): Address + { + return $this->address; + } + + private function tokenize(string $rule, Closure $addressResolver): array { $tokens = []; @@ -168,27 +123,23 @@ private function tokenize($rule, Closure $addressResolver) '[連至單雙全](?=[\d全]|$)', ]; - $addressResolver($this->normalize($rule)->replace('/'.implode('|', $pattern).'/u', function ($m) use (&$tokens) { - $token = &$m[0]; - if ($token === '連') { - return ''; - } + $address = $this->normalize($rule) + ->replace('/'.implode('|', $pattern).'/u', function ($m) use (&$tokens) { + $token = &$m[0]; + if ($token === '連') { + return ''; + } - $tokens[] = $token; + $tokens[] = $token; - return $token === '附號全' ? '號' : ''; - })); + return $token === '附號全' ? '號' : ''; + }); + $addressResolver($address); return $tokens; } - /** - * normalize. - * - * @param string $rule - * @return Normalizer - */ - private function normalize($rule) + private function normalize(string $rule): Normalizer { $pattern = '((?P\d+)之)?\s*(?P\d+)至之?\s*(?P\d+)(?P\w)'; @@ -207,12 +158,7 @@ private function normalize($rule) }); } - /** - * normalizeAddress. - * - * @return Address - */ - private function normalizeAddress(Address $address, JArray $ruleAddressTokens) + private function normalizeAddress(Address $address, JArray $ruleAddressTokens): Address { $removeUnits = array_diff(['里', '鄰', '巷', '弄'], (array) $ruleAddressTokens->map(function ($token) { return isset($token[Address::UNIT]) === true ? $token[Address::UNIT] : ''; @@ -220,22 +166,15 @@ private function normalizeAddress(Address $address, JArray $ruleAddressTokens) return new Address( new JArray($address->tokens()->filter(function ($token) use ($removeUnits) { - return isset($token[Address::UNIT]) === true && in_array($token[Address::UNIT], $removeUnits, true) === false; + return isset($token[Address::UNIT]) === true && + in_array($token[Address::UNIT], $removeUnits, true) === false; })->map(function ($token) { return implode('', $token); })) ); } - /** - * equalsToken. - * - * @param JArray $ruleAddressTokens - * @param JArray $addressTokens - * @param int $cur - * @return bool - */ - private function equalsToken($ruleAddressTokens, $addressTokens, $cur) + private function equalsToken(JArray $ruleAddressTokens, JArray $addressTokens, int $cur): bool { if ($cur >= $addressTokens->length()) { return false; diff --git a/src/Rules.php b/src/Rules.php index c388146..81c9370 100644 --- a/src/Rules.php +++ b/src/Rules.php @@ -2,26 +2,18 @@ namespace Recca0120\Twzipcode; +use Recca0120\Lodash\JArray; use Recca0120\Twzipcode\Contracts\Storage; use Recca0120\Twzipcode\Storages\File; class Rules { - /** - * $storage. - * - * @var Storage - */ + /** @var Storage */ private $storage; - /** - * __construct. - * - * @param Storage $storage - */ - public function __construct(Storage $storage = null) + public function __construct(?Storage $storage = null) { - $this->storage = $storage ?: new File(); + $this->storage = $storage ?: new File; } /** @@ -39,7 +31,7 @@ public function match($address) return; } - $rule = $this->storage->rules($zip3)->find(function ($rule) use ($address) { + $rule = (new JArray($this->storage->rules($zip3)))->find(function (Rule $rule) use ($address) { return $rule->match($address); }); diff --git a/src/Storages/File.php b/src/Storages/File.php index 63e3c31..4270b91 100644 --- a/src/Storages/File.php +++ b/src/Storages/File.php @@ -11,84 +11,52 @@ class File implements Storage { - /** - * cached. - * - * @var array - */ - public static $cached = [ - 'zip3' => null, - 'zip5' => null, - ]; + public static $cached = ['zip3' => null, 'zip5' => null]; - /** - * $path. - * - * @var string - */ + /** @var string */ public $path; - /** - * $suffix. - * - * @var string - */ public $suffix = '.rules'; - /** - * __construct. - * - * @param string $path - */ - public function __construct($path = null) + public function __construct(?string $path = null) { - $this->path = ($path ?: dirname(dirname(__DIR__)).'/resources/data').'/'; + $this->path = ($path ?: dirname(__DIR__, 2).'/resources/data').'/'; } - /** - * zip3. - * - * @return JString - */ - public function zip3(Address $address) + public function zip3(Address $address): ?string { $this->restore('zip3'); foreach ([2, 1] as $value) { $flat = $address->flat($value); if (isset(self::$cached['zip3'][$flat])) { - $zip3 = self::$cached['zip3'][$flat]; - - return $zip3; + return self::$cached['zip3'][$flat]; } } return null; } - /** - * load. - * - * @param string $source - * @return $this - */ - public function load($source) + public function load(string $source): Storage { $zip5 = []; $zip3 = []; - $this->each($this->prepareSource($source), function ($zipcode, $county, $district, $rules) use (&$zip5, &$zip3) { - $zip5[$zipcode] = $this->compress(array_map(function ($rule) { - return new Rule($rule); - }, $rules)); - - if (isset($zip3[$county]) === false) { - $zip3[$county] = substr($zipcode, 0, 1); - } + $this->each($this->prepareSource($source), + function ($zipcode, $county, $district, $rules) use (&$zip5, &$zip3) { + $zip5[$zipcode] = $this->compress( + array_map(static function ($rule) { + return new Rule($rule); + }, $rules) + ); + + if (isset($zip3[$county]) === false) { + $zip3[$county] = substr($zipcode, 0, 1); + } - if (isset($zip3[$county.$district]) === false) { - $zip3[$county.$district] = substr($zipcode, 0, 3); - } - }); + if (isset($zip3[$county.$district]) === false) { + $zip3[$county.$district] = substr($zipcode, 0, 3); + } + }); $this->store('zip3', $zip3); $this->store('zip5', $zip5); @@ -96,28 +64,16 @@ public function load($source) return $this; } - /** - * rules. - * - * @param string $zip3 - * @return JArray - */ - public function rules($zip3) + public function rules(string $zip3): array { $this->restore('zip5'); return isset(self::$cached['zip5'][$zip3]) === true - ? new JArray($this->decompress(self::$cached['zip5'][$zip3])) - : new JArray([]); + ? $this->decompress(self::$cached['zip5'][$zip3]) + : []; } - /** - * loadFile. - * - * @param string $file - * @return $this - */ - public function loadFile($file = null) + public function loadFile(?string $file = null): Storage { $file = $file ?: $this->path.'../Zip32_utf8_10501_1.csv'; $this->load($this->getSource($file)); @@ -125,49 +81,29 @@ public function loadFile($file = null) return $this; } - /** - * flush. - * - * @return $this - */ - public function flush() + public function flush(): Storage { - static::$cached = [ - 'zip3' => null, - 'zip5' => null, - ]; + static::$cached = ['zip3' => null, 'zip5' => null]; return $this; } - /** - * restore. - * - * @param string $filename - * @return mixed - */ - private function restore($filename) + private function restore(string $filename): void { if (self::$cached[$filename] !== null) { - return self::$cached[$filename]; + return; } if (file_exists($this->path.$filename.$this->suffix) === false) { - return false; + return; } - return self::$cached[$filename] = new JArray($this->decompress( + self::$cached[$filename] = new JArray($this->decompress( file_get_contents($this->path.$filename.$this->suffix) )); } - /** - * getSource. - * - * @param string $file - * @return string - */ - private function getSource($file) + private function getSource(string $file): string { $extension = pathinfo($file, PATHINFO_EXTENSION); @@ -211,13 +147,7 @@ private function prepareSource($source) return $results; } - /** - * each. - * - * @param array $ruleGroup - * @param Closure $callback - */ - private function each($ruleGroup, $callback) + private function each(array $ruleGroup, Closure $callback): void { foreach ($ruleGroup as $county => $districts) { foreach ($districts as $district => $addresses) { @@ -230,40 +160,22 @@ private function each($ruleGroup, $callback) /** * compress. - * - * @param array $array - * @return string */ - private function compress($array) + private function compress(array $array): string { return gzcompress(serialize($array)); } /** * decompress. - * - * @param string $compressed - * @return array */ - private function decompress($compressed) + private function decompress(string $compressed): array { - return unserialize(gzuncompress($compressed)); + return unserialize(gzuncompress($compressed), ['max_depth' => 0]); } - /** - * store. - * - * @param string $filename - * @param JArray $data - * @return $this - */ - private function store($filename, $data) + private function store(string $filename, array $data): void { - file_put_contents( - $this->path.$filename.$this->suffix, - $this->compress($data) - ); - - return $this; + file_put_contents($this->path.$filename.$this->suffix, $this->compress($data)); } } diff --git a/src/Tricky.php b/src/Tricky.php index 59418eb..a817794 100644 --- a/src/Tricky.php +++ b/src/Tricky.php @@ -42,10 +42,7 @@ public function __construct() } } - /** - * @return void - */ - private function init() + private function init(): void { $tricky = ['島', '嶼', '鄉', '市', '鎮', '區', '村', '里', '路', '新市', '阿里山', '鎮興里平']; self::$cached['hash'] = array_reduce($tricky, static function ($acc, $unit) { @@ -71,20 +68,12 @@ private function init() ]; } - /** - * @param Normalizer $normalizer - * @return Normalizer - */ - public function hash($normalizer) + public function hash(Normalizer $normalizer): Normalizer { return $normalizer->replace(self::$cached['replace']); } - /** - * @param string $token - * @return string - */ - public function flip($token) + public function flip(string $token): string { return strtr($token, self::$cached['flip']); } diff --git a/src/Zipcode.php b/src/Zipcode.php index 40090c4..29a7ccc 100644 --- a/src/Zipcode.php +++ b/src/Zipcode.php @@ -18,22 +18,15 @@ class Zipcode 'shortAddress' => null, ]; - /** - * $address. - * - * @var Address - */ + /** @var Address */ private $address; /** * __construct. - * - * @param string $address - * @param Rules $rules */ - public function __construct($address, Rules $rules = null) + public function __construct(string $address, ?Rules $rules = null) { - $rules = $rules ?: new Rules(); + $rules = $rules ?: new Rules; $this->address = new Address($address); $zip = (string) $rules->match($this->address); @@ -55,72 +48,37 @@ public function __construct($address, Rules $rules = null) $this->attributes['address'] = $this->address->flat(); } - /** - * parse. - * - * @return static - */ - public static function parse($address, Rules $rules = null) + public static function parse($address, ?Rules $rules = null): self { return new static($address, $rules); } - /** - * zip3. - * - * @return string - */ - public function zip3() + public function zip3(): ?string { return $this->attributes['zip3']; } - /** - * zip5. - * - * @return string - */ - public function zip5() + public function zip5(): ?string { return $this->attributes['zip5']; } - /** - * county. - * - * @return string - */ - public function county() + public function county(): ?string { return $this->attributes['county']; } - /** - * district. - * - * @return string - */ - public function district() + public function district(): ?string { return $this->attributes['district']; } - /** - * address. - * - * @return string - */ - public function address() + public function address(): ?string { return $this->attributes['address']; } - /** - * shortAddress. - * - * @return string - */ - public function shortAddress() + public function shortAddress(): ?string { return $this->attributes['shortAddress']; } diff --git a/tests/Moskytw/AddressTest.php b/tests/Moskytw/AddressTest.php index a5941aa..79dad0e 100644 --- a/tests/Moskytw/AddressTest.php +++ b/tests/Moskytw/AddressTest.php @@ -9,19 +9,19 @@ class AddressTest extends TestCase { - public function test_address_init() + public function test_address_init(): void { $expected = [['', '', '臺北', '市'], ['', '', '大安', '區'], ['', '', '市府', '路'], ['1', '', '', '號']]; $this->assertSame($expected, (array) (new Address('臺北市大安區市府路1號'))->tokens()); } - public function test_address_init_sub_no() + public function test_address_init_sub_no(): void { $expected = [['', '', '臺北', '市'], ['', '', '大安', '區'], ['', '', '市府', '路'], ['1', '之1', '', '號']]; $this->assertSame($expected, (array) (new Address('臺北市大安區市府路1之1號'))->tokens()); } - public function test_address_init_tricky_input() + public function test_address_init_tricky_input(): void { $expected = [['', '', '桃園', '市'], ['', '', '中壢', '區'], ['', '', '普義', '']]; $this->assertSame($expected, (array) (new Address('桃園縣中壢市普義'))->tokens()); @@ -36,7 +36,7 @@ public function test_address_init_tricky_input() $this->assertSame($expected, (array) (new Address('臺北市中山區敬業1路10號'))->tokens()); } - public function test_address_init_normalization() + public function test_address_init_normalization(): void { $expected = [['', '', '臺北', '市'], ['', '', '大安', '區'], ['', '', '市府', '路'], ['1', '之1', '', '號']]; @@ -49,7 +49,7 @@ public function test_address_init_normalization() $this->assertSame($expected, (array) (new Address('臺北市, 大安區, 市府路 1 - 1 號'))->tokens()); } - public function test_address_init_normalization_chinese_number() + public function test_address_init_normalization_chinese_number(): void { $this->assertSame('八德路', (new Address('八德路'))->normalize()); $this->assertSame('三元街', (new Address('三元街'))->normalize()); @@ -67,7 +67,7 @@ public function test_address_init_normalization_chinese_number() $this->assertSame('愛富3街', (new Address('愛富三街'))->normalize()); } - public function test_address_flat() + public function test_address_flat(): void { $address = new Address('臺北市大安區市府路1之1號'); $this->assertSame('臺北市', $address->flat(1)); diff --git a/tests/Moskytw/DirectoryTest.php b/tests/Moskytw/DirectoryTest.php index 6f2280f..be5afcf 100644 --- a/tests/Moskytw/DirectoryTest.php +++ b/tests/Moskytw/DirectoryTest.php @@ -85,7 +85,7 @@ protected function setUp(): void '); } - public function test_find() + public function test_find(): void { // 10043,臺北市,中正區,中華路1段,單 25之 3號以下 $this->assertSame('10043', $this->directory->find('臺北市中正區中華路1段25號')); @@ -119,7 +119,7 @@ public function test_find() $this->assertSame('10042', $this->directory->find('臺北市中正區中華路1段53號')); } - public function test_find_gradually() + public function test_find_gradually(): void { $this->assertSame('1', $this->directory->find('臺北市')); $this->assertSame('100', $this->directory->find('臺北市中正區')); diff --git a/tests/Moskytw/RuleTest.php b/tests/Moskytw/RuleTest.php index 35e46fc..98082c3 100644 --- a/tests/Moskytw/RuleTest.php +++ b/tests/Moskytw/RuleTest.php @@ -13,62 +13,92 @@ class RuleTest extends TestCase public function test_rule_init() { $rule = new Rule('臺北市,中正區,八德路1段,全'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '八德', '路'], ['', '', '1', '段']], (array) $rule->tokens()); + $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '八德', '路'], ['', '', '1', '段']], + (array) $rule->tokens()); $this->assertSame(['全'], (array) $rule->ruleTokens()); $rule = new Rule('臺北市,中正區,三元街,單全'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '三元', '街']], (array) $rule->tokens()); + $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '三元', '街']], + (array) $rule->tokens()); $this->assertSame(['單', '全'], (array) $rule->ruleTokens()); $rule = new Rule('臺北市,中正區,三元街,雙 48號以下'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '三元', '街'], ['48', '', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '三元', '街'], ['48', '', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['雙', '以下'], (array) $rule->ruleTokens()); $rule = new Rule('臺北市,中正區,大埔街,單 15號以上'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '大埔', '街'], ['15', '', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '大埔', '街'], ['15', '', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['單', '以上'], (array) $rule->ruleTokens()); $rule = new Rule('臺北市,中正區,中華路1段,單 25之 3號以下'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '中華', '路'], ['', '', '1', '段'], ['25', '之3', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '中華', '路'], ['', '', '1', '段'], + ['25', '之3', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['單', '以下'], (array) $rule->ruleTokens()); $rule = new Rule('臺北市,中正區,中華路1段,單 27號至 47號'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '中華', '路'], ['', '', '1', '段'], ['27', '', '', '號'], ['47', '', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '中華', '路'], ['', '', '1', '段'], + ['27', '', '', '號'], ['47', '', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['單', '至'], (array) $rule->ruleTokens()); $rule = new Rule('臺北市,中正區,仁愛路1段,連 2之 4號以上'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '仁愛', '路'], ['', '', '1', '段'], ['2', '之4', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '仁愛', '路'], ['', '', '1', '段'], + ['2', '之4', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['以上'], (array) $rule->ruleTokens()); $rule = new Rule('臺北市,中正區,杭州南路1段,  14號含附號'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '杭州南', '路'], ['', '', '1', '段'], ['14', '', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '臺北', '市'], ['', '', '中正', '區'], ['', '', '杭州南', '路'], ['', '', '1', '段'], + ['14', '', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['含附號'], (array) $rule->ruleTokens()); $rule = new Rule('臺北市,大同區,哈密街,  47附號全'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '大同', '區'], ['', '', '哈密', '街'], ['47', '', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '臺北', '市'], ['', '', '大同', '區'], ['', '', '哈密', '街'], ['47', '', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['附號全'], (array) $rule->ruleTokens()); $rule = new Rule('臺北市,大同區,哈密街,雙 68巷至 70號含附號全'); - $this->assertSame([['', '', '臺北', '市'], ['', '', '大同', '區'], ['', '', '哈密', '街'], ['68', '', '', '巷'], ['70', '', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '臺北', '市'], ['', '', '大同', '區'], ['', '', '哈密', '街'], ['68', '', '', '巷'], + ['70', '', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['雙', '至', '含附號全'], (array) $rule->ruleTokens()); $rule = new Rule('桃園縣,中壢市,普義,連 49號含附號以下'); - $this->assertSame([['', '', '桃園', '市'], ['', '', '中壢', '區'], ['', '', '普義', ''], ['49', '', '', '號']], (array) $rule->tokens()); + $this->assertSame([['', '', '桃園', '市'], ['', '', '中壢', '區'], ['', '', '普義', ''], ['49', '', '', '號']], + (array) $rule->tokens()); $this->assertSame(['含附號以下'], (array) $rule->ruleTokens()); $rule = new Rule('臺中市,西屯區,西屯路3段西平南巷,  1之 3號及以上附號'); - $this->assertSame([['', '', '臺中', '市'], ['', '', '西屯', '區'], ['', '', '西屯', '路'], ['', '', '3', '段'], ['', '', '西平南', '巷'], ['1', '之3', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '臺中', '市'], ['', '', '西屯', '區'], ['', '', '西屯', '路'], ['', '', '3', '段'], + ['', '', '西平南', '巷'], ['1', '之3', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['及以上附號'], (array) $rule->ruleTokens()); } - public function test_rule_init_tricky_input() + public function test_rule_init_tricky_input(): void { $rule = new Rule('新北市,中和區,連城路,雙 268之 1號以下'); - $this->assertSame([['', '', '新北', '市'], ['', '', '中和', '區'], ['', '', '連城', '路'], ['268', '之1', '', '號']], (array) $rule->tokens()); + $this->assertSame([ + ['', '', '新北', '市'], ['', '', '中和', '區'], ['', '', '連城', '路'], ['268', '之1', '', '號'], + ], (array) $rule->tokens()); $this->assertSame(['雙', '以下'], (array) $rule->ruleTokens()); $rule = new Rule('新北市,泰山區,全興路,全'); - $this->assertSame([['', '', '新北', '市'], ['', '', '泰山', '區'], ['', '', '全興', '路']], (array) $rule->tokens()); + $this->assertSame([['', '', '新北', '市'], ['', '', '泰山', '區'], ['', '', '全興', '路']], + (array) $rule->tokens()); $this->assertSame(['全'], (array) $rule->ruleTokens()); } diff --git a/tests/Moskytw/stubs/Address.php b/tests/Moskytw/stubs/Address.php index 2dc55e8..654d36f 100644 --- a/tests/Moskytw/stubs/Address.php +++ b/tests/Moskytw/stubs/Address.php @@ -34,7 +34,7 @@ public function flat($length = null) $length = count($this->tokens) + $length; } - return implode('', array_map(function ($token) { + return implode('', array_map(static function ($token) { return implode('', $token); }, array_slice((array) $this->tokens, 0, $length))); } @@ -44,7 +44,7 @@ public function tokens() return $this->tokens; } - protected function getTokenPoint($index) + protected function getTokenPoint($index): array { $point = $this->address->getPoint($index); diff --git a/tests/Moskytw/stubs/Directory.php b/tests/Moskytw/stubs/Directory.php index 176f7de..a406a1a 100644 --- a/tests/Moskytw/stubs/Directory.php +++ b/tests/Moskytw/stubs/Directory.php @@ -8,6 +8,7 @@ class Directory { private $storage; + private $rules; public function __construct($root) @@ -16,19 +17,19 @@ public function __construct($root) $this->rules = new Rules($this->storage); } - public function __call($method, $argments) + public function __call($method, $arguments) { - return call_user_func_array([$this->rules, $method], $argments); + return call_user_func_array([$this->rules, $method], $arguments); } - public function load($source) + public function load($source): Directory { $this->storage->flush()->load($source); return $this; } - public function find($address) + public function find($address): ?string { return $this->rules->match($address); } diff --git a/tests/Moskytw/stubs/Rule.php b/tests/Moskytw/stubs/Rule.php index 48237c3..ad54107 100644 --- a/tests/Moskytw/stubs/Rule.php +++ b/tests/Moskytw/stubs/Rule.php @@ -2,6 +2,7 @@ namespace Moskytw; +use Recca0120\Lodash\JArray; use Recca0120\Twzipcode\Rule as BaseRule; class Rule @@ -13,17 +14,17 @@ public function __construct($rule) $this->rule = new BaseRule($rule); } - public function ruleTokens() + public function ruleTokens(): JArray { return $this->rule->tokens(); } - public function tokens() + public function tokens(): JArray { return $this->rule->address->tokens(); } - public function match(Address $address) + public function match(Address $address): bool { return $this->rule->match((string) $address); } diff --git a/tests/RulesTest.php b/tests/RulesTest.php index 1647f7f..86d5899 100644 --- a/tests/RulesTest.php +++ b/tests/RulesTest.php @@ -125,396 +125,396 @@ public function testMatchGradually() $this->assertSame('10051', $this->rules->match('臺北市中正區仁愛路1段1號')); } - public function testZip3North() + public function testZip3North(): void { File::$cached = ['zip3' => null, 'zip5' => null]; - $rules = new Rules(); - $this->assertSame('100', $rules->match('台北市中正區'.uniqid())); - $this->assertSame('103', $rules->match('台北市大同區'.uniqid())); - $this->assertSame('104', $rules->match('台北市中山區'.uniqid())); - $this->assertSame('105', $rules->match('台北市松山區'.uniqid())); - $this->assertSame('106', $rules->match('台北市大安區'.uniqid())); - $this->assertSame('108', $rules->match('台北市萬華區'.uniqid())); - $this->assertSame('110', $rules->match('台北市信義區'.uniqid())); - $this->assertSame('111', $rules->match('台北市士林區'.uniqid())); - $this->assertSame('112', $rules->match('台北市北投區'.uniqid())); - $this->assertSame('114', $rules->match('台北市內湖區'.uniqid())); - $this->assertSame('115', $rules->match('台北市南港區'.uniqid())); - $this->assertSame('116', $rules->match('台北市文山區'.uniqid())); + $rules = new Rules; + $this->assertSame('100', $rules->match('台北市中正區'.uniqid('', true))); + $this->assertSame('103', $rules->match('台北市大同區'.uniqid('', true))); + $this->assertSame('104', $rules->match('台北市中山區'.uniqid('', true))); + $this->assertSame('105', $rules->match('台北市松山區'.uniqid('', true))); + $this->assertSame('106', $rules->match('台北市大安區'.uniqid('', true))); + $this->assertSame('108', $rules->match('台北市萬華區'.uniqid('', true))); + $this->assertSame('110', $rules->match('台北市信義區'.uniqid('', true))); + $this->assertSame('111', $rules->match('台北市士林區'.uniqid('', true))); + $this->assertSame('112', $rules->match('台北市北投區'.uniqid('', true))); + $this->assertSame('114', $rules->match('台北市內湖區'.uniqid('', true))); + $this->assertSame('115', $rules->match('台北市南港區'.uniqid('', true))); + $this->assertSame('116', $rules->match('台北市文山區'.uniqid('', true))); - $this->assertSame('207', $rules->match('新北市萬里區'.uniqid())); - $this->assertSame('208', $rules->match('新北市金山區'.uniqid())); - $this->assertSame('220', $rules->match('新北市板橋區'.uniqid())); - $this->assertSame('221', $rules->match('新北市汐止區'.uniqid())); - $this->assertSame('222', $rules->match('新北市深坑區'.uniqid())); - // $this->assertSame('223', $rules->match('新北市石碇區'.uniqid())); - $this->assertSame('224', $rules->match('新北市瑞芳區'.uniqid())); - $this->assertSame('226', $rules->match('新北市平溪區'.uniqid())); - $this->assertSame('227', $rules->match('新北市雙溪區'.uniqid())); - $this->assertSame('228', $rules->match('新北市貢寮區'.uniqid())); - $this->assertSame('231', $rules->match('新北市新店區'.uniqid())); - $this->assertSame('232', $rules->match('新北市坪林區'.uniqid())); - $this->assertSame('233', $rules->match('新北市烏來區'.uniqid())); - $this->assertSame('234', $rules->match('新北市永和區'.uniqid())); - $this->assertSame('235', $rules->match('新北市中和區'.uniqid())); - $this->assertSame('236', $rules->match('新北市土城區'.uniqid())); - $this->assertSame('237', $rules->match('新北市三峽區'.uniqid())); - $this->assertSame('238', $rules->match('新北市樹林區'.uniqid())); - $this->assertSame('239', $rules->match('新北市鶯歌區'.uniqid())); - $this->assertSame('241', $rules->match('新北市三重區'.uniqid())); - $this->assertSame('242', $rules->match('新北市新莊區'.uniqid())); - $this->assertSame('243', $rules->match('新北市泰山區'.uniqid())); - $this->assertSame('244', $rules->match('新北市林口區'.uniqid())); - $this->assertSame('247', $rules->match('新北市蘆洲區'.uniqid())); - $this->assertSame('248', $rules->match('新北市五股區'.uniqid())); - $this->assertSame('249', $rules->match('新北市八里區'.uniqid())); - $this->assertSame('251', $rules->match('新北市淡水區'.uniqid())); - $this->assertSame('252', $rules->match('新北市三芝區'.uniqid())); - $this->assertSame('253', $rules->match('新北市石門區'.uniqid())); + $this->assertSame('207', $rules->match('新北市萬里區'.uniqid('', true))); + $this->assertSame('208', $rules->match('新北市金山區'.uniqid('', true))); + $this->assertSame('220', $rules->match('新北市板橋區'.uniqid('', true))); + $this->assertSame('221', $rules->match('新北市汐止區'.uniqid('', true))); + $this->assertSame('222', $rules->match('新北市深坑區'.uniqid('', true))); + // $this->assertSame('223', $rules->match('新北市石碇區'.uniqid('', true))); + $this->assertSame('224', $rules->match('新北市瑞芳區'.uniqid('', true))); + $this->assertSame('226', $rules->match('新北市平溪區'.uniqid('', true))); + $this->assertSame('227', $rules->match('新北市雙溪區'.uniqid('', true))); + $this->assertSame('228', $rules->match('新北市貢寮區'.uniqid('', true))); + $this->assertSame('231', $rules->match('新北市新店區'.uniqid('', true))); + $this->assertSame('232', $rules->match('新北市坪林區'.uniqid('', true))); + $this->assertSame('233', $rules->match('新北市烏來區'.uniqid('', true))); + $this->assertSame('234', $rules->match('新北市永和區'.uniqid('', true))); + $this->assertSame('235', $rules->match('新北市中和區'.uniqid('', true))); + $this->assertSame('236', $rules->match('新北市土城區'.uniqid('', true))); + $this->assertSame('237', $rules->match('新北市三峽區'.uniqid('', true))); + $this->assertSame('238', $rules->match('新北市樹林區'.uniqid('', true))); + $this->assertSame('239', $rules->match('新北市鶯歌區'.uniqid('', true))); + $this->assertSame('241', $rules->match('新北市三重區'.uniqid('', true))); + $this->assertSame('242', $rules->match('新北市新莊區'.uniqid('', true))); + $this->assertSame('243', $rules->match('新北市泰山區'.uniqid('', true))); + $this->assertSame('244', $rules->match('新北市林口區'.uniqid('', true))); + $this->assertSame('247', $rules->match('新北市蘆洲區'.uniqid('', true))); + $this->assertSame('248', $rules->match('新北市五股區'.uniqid('', true))); + $this->assertSame('249', $rules->match('新北市八里區'.uniqid('', true))); + $this->assertSame('251', $rules->match('新北市淡水區'.uniqid('', true))); + $this->assertSame('252', $rules->match('新北市三芝區'.uniqid('', true))); + $this->assertSame('253', $rules->match('新北市石門區'.uniqid('', true))); - $this->assertSame('200', $rules->match('基隆市仁愛區'.uniqid())); - $this->assertSame('201', $rules->match('基隆市信義區'.uniqid())); - $this->assertSame('202', $rules->match('基隆市中正區'.uniqid())); - $this->assertSame('203', $rules->match('基隆市中山區'.uniqid())); - $this->assertSame('204', $rules->match('基隆市安樂區'.uniqid())); - $this->assertSame('205', $rules->match('基隆市暖暖區'.uniqid())); - $this->assertSame('206', $rules->match('基隆市七堵區'.uniqid())); + $this->assertSame('200', $rules->match('基隆市仁愛區'.uniqid('', true))); + $this->assertSame('201', $rules->match('基隆市信義區'.uniqid('', true))); + $this->assertSame('202', $rules->match('基隆市中正區'.uniqid('', true))); + $this->assertSame('203', $rules->match('基隆市中山區'.uniqid('', true))); + $this->assertSame('204', $rules->match('基隆市安樂區'.uniqid('', true))); + $this->assertSame('205', $rules->match('基隆市暖暖區'.uniqid('', true))); + $this->assertSame('206', $rules->match('基隆市七堵區'.uniqid('', true))); - $this->assertSame('320', $rules->match('桃園市中壢區'.uniqid())); - $this->assertSame('324', $rules->match('桃園市平鎮區'.uniqid())); - $this->assertSame('325', $rules->match('桃園市龍潭區'.uniqid())); - $this->assertSame('326', $rules->match('桃園市楊梅區'.uniqid())); - $this->assertSame('327', $rules->match('桃園市新屋區'.uniqid())); - $this->assertSame('328', $rules->match('桃園市觀音區'.uniqid())); - $this->assertSame('330', $rules->match('桃園市桃園區'.uniqid())); - $this->assertSame('333', $rules->match('桃園市龜山區'.uniqid())); - $this->assertSame('334', $rules->match('桃園市八德區'.uniqid())); - $this->assertSame('335', $rules->match('桃園市大溪區'.uniqid())); - $this->assertSame('336', $rules->match('桃園市復興區'.uniqid())); - $this->assertSame('337', $rules->match('桃園市大園區'.uniqid())); - $this->assertSame('338', $rules->match('桃園市蘆竹區'.uniqid())); + $this->assertSame('320', $rules->match('桃園市中壢區'.uniqid('', true))); + $this->assertSame('324', $rules->match('桃園市平鎮區'.uniqid('', true))); + $this->assertSame('325', $rules->match('桃園市龍潭區'.uniqid('', true))); + $this->assertSame('326', $rules->match('桃園市楊梅區'.uniqid('', true))); + $this->assertSame('327', $rules->match('桃園市新屋區'.uniqid('', true))); + $this->assertSame('328', $rules->match('桃園市觀音區'.uniqid('', true))); + $this->assertSame('330', $rules->match('桃園市桃園區'.uniqid('', true))); + $this->assertSame('333', $rules->match('桃園市龜山區'.uniqid('', true))); + $this->assertSame('334', $rules->match('桃園市八德區'.uniqid('', true))); + $this->assertSame('335', $rules->match('桃園市大溪區'.uniqid('', true))); + $this->assertSame('336', $rules->match('桃園市復興區'.uniqid('', true))); + $this->assertSame('337', $rules->match('桃園市大園區'.uniqid('', true))); + $this->assertSame('338', $rules->match('桃園市蘆竹區'.uniqid('', true))); - $this->assertSame('3', $rules->match('新竹市'.uniqid())); - $this->assertSame('302', $rules->match('新竹縣竹北市'.uniqid())); - $this->assertSame('303', $rules->match('新竹縣湖口鄉'.uniqid())); - $this->assertSame('304', $rules->match('新竹縣新豐鄉'.uniqid())); - $this->assertSame('305', $rules->match('新竹縣新埔鎮'.uniqid())); - $this->assertSame('306', $rules->match('新竹縣關西鎮'.uniqid())); - $this->assertSame('307', $rules->match('新竹縣芎林鄉'.uniqid())); - $this->assertSame('308', $rules->match('新竹縣寶山鄉'.uniqid())); - $this->assertSame('310', $rules->match('新竹縣竹東鎮'.uniqid())); - $this->assertSame('311', $rules->match('新竹縣五峰鄉'.uniqid())); - $this->assertSame('312', $rules->match('新竹縣橫山鄉'.uniqid())); - $this->assertSame('313', $rules->match('新竹縣尖石鄉'.uniqid())); - $this->assertSame('314', $rules->match('新竹縣北埔鄉'.uniqid())); - $this->assertSame('315', $rules->match('新竹縣峨眉鄉'.uniqid())); + $this->assertSame('3', $rules->match('新竹市'.uniqid('', true))); + $this->assertSame('302', $rules->match('新竹縣竹北市'.uniqid('', true))); + $this->assertSame('303', $rules->match('新竹縣湖口鄉'.uniqid('', true))); + $this->assertSame('304', $rules->match('新竹縣新豐鄉'.uniqid('', true))); + $this->assertSame('305', $rules->match('新竹縣新埔鎮'.uniqid('', true))); + $this->assertSame('306', $rules->match('新竹縣關西鎮'.uniqid('', true))); + $this->assertSame('307', $rules->match('新竹縣芎林鄉'.uniqid('', true))); + $this->assertSame('308', $rules->match('新竹縣寶山鄉'.uniqid('', true))); + $this->assertSame('310', $rules->match('新竹縣竹東鎮'.uniqid('', true))); + $this->assertSame('311', $rules->match('新竹縣五峰鄉'.uniqid('', true))); + $this->assertSame('312', $rules->match('新竹縣橫山鄉'.uniqid('', true))); + $this->assertSame('313', $rules->match('新竹縣尖石鄉'.uniqid('', true))); + $this->assertSame('314', $rules->match('新竹縣北埔鄉'.uniqid('', true))); + $this->assertSame('315', $rules->match('新竹縣峨眉鄉'.uniqid('', true))); - $this->assertSame('350', $rules->match('苗栗縣竹南鎮'.uniqid())); - $this->assertSame('351', $rules->match('苗栗縣頭份鎮'.uniqid())); - $this->assertSame('352', $rules->match('苗栗縣三灣鄉'.uniqid())); - $this->assertSame('353', $rules->match('苗栗縣南庄鄉'.uniqid())); - $this->assertSame('354', $rules->match('苗栗縣獅潭鄉'.uniqid())); - $this->assertSame('356', $rules->match('苗栗縣後龍鎮'.uniqid())); - $this->assertSame('357', $rules->match('苗栗縣通霄鎮'.uniqid())); - $this->assertSame('358', $rules->match('苗栗縣苑裡鎮'.uniqid())); - $this->assertSame('360', $rules->match('苗栗縣苗栗市'.uniqid())); - $this->assertSame('361', $rules->match('苗栗縣造橋鄉'.uniqid())); - $this->assertSame('362', $rules->match('苗栗縣頭屋鄉'.uniqid())); - $this->assertSame('363', $rules->match('苗栗縣公館鄉'.uniqid())); - $this->assertSame('364', $rules->match('苗栗縣大湖鄉'.uniqid())); - $this->assertSame('365', $rules->match('苗栗縣泰安鄉'.uniqid())); - $this->assertSame('366', $rules->match('苗栗縣銅鑼鄉'.uniqid())); - $this->assertSame('367', $rules->match('苗栗縣三義鄉'.uniqid())); - $this->assertSame('368', $rules->match('苗栗縣西湖鄉'.uniqid())); - $this->assertSame('369', $rules->match('苗栗縣卓蘭鎮'.uniqid())); + $this->assertSame('350', $rules->match('苗栗縣竹南鎮'.uniqid('', true))); + $this->assertSame('351', $rules->match('苗栗縣頭份鎮'.uniqid('', true))); + $this->assertSame('352', $rules->match('苗栗縣三灣鄉'.uniqid('', true))); + $this->assertSame('353', $rules->match('苗栗縣南庄鄉'.uniqid('', true))); + $this->assertSame('354', $rules->match('苗栗縣獅潭鄉'.uniqid('', true))); + $this->assertSame('356', $rules->match('苗栗縣後龍鎮'.uniqid('', true))); + $this->assertSame('357', $rules->match('苗栗縣通霄鎮'.uniqid('', true))); + $this->assertSame('358', $rules->match('苗栗縣苑裡鎮'.uniqid('', true))); + $this->assertSame('360', $rules->match('苗栗縣苗栗市'.uniqid('', true))); + $this->assertSame('361', $rules->match('苗栗縣造橋鄉'.uniqid('', true))); + $this->assertSame('362', $rules->match('苗栗縣頭屋鄉'.uniqid('', true))); + $this->assertSame('363', $rules->match('苗栗縣公館鄉'.uniqid('', true))); + $this->assertSame('364', $rules->match('苗栗縣大湖鄉'.uniqid('', true))); + $this->assertSame('365', $rules->match('苗栗縣泰安鄉'.uniqid('', true))); + $this->assertSame('366', $rules->match('苗栗縣銅鑼鄉'.uniqid('', true))); + $this->assertSame('367', $rules->match('苗栗縣三義鄉'.uniqid('', true))); + $this->assertSame('368', $rules->match('苗栗縣西湖鄉'.uniqid('', true))); + $this->assertSame('369', $rules->match('苗栗縣卓蘭鎮'.uniqid('', true))); - $this->assertSame('400', $rules->match('台中市中 區'.uniqid())); - $this->assertSame('401', $rules->match('台中市東 區'.uniqid())); - $this->assertSame('402', $rules->match('台中市南 區'.uniqid())); - $this->assertSame('403', $rules->match('台中市西 區'.uniqid())); - $this->assertSame('404', $rules->match('台中市北 區'.uniqid())); - $this->assertSame('406', $rules->match('台中市北屯區'.uniqid())); - $this->assertSame('407', $rules->match('台中市西屯區'.uniqid())); - $this->assertSame('408', $rules->match('台中市南屯區'.uniqid())); - $this->assertSame('411', $rules->match('台中市太平區'.uniqid())); - $this->assertSame('412', $rules->match('台中市大里區'.uniqid())); - $this->assertSame('413', $rules->match('台中市霧峰區'.uniqid())); - $this->assertSame('414', $rules->match('台中市烏日區'.uniqid())); - $this->assertSame('420', $rules->match('台中市豐原區'.uniqid())); - $this->assertSame('421', $rules->match('台中市后里區'.uniqid())); - $this->assertSame('422', $rules->match('台中市石岡區'.uniqid())); - $this->assertSame('423', $rules->match('台中市東勢區'.uniqid())); - $this->assertSame('424', $rules->match('台中市和平區'.uniqid())); - $this->assertSame('426', $rules->match('台中市新社區'.uniqid())); - $this->assertSame('427', $rules->match('台中市潭子區'.uniqid())); - $this->assertSame('428', $rules->match('台中市大雅區'.uniqid())); - $this->assertSame('429', $rules->match('台中市神岡區'.uniqid())); - $this->assertSame('432', $rules->match('台中市大肚區'.uniqid())); - $this->assertSame('433', $rules->match('台中市沙鹿區'.uniqid())); - $this->assertSame('434', $rules->match('台中市龍井區'.uniqid())); - $this->assertSame('435', $rules->match('台中市梧棲區'.uniqid())); - $this->assertSame('436', $rules->match('台中市清水區'.uniqid())); - $this->assertSame('437', $rules->match('台中市大甲區'.uniqid())); - $this->assertSame('438', $rules->match('台中市外埔區'.uniqid())); - $this->assertSame('439', $rules->match('台中市大安區'.uniqid())); + $this->assertSame('400', $rules->match('台中市中 區'.uniqid('', true))); + $this->assertSame('401', $rules->match('台中市東 區'.uniqid('', true))); + $this->assertSame('402', $rules->match('台中市南 區'.uniqid('', true))); + $this->assertSame('403', $rules->match('台中市西 區'.uniqid('', true))); + $this->assertSame('404', $rules->match('台中市北 區'.uniqid('', true))); + $this->assertSame('406', $rules->match('台中市北屯區'.uniqid('', true))); + $this->assertSame('407', $rules->match('台中市西屯區'.uniqid('', true))); + $this->assertSame('408', $rules->match('台中市南屯區'.uniqid('', true))); + $this->assertSame('411', $rules->match('台中市太平區'.uniqid('', true))); + $this->assertSame('412', $rules->match('台中市大里區'.uniqid('', true))); + $this->assertSame('413', $rules->match('台中市霧峰區'.uniqid('', true))); + $this->assertSame('414', $rules->match('台中市烏日區'.uniqid('', true))); + $this->assertSame('420', $rules->match('台中市豐原區'.uniqid('', true))); + $this->assertSame('421', $rules->match('台中市后里區'.uniqid('', true))); + $this->assertSame('422', $rules->match('台中市石岡區'.uniqid('', true))); + $this->assertSame('423', $rules->match('台中市東勢區'.uniqid('', true))); + $this->assertSame('424', $rules->match('台中市和平區'.uniqid('', true))); + $this->assertSame('426', $rules->match('台中市新社區'.uniqid('', true))); + $this->assertSame('427', $rules->match('台中市潭子區'.uniqid('', true))); + $this->assertSame('428', $rules->match('台中市大雅區'.uniqid('', true))); + $this->assertSame('429', $rules->match('台中市神岡區'.uniqid('', true))); + $this->assertSame('432', $rules->match('台中市大肚區'.uniqid('', true))); + $this->assertSame('433', $rules->match('台中市沙鹿區'.uniqid('', true))); + $this->assertSame('434', $rules->match('台中市龍井區'.uniqid('', true))); + $this->assertSame('435', $rules->match('台中市梧棲區'.uniqid('', true))); + $this->assertSame('436', $rules->match('台中市清水區'.uniqid('', true))); + $this->assertSame('437', $rules->match('台中市大甲區'.uniqid('', true))); + $this->assertSame('438', $rules->match('台中市外埔區'.uniqid('', true))); + $this->assertSame('439', $rules->match('台中市大安區'.uniqid('', true))); - $this->assertSame('500', $rules->match('彰化縣彰化市'.uniqid())); - $this->assertSame('502', $rules->match('彰化縣芬園鄉'.uniqid())); - $this->assertSame('503', $rules->match('彰化縣花壇鄉'.uniqid())); - $this->assertSame('504', $rules->match('彰化縣秀水鄉'.uniqid())); - $this->assertSame('505', $rules->match('彰化縣鹿港鎮'.uniqid())); - $this->assertSame('506', $rules->match('彰化縣福興鄉'.uniqid())); - $this->assertSame('507', $rules->match('彰化縣線西鄉'.uniqid())); - $this->assertSame('508', $rules->match('彰化縣和美鎮'.uniqid())); - $this->assertSame('509', $rules->match('彰化縣伸港鄉'.uniqid())); - $this->assertSame('510', $rules->match('彰化縣員林鎮'.uniqid())); - $this->assertSame('511', $rules->match('彰化縣社頭鄉'.uniqid())); - $this->assertSame('512', $rules->match('彰化縣永靖鄉'.uniqid())); - $this->assertSame('513', $rules->match('彰化縣埔心鄉'.uniqid())); - $this->assertSame('514', $rules->match('彰化縣溪湖鎮'.uniqid())); - $this->assertSame('515', $rules->match('彰化縣大村鄉'.uniqid())); - $this->assertSame('516', $rules->match('彰化縣埔鹽鄉'.uniqid())); - $this->assertSame('520', $rules->match('彰化縣田中鎮'.uniqid())); - $this->assertSame('521', $rules->match('彰化縣北斗鎮'.uniqid())); - $this->assertSame('522', $rules->match('彰化縣田尾鄉'.uniqid())); - $this->assertSame('523', $rules->match('彰化縣埤頭鄉'.uniqid())); - $this->assertSame('524', $rules->match('彰化縣溪州鄉'.uniqid())); - $this->assertSame('525', $rules->match('彰化縣竹塘鄉'.uniqid())); - $this->assertSame('526', $rules->match('彰化縣二林鎮'.uniqid())); - $this->assertSame('527', $rules->match('彰化縣大城鄉'.uniqid())); - $this->assertSame('528', $rules->match('彰化縣芳苑鄉'.uniqid())); - $this->assertSame('530', $rules->match('彰化縣二水鄉'.uniqid())); + $this->assertSame('500', $rules->match('彰化縣彰化市'.uniqid('', true))); + $this->assertSame('502', $rules->match('彰化縣芬園鄉'.uniqid('', true))); + $this->assertSame('503', $rules->match('彰化縣花壇鄉'.uniqid('', true))); + $this->assertSame('504', $rules->match('彰化縣秀水鄉'.uniqid('', true))); + $this->assertSame('505', $rules->match('彰化縣鹿港鎮'.uniqid('', true))); + $this->assertSame('506', $rules->match('彰化縣福興鄉'.uniqid('', true))); + $this->assertSame('507', $rules->match('彰化縣線西鄉'.uniqid('', true))); + $this->assertSame('508', $rules->match('彰化縣和美鎮'.uniqid('', true))); + $this->assertSame('509', $rules->match('彰化縣伸港鄉'.uniqid('', true))); + $this->assertSame('510', $rules->match('彰化縣員林鎮'.uniqid('', true))); + $this->assertSame('511', $rules->match('彰化縣社頭鄉'.uniqid('', true))); + $this->assertSame('512', $rules->match('彰化縣永靖鄉'.uniqid('', true))); + $this->assertSame('513', $rules->match('彰化縣埔心鄉'.uniqid('', true))); + $this->assertSame('514', $rules->match('彰化縣溪湖鎮'.uniqid('', true))); + $this->assertSame('515', $rules->match('彰化縣大村鄉'.uniqid('', true))); + $this->assertSame('516', $rules->match('彰化縣埔鹽鄉'.uniqid('', true))); + $this->assertSame('520', $rules->match('彰化縣田中鎮'.uniqid('', true))); + $this->assertSame('521', $rules->match('彰化縣北斗鎮'.uniqid('', true))); + $this->assertSame('522', $rules->match('彰化縣田尾鄉'.uniqid('', true))); + $this->assertSame('523', $rules->match('彰化縣埤頭鄉'.uniqid('', true))); + $this->assertSame('524', $rules->match('彰化縣溪州鄉'.uniqid('', true))); + $this->assertSame('525', $rules->match('彰化縣竹塘鄉'.uniqid('', true))); + $this->assertSame('526', $rules->match('彰化縣二林鎮'.uniqid('', true))); + $this->assertSame('527', $rules->match('彰化縣大城鄉'.uniqid('', true))); + $this->assertSame('528', $rules->match('彰化縣芳苑鄉'.uniqid('', true))); + $this->assertSame('530', $rules->match('彰化縣二水鄉'.uniqid('', true))); - $this->assertSame('540', $rules->match('南投縣南投市'.uniqid())); - $this->assertSame('541', $rules->match('南投縣中寮鄉'.uniqid())); - $this->assertSame('542', $rules->match('南投縣草屯鎮'.uniqid())); - $this->assertSame('544', $rules->match('南投縣國姓鄉'.uniqid())); - $this->assertSame('545', $rules->match('南投縣埔里鎮'.uniqid())); - $this->assertSame('546', $rules->match('南投縣仁愛鄉'.uniqid())); - $this->assertSame('551', $rules->match('南投縣名間鄉'.uniqid())); - $this->assertSame('552', $rules->match('南投縣集集鎮'.uniqid())); - $this->assertSame('553', $rules->match('南投縣水里鄉'.uniqid())); - $this->assertSame('555', $rules->match('南投縣魚池鄉'.uniqid())); - $this->assertSame('556', $rules->match('南投縣信義鄉'.uniqid())); - $this->assertSame('557', $rules->match('南投縣竹山鎮'.uniqid())); - $this->assertSame('558', $rules->match('南投縣鹿谷鄉'.uniqid())); + $this->assertSame('540', $rules->match('南投縣南投市'.uniqid('', true))); + $this->assertSame('541', $rules->match('南投縣中寮鄉'.uniqid('', true))); + $this->assertSame('542', $rules->match('南投縣草屯鎮'.uniqid('', true))); + $this->assertSame('544', $rules->match('南投縣國姓鄉'.uniqid('', true))); + $this->assertSame('545', $rules->match('南投縣埔里鎮'.uniqid('', true))); + $this->assertSame('546', $rules->match('南投縣仁愛鄉'.uniqid('', true))); + $this->assertSame('551', $rules->match('南投縣名間鄉'.uniqid('', true))); + $this->assertSame('552', $rules->match('南投縣集集鎮'.uniqid('', true))); + $this->assertSame('553', $rules->match('南投縣水里鄉'.uniqid('', true))); + $this->assertSame('555', $rules->match('南投縣魚池鄉'.uniqid('', true))); + $this->assertSame('556', $rules->match('南投縣信義鄉'.uniqid('', true))); + $this->assertSame('557', $rules->match('南投縣竹山鎮'.uniqid('', true))); + $this->assertSame('558', $rules->match('南投縣鹿谷鄉'.uniqid('', true))); - $this->assertSame('630', $rules->match('雲林縣斗南鎮'.uniqid())); - $this->assertSame('631', $rules->match('雲林縣大埤鄉'.uniqid())); - $this->assertSame('632', $rules->match('雲林縣虎尾鎮'.uniqid())); - $this->assertSame('633', $rules->match('雲林縣土庫鎮'.uniqid())); - $this->assertSame('634', $rules->match('雲林縣褒忠鄉'.uniqid())); - $this->assertSame('635', $rules->match('雲林縣東勢鄉'.uniqid())); - $this->assertSame('636', $rules->match('雲林縣臺西鄉'.uniqid())); - $this->assertSame('637', $rules->match('雲林縣崙背鄉'.uniqid())); - $this->assertSame('638', $rules->match('雲林縣麥寮鄉'.uniqid())); - $this->assertSame('640', $rules->match('雲林縣斗六市'.uniqid())); - $this->assertSame('643', $rules->match('雲林縣林內鄉'.uniqid())); - $this->assertSame('646', $rules->match('雲林縣古坑鄉'.uniqid())); - $this->assertSame('647', $rules->match('雲林縣莿桐鄉'.uniqid())); - $this->assertSame('648', $rules->match('雲林縣西螺鎮'.uniqid())); - $this->assertSame('649', $rules->match('雲林縣二崙鄉'.uniqid())); - $this->assertSame('651', $rules->match('雲林縣北港鎮'.uniqid())); - $this->assertSame('652', $rules->match('雲林縣水林鄉'.uniqid())); - $this->assertSame('653', $rules->match('雲林縣口湖鄉'.uniqid())); - $this->assertSame('654', $rules->match('雲林縣四湖鄉'.uniqid())); - $this->assertSame('655', $rules->match('雲林縣元長鄉'.uniqid())); + $this->assertSame('630', $rules->match('雲林縣斗南鎮'.uniqid('', true))); + $this->assertSame('631', $rules->match('雲林縣大埤鄉'.uniqid('', true))); + $this->assertSame('632', $rules->match('雲林縣虎尾鎮'.uniqid('', true))); + $this->assertSame('633', $rules->match('雲林縣土庫鎮'.uniqid('', true))); + $this->assertSame('634', $rules->match('雲林縣褒忠鄉'.uniqid('', true))); + $this->assertSame('635', $rules->match('雲林縣東勢鄉'.uniqid('', true))); + $this->assertSame('636', $rules->match('雲林縣臺西鄉'.uniqid('', true))); + $this->assertSame('637', $rules->match('雲林縣崙背鄉'.uniqid('', true))); + $this->assertSame('638', $rules->match('雲林縣麥寮鄉'.uniqid('', true))); + $this->assertSame('640', $rules->match('雲林縣斗六市'.uniqid('', true))); + $this->assertSame('643', $rules->match('雲林縣林內鄉'.uniqid('', true))); + $this->assertSame('646', $rules->match('雲林縣古坑鄉'.uniqid('', true))); + $this->assertSame('647', $rules->match('雲林縣莿桐鄉'.uniqid('', true))); + $this->assertSame('648', $rules->match('雲林縣西螺鎮'.uniqid('', true))); + $this->assertSame('649', $rules->match('雲林縣二崙鄉'.uniqid('', true))); + $this->assertSame('651', $rules->match('雲林縣北港鎮'.uniqid('', true))); + $this->assertSame('652', $rules->match('雲林縣水林鄉'.uniqid('', true))); + $this->assertSame('653', $rules->match('雲林縣口湖鄉'.uniqid('', true))); + $this->assertSame('654', $rules->match('雲林縣四湖鄉'.uniqid('', true))); + $this->assertSame('655', $rules->match('雲林縣元長鄉'.uniqid('', true))); - // $this->assertSame('600', $rules->match('嘉義市'.uniqid())); - $this->assertSame('602', $rules->match('嘉義縣番路鄉'.uniqid())); - $this->assertSame('603', $rules->match('嘉義縣梅山鄉'.uniqid())); - $this->assertSame('604', $rules->match('嘉義縣竹崎鄉'.uniqid())); - $this->assertSame('605', $rules->match('嘉義縣阿里山鄉'.uniqid())); - $this->assertSame('606', $rules->match('嘉義縣中埔鄉'.uniqid())); - $this->assertSame('607', $rules->match('嘉義縣大埔鄉'.uniqid())); - $this->assertSame('608', $rules->match('嘉義縣水上鄉'.uniqid())); - $this->assertSame('611', $rules->match('嘉義縣鹿草鄉'.uniqid())); - $this->assertSame('612', $rules->match('嘉義縣太保市'.uniqid())); - $this->assertSame('613', $rules->match('嘉義縣朴子市'.uniqid())); - $this->assertSame('614', $rules->match('嘉義縣東石鄉'.uniqid())); - $this->assertSame('615', $rules->match('嘉義縣六腳鄉'.uniqid())); - $this->assertSame('616', $rules->match('嘉義縣新港鄉'.uniqid())); - $this->assertSame('621', $rules->match('嘉義縣民雄鄉'.uniqid())); - $this->assertSame('622', $rules->match('嘉義縣大林鎮'.uniqid())); - $this->assertSame('623', $rules->match('嘉義縣溪口鄉'.uniqid())); - $this->assertSame('624', $rules->match('嘉義縣義竹鄉'.uniqid())); - $this->assertSame('625', $rules->match('嘉義縣布袋鎮'.uniqid())); + // $this->assertSame('600', $rules->match('嘉義市'.uniqid('', true))); + $this->assertSame('602', $rules->match('嘉義縣番路鄉'.uniqid('', true))); + $this->assertSame('603', $rules->match('嘉義縣梅山鄉'.uniqid('', true))); + $this->assertSame('604', $rules->match('嘉義縣竹崎鄉'.uniqid('', true))); + $this->assertSame('605', $rules->match('嘉義縣阿里山鄉'.uniqid('', true))); + $this->assertSame('606', $rules->match('嘉義縣中埔鄉'.uniqid('', true))); + $this->assertSame('607', $rules->match('嘉義縣大埔鄉'.uniqid('', true))); + $this->assertSame('608', $rules->match('嘉義縣水上鄉'.uniqid('', true))); + $this->assertSame('611', $rules->match('嘉義縣鹿草鄉'.uniqid('', true))); + $this->assertSame('612', $rules->match('嘉義縣太保市'.uniqid('', true))); + $this->assertSame('613', $rules->match('嘉義縣朴子市'.uniqid('', true))); + $this->assertSame('614', $rules->match('嘉義縣東石鄉'.uniqid('', true))); + $this->assertSame('615', $rules->match('嘉義縣六腳鄉'.uniqid('', true))); + $this->assertSame('616', $rules->match('嘉義縣新港鄉'.uniqid('', true))); + $this->assertSame('621', $rules->match('嘉義縣民雄鄉'.uniqid('', true))); + $this->assertSame('622', $rules->match('嘉義縣大林鎮'.uniqid('', true))); + $this->assertSame('623', $rules->match('嘉義縣溪口鄉'.uniqid('', true))); + $this->assertSame('624', $rules->match('嘉義縣義竹鄉'.uniqid('', true))); + $this->assertSame('625', $rules->match('嘉義縣布袋鎮'.uniqid('', true))); - $this->assertSame('700', $rules->match('台南市中 區'.uniqid())); - $this->assertSame('701', $rules->match('台南市東 區'.uniqid())); - $this->assertSame('702', $rules->match('台南市南 區'.uniqid())); - $this->assertSame('700', $rules->match('台南市西 區'.uniqid())); - $this->assertSame('704', $rules->match('台南市北 區'.uniqid())); - $this->assertSame('708', $rules->match('台南市安平區'.uniqid())); - $this->assertSame('709', $rules->match('台南市安南區'.uniqid())); - $this->assertSame('710', $rules->match('台南市永康區'.uniqid())); - $this->assertSame('711', $rules->match('台南市歸仁區'.uniqid())); - $this->assertSame('712', $rules->match('台南市新化區'.uniqid())); - $this->assertSame('713', $rules->match('台南市左鎮區'.uniqid())); - $this->assertSame('714', $rules->match('台南市玉井區'.uniqid())); - $this->assertSame('715', $rules->match('台南市楠西區'.uniqid())); - $this->assertSame('716', $rules->match('台南市南化區'.uniqid())); - $this->assertSame('717', $rules->match('台南市仁德區'.uniqid())); - $this->assertSame('718', $rules->match('台南市關廟區'.uniqid())); - $this->assertSame('719', $rules->match('台南市龍崎區'.uniqid())); - $this->assertSame('720', $rules->match('台南市官田區'.uniqid())); - $this->assertSame('721', $rules->match('台南市麻豆區'.uniqid())); - $this->assertSame('722', $rules->match('台南市佳里區'.uniqid())); - $this->assertSame('723', $rules->match('台南市西港區'.uniqid())); - $this->assertSame('724', $rules->match('台南市七股區'.uniqid())); - $this->assertSame('725', $rules->match('台南市將軍區'.uniqid())); - $this->assertSame('726', $rules->match('台南市學甲區'.uniqid())); - $this->assertSame('727', $rules->match('台南市北門區'.uniqid())); - $this->assertSame('730', $rules->match('台南市新營區'.uniqid())); - $this->assertSame('731', $rules->match('台南市後壁區'.uniqid())); - $this->assertSame('732', $rules->match('台南市白河區'.uniqid())); - $this->assertSame('733', $rules->match('台南市東山區'.uniqid())); - $this->assertSame('734', $rules->match('台南市六甲區'.uniqid())); - $this->assertSame('735', $rules->match('台南市下營區'.uniqid())); - $this->assertSame('736', $rules->match('台南市柳營區'.uniqid())); - $this->assertSame('737', $rules->match('台南市鹽水區'.uniqid())); - $this->assertSame('741', $rules->match('台南市善化區'.uniqid())); - $this->assertSame('742', $rules->match('台南市大內區'.uniqid())); - $this->assertSame('743', $rules->match('台南市山上區'.uniqid())); - $this->assertSame('744', $rules->match('台南市新市區'.uniqid())); - $this->assertSame('745', $rules->match('台南市安定區'.uniqid())); + $this->assertSame('700', $rules->match('台南市中 區'.uniqid('', true))); + $this->assertSame('701', $rules->match('台南市東 區'.uniqid('', true))); + $this->assertSame('702', $rules->match('台南市南 區'.uniqid('', true))); + $this->assertSame('700', $rules->match('台南市西 區'.uniqid('', true))); + $this->assertSame('704', $rules->match('台南市北 區'.uniqid('', true))); + $this->assertSame('708', $rules->match('台南市安平區'.uniqid('', true))); + $this->assertSame('709', $rules->match('台南市安南區'.uniqid('', true))); + $this->assertSame('710', $rules->match('台南市永康區'.uniqid('', true))); + $this->assertSame('711', $rules->match('台南市歸仁區'.uniqid('', true))); + $this->assertSame('712', $rules->match('台南市新化區'.uniqid('', true))); + $this->assertSame('713', $rules->match('台南市左鎮區'.uniqid('', true))); + $this->assertSame('714', $rules->match('台南市玉井區'.uniqid('', true))); + $this->assertSame('715', $rules->match('台南市楠西區'.uniqid('', true))); + $this->assertSame('716', $rules->match('台南市南化區'.uniqid('', true))); + $this->assertSame('717', $rules->match('台南市仁德區'.uniqid('', true))); + $this->assertSame('718', $rules->match('台南市關廟區'.uniqid('', true))); + $this->assertSame('719', $rules->match('台南市龍崎區'.uniqid('', true))); + $this->assertSame('720', $rules->match('台南市官田區'.uniqid('', true))); + $this->assertSame('721', $rules->match('台南市麻豆區'.uniqid('', true))); + $this->assertSame('722', $rules->match('台南市佳里區'.uniqid('', true))); + $this->assertSame('723', $rules->match('台南市西港區'.uniqid('', true))); + $this->assertSame('724', $rules->match('台南市七股區'.uniqid('', true))); + $this->assertSame('725', $rules->match('台南市將軍區'.uniqid('', true))); + $this->assertSame('726', $rules->match('台南市學甲區'.uniqid('', true))); + $this->assertSame('727', $rules->match('台南市北門區'.uniqid('', true))); + $this->assertSame('730', $rules->match('台南市新營區'.uniqid('', true))); + $this->assertSame('731', $rules->match('台南市後壁區'.uniqid('', true))); + $this->assertSame('732', $rules->match('台南市白河區'.uniqid('', true))); + $this->assertSame('733', $rules->match('台南市東山區'.uniqid('', true))); + $this->assertSame('734', $rules->match('台南市六甲區'.uniqid('', true))); + $this->assertSame('735', $rules->match('台南市下營區'.uniqid('', true))); + $this->assertSame('736', $rules->match('台南市柳營區'.uniqid('', true))); + $this->assertSame('737', $rules->match('台南市鹽水區'.uniqid('', true))); + $this->assertSame('741', $rules->match('台南市善化區'.uniqid('', true))); + $this->assertSame('742', $rules->match('台南市大內區'.uniqid('', true))); + $this->assertSame('743', $rules->match('台南市山上區'.uniqid('', true))); + $this->assertSame('744', $rules->match('台南市新市區'.uniqid('', true))); + $this->assertSame('745', $rules->match('台南市安定區'.uniqid('', true))); - $this->assertSame('800', $rules->match('高雄市新興區'.uniqid())); - $this->assertSame('801', $rules->match('高雄市前金區'.uniqid())); - $this->assertSame('802', $rules->match('高雄市苓雅區'.uniqid())); - $this->assertSame('803', $rules->match('高雄市鹽埕區'.uniqid())); - $this->assertSame('804', $rules->match('高雄市鼓山區'.uniqid())); - $this->assertSame('805', $rules->match('高雄市旗津區'.uniqid())); - $this->assertSame('806', $rules->match('高雄市前鎮區'.uniqid())); - $this->assertSame('807', $rules->match('高雄市三民區'.uniqid())); - $this->assertSame('811', $rules->match('高雄市楠梓區'.uniqid())); - $this->assertSame('812', $rules->match('高雄市小港區'.uniqid())); - $this->assertSame('813', $rules->match('高雄市左營區'.uniqid())); - $this->assertSame('814', $rules->match('高雄市仁武區'.uniqid())); - $this->assertSame('815', $rules->match('高雄市大社區'.uniqid())); - $this->assertSame('820', $rules->match('高雄市岡山區'.uniqid())); - $this->assertSame('821', $rules->match('高雄市路竹區'.uniqid())); - $this->assertSame('822', $rules->match('高雄市阿蓮區'.uniqid())); - $this->assertSame('823', $rules->match('高雄市田寮區'.uniqid())); - $this->assertSame('824', $rules->match('高雄市燕巢區'.uniqid())); - $this->assertSame('825', $rules->match('高雄市橋頭區'.uniqid())); - $this->assertSame('826', $rules->match('高雄市梓官區'.uniqid())); - $this->assertSame('827', $rules->match('高雄市彌陀區'.uniqid())); - $this->assertSame('828', $rules->match('高雄市永安區'.uniqid())); - $this->assertSame('829', $rules->match('高雄市湖內區'.uniqid())); - $this->assertSame('830', $rules->match('高雄市鳳山區'.uniqid())); - $this->assertSame('831', $rules->match('高雄市大寮區'.uniqid())); - $this->assertSame('832', $rules->match('高雄市林園區'.uniqid())); - $this->assertSame('833', $rules->match('高雄市鳥松區'.uniqid())); - $this->assertSame('840', $rules->match('高雄市大樹區'.uniqid())); - $this->assertSame('842', $rules->match('高雄市旗山區'.uniqid())); - $this->assertSame('843', $rules->match('高雄市美濃區'.uniqid())); - $this->assertSame('844', $rules->match('高雄市六龜區'.uniqid())); - $this->assertSame('845', $rules->match('高雄市內門區'.uniqid())); - $this->assertSame('846', $rules->match('高雄市杉林區'.uniqid())); - $this->assertSame('847', $rules->match('高雄市甲仙區'.uniqid())); - $this->assertSame('848', $rules->match('高雄市桃源區'.uniqid())); - $this->assertSame('849', $rules->match('高雄市那瑪夏區'.uniqid())); - $this->assertSame('851', $rules->match('高雄市茂林區'.uniqid())); - $this->assertSame('852', $rules->match('高雄市茄萣區'.uniqid())); + $this->assertSame('800', $rules->match('高雄市新興區'.uniqid('', true))); + $this->assertSame('801', $rules->match('高雄市前金區'.uniqid('', true))); + $this->assertSame('802', $rules->match('高雄市苓雅區'.uniqid('', true))); + $this->assertSame('803', $rules->match('高雄市鹽埕區'.uniqid('', true))); + $this->assertSame('804', $rules->match('高雄市鼓山區'.uniqid('', true))); + $this->assertSame('805', $rules->match('高雄市旗津區'.uniqid('', true))); + $this->assertSame('806', $rules->match('高雄市前鎮區'.uniqid('', true))); + $this->assertSame('807', $rules->match('高雄市三民區'.uniqid('', true))); + $this->assertSame('811', $rules->match('高雄市楠梓區'.uniqid('', true))); + $this->assertSame('812', $rules->match('高雄市小港區'.uniqid('', true))); + $this->assertSame('813', $rules->match('高雄市左營區'.uniqid('', true))); + $this->assertSame('814', $rules->match('高雄市仁武區'.uniqid('', true))); + $this->assertSame('815', $rules->match('高雄市大社區'.uniqid('', true))); + $this->assertSame('820', $rules->match('高雄市岡山區'.uniqid('', true))); + $this->assertSame('821', $rules->match('高雄市路竹區'.uniqid('', true))); + $this->assertSame('822', $rules->match('高雄市阿蓮區'.uniqid('', true))); + $this->assertSame('823', $rules->match('高雄市田寮區'.uniqid('', true))); + $this->assertSame('824', $rules->match('高雄市燕巢區'.uniqid('', true))); + $this->assertSame('825', $rules->match('高雄市橋頭區'.uniqid('', true))); + $this->assertSame('826', $rules->match('高雄市梓官區'.uniqid('', true))); + $this->assertSame('827', $rules->match('高雄市彌陀區'.uniqid('', true))); + $this->assertSame('828', $rules->match('高雄市永安區'.uniqid('', true))); + $this->assertSame('829', $rules->match('高雄市湖內區'.uniqid('', true))); + $this->assertSame('830', $rules->match('高雄市鳳山區'.uniqid('', true))); + $this->assertSame('831', $rules->match('高雄市大寮區'.uniqid('', true))); + $this->assertSame('832', $rules->match('高雄市林園區'.uniqid('', true))); + $this->assertSame('833', $rules->match('高雄市鳥松區'.uniqid('', true))); + $this->assertSame('840', $rules->match('高雄市大樹區'.uniqid('', true))); + $this->assertSame('842', $rules->match('高雄市旗山區'.uniqid('', true))); + $this->assertSame('843', $rules->match('高雄市美濃區'.uniqid('', true))); + $this->assertSame('844', $rules->match('高雄市六龜區'.uniqid('', true))); + $this->assertSame('845', $rules->match('高雄市內門區'.uniqid('', true))); + $this->assertSame('846', $rules->match('高雄市杉林區'.uniqid('', true))); + $this->assertSame('847', $rules->match('高雄市甲仙區'.uniqid('', true))); + $this->assertSame('848', $rules->match('高雄市桃源區'.uniqid('', true))); + $this->assertSame('849', $rules->match('高雄市那瑪夏區'.uniqid('', true))); + $this->assertSame('851', $rules->match('高雄市茂林區'.uniqid('', true))); + $this->assertSame('852', $rules->match('高雄市茄萣區'.uniqid('', true))); - $this->assertSame('900', $rules->match('屏東縣屏東市'.uniqid())); - $this->assertSame('901', $rules->match('屏東縣三地門鄉'.uniqid())); - $this->assertSame('902', $rules->match('屏東縣霧臺鄉'.uniqid())); - $this->assertSame('903', $rules->match('屏東縣瑪家鄉'.uniqid())); - $this->assertSame('904', $rules->match('屏東縣九如鄉'.uniqid())); - $this->assertSame('905', $rules->match('屏東縣里港鄉'.uniqid())); - $this->assertSame('906', $rules->match('屏東縣高樹鄉'.uniqid())); - $this->assertSame('907', $rules->match('屏東縣鹽埔鄉'.uniqid())); - $this->assertSame('908', $rules->match('屏東縣長治鄉'.uniqid())); - $this->assertSame('909', $rules->match('屏東縣麟洛鄉'.uniqid())); - $this->assertSame('911', $rules->match('屏東縣竹田鄉'.uniqid())); - $this->assertSame('912', $rules->match('屏東縣內埔鄉'.uniqid())); - $this->assertSame('913', $rules->match('屏東縣萬丹鄉'.uniqid())); - $this->assertSame('920', $rules->match('屏東縣潮州鎮'.uniqid())); - $this->assertSame('921', $rules->match('屏東縣泰武鄉'.uniqid())); - $this->assertSame('922', $rules->match('屏東縣來義鄉'.uniqid())); - $this->assertSame('923', $rules->match('屏東縣萬巒鄉'.uniqid())); - $this->assertSame('924', $rules->match('屏東縣崁頂鄉'.uniqid())); - $this->assertSame('925', $rules->match('屏東縣新埤鄉'.uniqid())); - $this->assertSame('926', $rules->match('屏東縣南州鄉'.uniqid())); - $this->assertSame('927', $rules->match('屏東縣林邊鄉'.uniqid())); - $this->assertSame('928', $rules->match('屏東縣東港鎮'.uniqid())); - $this->assertSame('929', $rules->match('屏東縣琉球鄉'.uniqid())); - $this->assertSame('931', $rules->match('屏東縣佳冬鄉'.uniqid())); - $this->assertSame('932', $rules->match('屏東縣新園鄉'.uniqid())); - $this->assertSame('940', $rules->match('屏東縣枋寮鄉'.uniqid())); - $this->assertSame('941', $rules->match('屏東縣枋山鄉'.uniqid())); - $this->assertSame('942', $rules->match('屏東縣春日鄉'.uniqid())); - $this->assertSame('943', $rules->match('屏東縣獅子鄉'.uniqid())); - $this->assertSame('944', $rules->match('屏東縣車城鄉'.uniqid())); - $this->assertSame('945', $rules->match('屏東縣牡丹鄉'.uniqid())); - $this->assertSame('946', $rules->match('屏東縣恆春鎮'.uniqid())); - $this->assertSame('947', $rules->match('屏東縣滿州鄉'.uniqid())); + $this->assertSame('900', $rules->match('屏東縣屏東市'.uniqid('', true))); + $this->assertSame('901', $rules->match('屏東縣三地門鄉'.uniqid('', true))); + $this->assertSame('902', $rules->match('屏東縣霧臺鄉'.uniqid('', true))); + $this->assertSame('903', $rules->match('屏東縣瑪家鄉'.uniqid('', true))); + $this->assertSame('904', $rules->match('屏東縣九如鄉'.uniqid('', true))); + $this->assertSame('905', $rules->match('屏東縣里港鄉'.uniqid('', true))); + $this->assertSame('906', $rules->match('屏東縣高樹鄉'.uniqid('', true))); + $this->assertSame('907', $rules->match('屏東縣鹽埔鄉'.uniqid('', true))); + $this->assertSame('908', $rules->match('屏東縣長治鄉'.uniqid('', true))); + $this->assertSame('909', $rules->match('屏東縣麟洛鄉'.uniqid('', true))); + $this->assertSame('911', $rules->match('屏東縣竹田鄉'.uniqid('', true))); + $this->assertSame('912', $rules->match('屏東縣內埔鄉'.uniqid('', true))); + $this->assertSame('913', $rules->match('屏東縣萬丹鄉'.uniqid('', true))); + $this->assertSame('920', $rules->match('屏東縣潮州鎮'.uniqid('', true))); + $this->assertSame('921', $rules->match('屏東縣泰武鄉'.uniqid('', true))); + $this->assertSame('922', $rules->match('屏東縣來義鄉'.uniqid('', true))); + $this->assertSame('923', $rules->match('屏東縣萬巒鄉'.uniqid('', true))); + $this->assertSame('924', $rules->match('屏東縣崁頂鄉'.uniqid('', true))); + $this->assertSame('925', $rules->match('屏東縣新埤鄉'.uniqid('', true))); + $this->assertSame('926', $rules->match('屏東縣南州鄉'.uniqid('', true))); + $this->assertSame('927', $rules->match('屏東縣林邊鄉'.uniqid('', true))); + $this->assertSame('928', $rules->match('屏東縣東港鎮'.uniqid('', true))); + $this->assertSame('929', $rules->match('屏東縣琉球鄉'.uniqid('', true))); + $this->assertSame('931', $rules->match('屏東縣佳冬鄉'.uniqid('', true))); + $this->assertSame('932', $rules->match('屏東縣新園鄉'.uniqid('', true))); + $this->assertSame('940', $rules->match('屏東縣枋寮鄉'.uniqid('', true))); + $this->assertSame('941', $rules->match('屏東縣枋山鄉'.uniqid('', true))); + $this->assertSame('942', $rules->match('屏東縣春日鄉'.uniqid('', true))); + $this->assertSame('943', $rules->match('屏東縣獅子鄉'.uniqid('', true))); + $this->assertSame('944', $rules->match('屏東縣車城鄉'.uniqid('', true))); + $this->assertSame('945', $rules->match('屏東縣牡丹鄉'.uniqid('', true))); + $this->assertSame('946', $rules->match('屏東縣恆春鎮'.uniqid('', true))); + $this->assertSame('947', $rules->match('屏東縣滿州鄉'.uniqid('', true))); - $this->assertSame('260', $rules->match('宜蘭縣宜蘭市'.uniqid())); - $this->assertSame('261', $rules->match('宜蘭縣頭城鎮'.uniqid())); - $this->assertSame('262', $rules->match('宜蘭縣礁溪鄉'.uniqid())); - $this->assertSame('263', $rules->match('宜蘭縣壯圍鄉'.uniqid())); - $this->assertSame('264', $rules->match('宜蘭縣員山鄉'.uniqid())); - $this->assertSame('265', $rules->match('宜蘭縣羅東鎮'.uniqid())); - $this->assertSame('266', $rules->match('宜蘭縣三星鄉'.uniqid())); - $this->assertSame('267', $rules->match('宜蘭縣大同鄉'.uniqid())); - $this->assertSame('268', $rules->match('宜蘭縣五結鄉'.uniqid())); - $this->assertSame('269', $rules->match('宜蘭縣冬山鄉'.uniqid())); - $this->assertSame('270', $rules->match('宜蘭縣蘇澳鎮'.uniqid())); - $this->assertSame('272', $rules->match('宜蘭縣南澳鄉'.uniqid())); + $this->assertSame('260', $rules->match('宜蘭縣宜蘭市'.uniqid('', true))); + $this->assertSame('261', $rules->match('宜蘭縣頭城鎮'.uniqid('', true))); + $this->assertSame('262', $rules->match('宜蘭縣礁溪鄉'.uniqid('', true))); + $this->assertSame('263', $rules->match('宜蘭縣壯圍鄉'.uniqid('', true))); + $this->assertSame('264', $rules->match('宜蘭縣員山鄉'.uniqid('', true))); + $this->assertSame('265', $rules->match('宜蘭縣羅東鎮'.uniqid('', true))); + $this->assertSame('266', $rules->match('宜蘭縣三星鄉'.uniqid('', true))); + $this->assertSame('267', $rules->match('宜蘭縣大同鄉'.uniqid('', true))); + $this->assertSame('268', $rules->match('宜蘭縣五結鄉'.uniqid('', true))); + $this->assertSame('269', $rules->match('宜蘭縣冬山鄉'.uniqid('', true))); + $this->assertSame('270', $rules->match('宜蘭縣蘇澳鎮'.uniqid('', true))); + $this->assertSame('272', $rules->match('宜蘭縣南澳鄉'.uniqid('', true))); - $this->assertSame('970', $rules->match('花蓮縣花蓮市'.uniqid())); - $this->assertSame('971', $rules->match('花蓮縣新城鄉'.uniqid())); - $this->assertSame('972', $rules->match('花蓮縣秀林鄉'.uniqid())); - $this->assertSame('973', $rules->match('花蓮縣吉安鄉'.uniqid())); - $this->assertSame('974', $rules->match('花蓮縣壽豐鄉'.uniqid())); - $this->assertSame('975', $rules->match('花蓮縣鳳林鎮'.uniqid())); - $this->assertSame('976', $rules->match('花蓮縣光復鄉'.uniqid())); - $this->assertSame('977', $rules->match('花蓮縣豐濱鄉'.uniqid())); - $this->assertSame('978', $rules->match('花蓮縣瑞穗鄉'.uniqid())); - $this->assertSame('979', $rules->match('花蓮縣萬榮鄉'.uniqid())); - $this->assertSame('981', $rules->match('花蓮縣玉里鎮'.uniqid())); - $this->assertSame('982', $rules->match('花蓮縣卓溪鄉'.uniqid())); - $this->assertSame('983', $rules->match('花蓮縣富里鄉'.uniqid())); + $this->assertSame('970', $rules->match('花蓮縣花蓮市'.uniqid('', true))); + $this->assertSame('971', $rules->match('花蓮縣新城鄉'.uniqid('', true))); + $this->assertSame('972', $rules->match('花蓮縣秀林鄉'.uniqid('', true))); + $this->assertSame('973', $rules->match('花蓮縣吉安鄉'.uniqid('', true))); + $this->assertSame('974', $rules->match('花蓮縣壽豐鄉'.uniqid('', true))); + $this->assertSame('975', $rules->match('花蓮縣鳳林鎮'.uniqid('', true))); + $this->assertSame('976', $rules->match('花蓮縣光復鄉'.uniqid('', true))); + $this->assertSame('977', $rules->match('花蓮縣豐濱鄉'.uniqid('', true))); + $this->assertSame('978', $rules->match('花蓮縣瑞穗鄉'.uniqid('', true))); + $this->assertSame('979', $rules->match('花蓮縣萬榮鄉'.uniqid('', true))); + $this->assertSame('981', $rules->match('花蓮縣玉里鎮'.uniqid('', true))); + $this->assertSame('982', $rules->match('花蓮縣卓溪鄉'.uniqid('', true))); + $this->assertSame('983', $rules->match('花蓮縣富里鄉'.uniqid('', true))); - $this->assertSame('950', $rules->match('台東縣臺東市'.uniqid())); - $this->assertSame('951', $rules->match('台東縣綠島鄉'.uniqid())); - $this->assertSame('952', $rules->match('台東縣蘭嶼鄉'.uniqid())); - $this->assertSame('953', $rules->match('台東縣延平鄉'.uniqid())); - $this->assertSame('954', $rules->match('台東縣卑南鄉'.uniqid())); - $this->assertSame('955', $rules->match('台東縣鹿野鄉'.uniqid())); - $this->assertSame('956', $rules->match('台東縣關山鎮'.uniqid())); - $this->assertSame('957', $rules->match('台東縣海端鄉'.uniqid())); - $this->assertSame('958', $rules->match('台東縣池上鄉'.uniqid())); - $this->assertSame('959', $rules->match('台東縣東河鄉'.uniqid())); - $this->assertSame('961', $rules->match('台東縣成功鎮'.uniqid())); - $this->assertSame('962', $rules->match('台東縣長濱鄉'.uniqid())); - $this->assertSame('963', $rules->match('台東縣太麻里鄉'.uniqid())); - $this->assertSame('964', $rules->match('台東縣金峰鄉'.uniqid())); - $this->assertSame('965', $rules->match('台東縣大武鄉'.uniqid())); - $this->assertSame('966', $rules->match('台東縣達仁鄉'.uniqid())); + $this->assertSame('950', $rules->match('台東縣臺東市'.uniqid('', true))); + $this->assertSame('951', $rules->match('台東縣綠島鄉'.uniqid('', true))); + $this->assertSame('952', $rules->match('台東縣蘭嶼鄉'.uniqid('', true))); + $this->assertSame('953', $rules->match('台東縣延平鄉'.uniqid('', true))); + $this->assertSame('954', $rules->match('台東縣卑南鄉'.uniqid('', true))); + $this->assertSame('955', $rules->match('台東縣鹿野鄉'.uniqid('', true))); + $this->assertSame('956', $rules->match('台東縣關山鎮'.uniqid('', true))); + $this->assertSame('957', $rules->match('台東縣海端鄉'.uniqid('', true))); + $this->assertSame('958', $rules->match('台東縣池上鄉'.uniqid('', true))); + $this->assertSame('959', $rules->match('台東縣東河鄉'.uniqid('', true))); + $this->assertSame('961', $rules->match('台東縣成功鎮'.uniqid('', true))); + $this->assertSame('962', $rules->match('台東縣長濱鄉'.uniqid('', true))); + $this->assertSame('963', $rules->match('台東縣太麻里鄉'.uniqid('', true))); + $this->assertSame('964', $rules->match('台東縣金峰鄉'.uniqid('', true))); + $this->assertSame('965', $rules->match('台東縣大武鄉'.uniqid('', true))); + $this->assertSame('966', $rules->match('台東縣達仁鄉'.uniqid('', true))); - $this->assertSame('890', $rules->match('金門縣金沙鎮'.uniqid())); - $this->assertSame('891', $rules->match('金門縣金湖鎮'.uniqid())); - $this->assertSame('892', $rules->match('金門縣金寧鄉'.uniqid())); - $this->assertSame('893', $rules->match('金門縣金城鎮'.uniqid())); - $this->assertSame('894', $rules->match('金門縣烈嶼鄉'.uniqid())); - $this->assertSame('896', $rules->match('金門縣烏坵鄉'.uniqid())); - $this->assertSame('880', $rules->match('澎湖縣馬公市'.uniqid())); - $this->assertSame('881', $rules->match('澎湖縣西嶼鄉'.uniqid())); - $this->assertSame('882', $rules->match('澎湖縣望安鄉'.uniqid())); - $this->assertSame('883', $rules->match('澎湖縣七美鄉'.uniqid())); - $this->assertSame('884', $rules->match('澎湖縣白沙鄉'.uniqid())); - $this->assertSame('885', $rules->match('澎湖縣湖西鄉'.uniqid())); - $this->assertSame('209', $rules->match('連江縣南竿鄉'.uniqid())); - $this->assertSame('210', $rules->match('連江縣北竿鄉'.uniqid())); - $this->assertSame('211', $rules->match('連江縣莒光鄉'.uniqid())); - $this->assertSame('212', $rules->match('連江縣東引鄉'.uniqid())); - $this->assertSame('817', $rules->match('南海諸島東 沙'.uniqid())); - $this->assertSame('819', $rules->match('南海諸島南 沙'.uniqid())); - $this->assertSame('290', $rules->match('南海諸島釣魚台列嶼'.uniqid())); + $this->assertSame('890', $rules->match('金門縣金沙鎮'.uniqid('', true))); + $this->assertSame('891', $rules->match('金門縣金湖鎮'.uniqid('', true))); + $this->assertSame('892', $rules->match('金門縣金寧鄉'.uniqid('', true))); + $this->assertSame('893', $rules->match('金門縣金城鎮'.uniqid('', true))); + $this->assertSame('894', $rules->match('金門縣烈嶼鄉'.uniqid('', true))); + $this->assertSame('896', $rules->match('金門縣烏坵鄉'.uniqid('', true))); + $this->assertSame('880', $rules->match('澎湖縣馬公市'.uniqid('', true))); + $this->assertSame('881', $rules->match('澎湖縣西嶼鄉'.uniqid('', true))); + $this->assertSame('882', $rules->match('澎湖縣望安鄉'.uniqid('', true))); + $this->assertSame('883', $rules->match('澎湖縣七美鄉'.uniqid('', true))); + $this->assertSame('884', $rules->match('澎湖縣白沙鄉'.uniqid('', true))); + $this->assertSame('885', $rules->match('澎湖縣湖西鄉'.uniqid('', true))); + $this->assertSame('209', $rules->match('連江縣南竿鄉'.uniqid('', true))); + $this->assertSame('210', $rules->match('連江縣北竿鄉'.uniqid('', true))); + $this->assertSame('211', $rules->match('連江縣莒光鄉'.uniqid('', true))); + $this->assertSame('212', $rules->match('連江縣東引鄉'.uniqid('', true))); + $this->assertSame('817', $rules->match('南海諸島東 沙'.uniqid('', true))); + $this->assertSame('819', $rules->match('南海諸島南 沙'.uniqid('', true))); + $this->assertSame('290', $rules->match('南海諸島釣魚台列嶼'.uniqid('', true))); } // public function testMatchMiddleToken() diff --git a/tests/Storages/FileTest.php b/tests/Storages/FileTest.php index f30fade..6ae0fb2 100644 --- a/tests/Storages/FileTest.php +++ b/tests/Storages/FileTest.php @@ -6,19 +6,21 @@ use Mockery as m; use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; -use Recca0120\Twzipcode\Storages\File; use Recca0120\Twzipcode\Address; +use Recca0120\Twzipcode\Storages\File as Storage; class FileTest extends TestCase { use MockeryPHPUnitIntegration; + private $root; + private $storage; protected function setUp(): void { - $root = vfsStream::setup(); - $this->storage = new File($root->url()); + $this->root = vfsStream::setup(); + $this->storage = new Storage($this->root->url()); $this->storage->flush()->load(' 10058,臺北市,中正區,八德路1段,全 10079,臺北市,中正區,三元街,單全 @@ -87,7 +89,7 @@ protected function setUp(): void public function testDefaultPath(): void { - $storage = new File(); + $storage = new Storage; $this->assertEquals(realpath(__DIR__.'/../../resources/data').'/', $storage->path); } @@ -116,14 +118,9 @@ public function testRules(): void public function testLoadResources(): void { - File::$cached = [ - 'zip3' => null, - 'zip5' => null, - ]; - $root = vfsStream::setup(); - $storage = new File($root->url()); - $storage->flush() - ->loadFile(__DIR__.'/../../resources/Zip32_utf8_10501_1.zip'); + Storage::$cached = ['zip3' => null, 'zip5' => null]; + $storage = new Storage($this->root->url()); + $storage->flush()->loadFile(__DIR__.'/../../resources/Zip32_utf8_10501_1.zip'); $address = m::mock(Address::class); diff --git a/tests/ZipcodeTest.php b/tests/ZipcodeTest.php index 7e7def0..995cd4d 100644 --- a/tests/ZipcodeTest.php +++ b/tests/ZipcodeTest.php @@ -47,7 +47,7 @@ protected function setUp(): void public function testZipcode(): void { $address = '台中市大里區金城里14鄰塗城路9478巷9478弄9478號'; - $zipcode = Zipcode::parse($address, $this->rules ?: new Rules()); + $zipcode = Zipcode::parse($address, $this->rules ?: new Rules); $this->assertSame('412', $zipcode->zip3()); $this->assertSame('41275', $zipcode->zip5()); @@ -60,7 +60,7 @@ public function testZipcode(): void public function testZipcode2(): void { $address = '宜蘭縣宜蘭市金城里14鄰慶和街同興巷9478弄9478號'; - $zipcode = Zipcode::parse($address, $this->rules ?: new Rules()); + $zipcode = Zipcode::parse($address, $this->rules ?: new Rules); $this->assertSame('260', $zipcode->zip3()); $this->assertSame('26044', $zipcode->zip5()); @@ -73,7 +73,7 @@ public function testZipcode2(): void public function testZipcode3(): void { $address = '台北市中正區中華路1段25號'; - $zipcode = Zipcode::parse($address, $this->rules ?: new Rules()); + $zipcode = Zipcode::parse($address, $this->rules ?: new Rules); $this->assertSame('100', $zipcode->zip3()); $this->assertSame('10043', $zipcode->zip5()); @@ -86,7 +86,7 @@ public function testZipcode3(): void public function testZipcode4(): void { $address = '宜蘭縣壯圍鄉環市東路1段374號'; - $zipcode = Zipcode::parse($address, $this->rules ?: new Rules()); + $zipcode = Zipcode::parse($address, $this->rules ?: new Rules); $this->assertSame('260', $zipcode->zip3()); $this->assertSame('26060', $zipcode->zip5());