diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..fdca1d4 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,14 @@ +version: 2 + +jobs: + build: + working_directory: ~/zengin-php + docker: + - image: circleci/php:latest + steps: + - checkout + - run: sudo composer self-update + - run: composer install -n --prefer-dist + - run: + name: phpunit + command: ./vendor/bin/phpunit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..80ee51f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/* +/composer.lock +/vendor/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..53a3333 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "source-data"] + path = source-data + url = git@github.com:zengin-code/source-data.git diff --git a/README.md b/README.md index 10da683..d98e59b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ # zengin-php -The ruby implementation of ZenginCode. +The PHP implementation of ZenginCode. + +## Installation +Install via [composer](https://getcomposer.org/). + +``` +$ composer require zengin-code/zengin-php +``` + +## Usage +```php +// get source data updated at +echo \ZenginCode\ZenginCode::getLastUpdatedAt(); // 20190501 + +// get all banks as Bank instance array +$banks = \ZenginCode\ZenginCode::findBank(); + +// find bank from code as Bank instance +$bank = \ZenginCode\ZenginCode::findBank('0005'); +echo $bank->code . PHP_EOL; // 0005 +echo $bank->name . PHP_EOL; // 三菱UFJ +echo $bank->kana . PHP_EOL; // ミツビシユ-エフジエイ +echo $bank->hira . PHP_EOL; // みつびしゆ-えふじえい +echo $bank->roma . PHP_EOL; // mitsubishiyu-efujiei + +// get all branches of bank as Branch instance array +$branches = \ZenginCode\ZenginCode::findBranch(); + +// find branch from code as Branch instance +$branch = \ZenginCode\ZenginCode::findBranch('0005', '002'); +echo $branch->code . PHP_EOL; // 002 +echo $branch->name . PHP_EOL; // 丸の内 +echo $branch->kana . PHP_EOL; // マルノウチ +echo $branch->hira . PHP_EOL; // まるのうち +echo $branch->roma . PHP_EOL; // marunouchi +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..13733b7 --- /dev/null +++ b/composer.json @@ -0,0 +1,25 @@ +{ + "name": "zengin-code/zengin-php", + "description": "bank codes and branch codes for Japanese", + "keywords": ["bank code"], + "homepage": "https://github.com/thatblue/zengin-php", + "license": "MIT", + "require": { + "php": ">= 5.5", + "guzzlehttp/guzzle": "^6.3" + }, + "require-dev": { + "phpunit/phpunit": "^7.5 || ^4.8", + "php-coveralls/php-coveralls": "^2.1 || ^1.1" + }, + "autoload": { + "psr-4": { + "ZenginCode\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "ZenginCode\\": "tests/" + } + } +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..6a5edcd --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,21 @@ + + + + + + tests/ZenginCode/ + + + + + + src + + + + + + + diff --git a/source-data b/source-data new file mode 160000 index 0000000..c398f18 --- /dev/null +++ b/source-data @@ -0,0 +1 @@ +Subproject commit c398f18bc4cd49d12ecace79f1b2bbca731deac0 diff --git a/src/Model/Bank.php b/src/Model/Bank.php new file mode 100644 index 0000000..5406f52 --- /dev/null +++ b/src/Model/Bank.php @@ -0,0 +1,25 @@ +code = $sourceJson['code']; + $this->name = $sourceJson['name']; + $this->kana = $sourceJson['kana']; + $this->hira = $sourceJson['hira']; + $this->roma = $sourceJson['roma']; + } +} diff --git a/src/Model/Branch.php b/src/Model/Branch.php new file mode 100644 index 0000000..ef55bb6 --- /dev/null +++ b/src/Model/Branch.php @@ -0,0 +1,25 @@ +code = $sourceJson['code']; + $this->name = $sourceJson['name']; + $this->kana = $sourceJson['kana']; + $this->hira = $sourceJson['hira']; + $this->roma = $sourceJson['roma']; + } +} diff --git a/src/ZenginCode.php b/src/ZenginCode.php new file mode 100644 index 0000000..100a818 --- /dev/null +++ b/src/ZenginCode.php @@ -0,0 +1,103 @@ +assertSame( + file_get_contents(ZenginCode::DATA_PATH . DIRECTORY_SEPARATOR . 'updated_at'), + ZenginCode::getLastUpdatedAt() + ); + } + + public function test_findBank_existsCode() + { + $actualBank = ZenginCode::findBank('0001'); + + $this->assertSame('0001', $actualBank->code); + $this->assertSame('みずほ', $actualBank->name); + $this->assertSame('ミズホ', $actualBank->kana); + $this->assertSame('みずほ', $actualBank->hira); + $this->assertSame('mizuho', $actualBank->roma); + } + + public function test_findBank_notExistsCode() + { + $this->assertNull(ZenginCode::findBank('9999')); + } + + public function test_findBank_intCode() + { + $actualBank = ZenginCode::findBank(125); + + $this->assertSame('0125', $actualBank->code); + $this->assertSame('七十七', $actualBank->name); + $this->assertSame('シチジユウシチ', $actualBank->kana); + $this->assertSame('しちじゆうしち', $actualBank->hira); + $this->assertSame('shichijiyuushichi', $actualBank->roma); + } + + public function test_findBank_all() + { + $banks = ZenginCode::findBank(); + + $this->assertIsArray($banks); + foreach ($banks as $bank) { + $this->assertInstanceOf('ZenginCode\Model\Bank', $bank); + } + } + + public function test_findBranch_existsCode() + { + $actualBranch = ZenginCode::findBranch('0001', '001'); + $this->assertSame('001', $actualBranch->code); + $this->assertSame('東京営業部', $actualBranch->name); + $this->assertSame('トウキヨウ', $actualBranch->kana); + $this->assertSame('とうきよう', $actualBranch->hira); + $this->assertSame('toukiyou', $actualBranch->roma); + } + + /** + * @depends test_findBranch_existsCode + */ + public function test_findBranch_anotherExistsCode() + { + $actualBranch = ZenginCode::findBranch('0005', '001'); + $this->assertSame('001', $actualBranch->code); + $this->assertSame('本店', $actualBranch->name); + $this->assertSame('ホンテン', $actualBranch->kana); + $this->assertSame('ほんてん', $actualBranch->hira); + $this->assertSame('honten', $actualBranch->roma); + } + + /** + * @depends test_findBranch_anotherExistsCode + */ + public function test_findBranch_recallFirstExitsCode() + { + $actualBranch = ZenginCode::findBranch('0001', '001'); + $this->assertSame('001', $actualBranch->code); + $this->assertSame('東京営業部', $actualBranch->name); + $this->assertSame('トウキヨウ', $actualBranch->kana); + $this->assertSame('とうきよう', $actualBranch->hira); + $this->assertSame('toukiyou', $actualBranch->roma); + } + + public function test_findBranch_notExistsCode() + { + $this->assertNull(ZenginCode::findBranch('0001', '999')); + } + + public function test_findBranch_notExistsBank() + { + try { + $this->assertNull(ZenginCode::findBranch('9999', '001')); + } catch (\Throwable $t) { + $this->fail(); + } + } + + public function test_findBranch_all() + { + $branches = ZenginCode::findBranch('0001'); + + $this->assertIsArray($branches); + foreach ($branches as $branch) { + $this->assertInstanceOf('ZenginCode\Model\Branch', $branch); + } + } + +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..129d07b --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,4 @@ +