diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..22aac70 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,14 @@ +/tests export-ignore +/vendor export-ignore + +/LICENSE export-ignore +/Makefile export-ignore +/README.md export-ignore +/phpmd.xml export-ignore +/phpunit.xml export-ignore +/phpstan.neon.dist export-ignore +/infection.json.dist export-ignore + +/.github export-ignore +/.gitignore export-ignore +/.gitattributes export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32850ac..105bc90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,11 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Use PHP 8.2 + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + - name: Install dependencies run: composer update --no-progress --optimize-autoloader @@ -33,6 +38,11 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Use PHP 8.2 + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + - name: Install dependencies run: composer update --no-progress --optimize-autoloader diff --git a/Makefile b/Makefile index 9bf35fe..1b3026e 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,17 @@ DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.2 -.PHONY: configure test test-no-coverage review show-reports clean +.PHONY: configure test test-file test-no-coverage review show-reports clean configure: @${DOCKER_RUN} composer update --optimize-autoloader -test: review +test: @${DOCKER_RUN} composer tests -test-no-coverage: review +test-file: + @${DOCKER_RUN} composer tests-file-no-coverage ${FILE} + +test-no-coverage: @${DOCKER_RUN} composer tests-no-coverage review: @@ -19,4 +22,4 @@ show-reports: clean: @sudo chown -R ${USER}:${USER} ${PWD} - @rm -rf report vendor + @rm -rf report vendor .phpunit.cache diff --git a/README.md b/README.md index e9d0419..e9279db 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,9 @@ get the default amount fraction digits for the respective currency. ```php $currency = Currency::USD; -$currency->name; # USD -$currency->value; # USD -$currency->getDefaultFractionDigits(); # 2 +$currency->name; # USD +$currency->value; # USD +$currency->getFractionDigits(); # 2 ```
diff --git a/composer.json b/composer.json index cbd1e07..e4ed20c 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,6 @@ "keywords": [ "vo", "psr", - "psr-4", - "psr-12", "currency", "iso-4217", "tiny-blocks", @@ -22,6 +20,10 @@ "homepage": "https://github.com/gustavofreze" } ], + "support": { + "issues": "https://github.com/tiny-blocks/currency/issues", + "source": "https://github.com/tiny-blocks/currency" + }, "config": { "sort-packages": true, "allow-plugins": { @@ -39,24 +41,27 @@ } }, "require": { - "php": "^8.1||^8.2" + "php": "^8.2" }, "require-dev": { - "infection/infection": "^0.26", - "phpmd/phpmd": "^2.13", - "phpunit/phpunit": "^9.6", - "squizlabs/php_codesniffer": "^3.7" + "phpmd/phpmd": "^2.15", + "phpunit/phpunit": "^11", + "phpstan/phpstan": "^1", + "infection/infection": "^0.29", + "squizlabs/php_codesniffer": "^3.10" }, "scripts": { "phpcs": "phpcs --standard=PSR12 --extensions=php ./src", "phpmd": "phpmd ./src text phpmd.xml --suffixes php --exclude /src/Currency.php --ignore-violations-on-exit", + "phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress", "test": "phpunit --log-junit=report/coverage/junit.xml --coverage-xml=report/coverage/coverage-xml --coverage-html=report/coverage/coverage-html tests", "test-mutation": "infection --only-covered --logger-html=report/coverage/mutation-report.html --coverage=report/coverage --min-msi=100 --min-covered-msi=100 --threads=4", "test-no-coverage": "phpunit --no-coverage", "test-mutation-no-coverage": "infection --only-covered --min-msi=100 --threads=4", "review": [ "@phpcs", - "@phpmd" + "@phpmd", + "@phpstan" ], "tests": [ "@test", diff --git a/infection.json.dist b/infection.json.dist index d840b61..351e7f9 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -1,22 +1,21 @@ { "timeout": 10, "testFramework": "phpunit", - "tmpDir": "report/", + "tmpDir": "report/infection/", "source": { "directories": [ "src" ] }, "logs": { - "text": "report/logs/infection-text.log", - "summary": "report/logs/infection-summary.log" + "text": "report/infection/logs/infection-text.log", + "summary": "report/infection/logs/infection-summary.log" }, "mutators": { - "@default": true, - "MatchArmRemoval": false + "@default": true }, "phpUnit": { "configDir": "", "customPath": "./vendor/bin/phpunit" } -} \ No newline at end of file +} diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..b99884f --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,7 @@ +parameters: + paths: + - src + level: 9 + tmpDir: report/phpstan + ignoreErrors: + reportUnmatchedIgnoredErrors: false diff --git a/phpunit.xml b/phpunit.xml index 3d05fc8..7f080dd 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,25 +1,35 @@ + bootstrap="vendor/autoload.php" + failOnRisky="true" + failOnWarning="true" + cacheDirectory=".phpunit.cache" + beStrictAboutOutputDuringTests="true"> + + + + src + + + - tests + tests - - src - + + + + + + + + + + diff --git a/src/Currency.php b/src/Currency.php index feef080..15093fb 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -1,5 +1,7 @@ 0, + Currency::XOF, Currency::XPF => self::FRACTION_DIGITS_ZERO, Currency::BHD, Currency::IQD, Currency::JOD, Currency::KWD, Currency::LYD, - Currency::OMR, Currency::TND => 3, - Currency::CLF, Currency::UYW, => 4, - default => 2 + Currency::OMR, Currency::TND => self::FRACTION_DIGITS_THREE, + Currency::CLF, Currency::UYW, => self::FRACTION_DIGITS_FOUR, + default => self::FRACTION_DIGITS_TWO }; } } diff --git a/tests/CurrencyTest.php b/tests/CurrencyTest.php index 0e86cd9..0d5395b 100644 --- a/tests/CurrencyTest.php +++ b/tests/CurrencyTest.php @@ -1,65 +1,68 @@ getDefaultFractionDigits(); + $actual = $currency->getFractionDigits(); - self::assertEquals($expected, $actual); + self::assertSame($expected, $actual); } - public function providerForTestValidNameAndValue(): array + public static function currenciesDataProvider(): array { - return array_map(fn(Currency $currency) => [ + return array_map(static fn(Currency $currency): array => [ 'name' => $currency->name, 'value' => $currency->value ], Currency::cases()); } - public function providerForTestGetDefaultFractionDigits(): array + public static function fractionDigitsDataProvider(): array { return [ - [ - 'expected' => 0, - 'currency' => Currency::CLP, - ], - [ - 'expected' => 2, - 'currency' => Currency::BRL, - ], - [ - 'expected' => 2, - 'currency' => Currency::USD, - ], - [ - 'expected' => 2, - 'currency' => Currency::EUR, - ], - [ - 'expected' => 3, - 'currency' => Currency::KWD, - ], - [ - 'expected' => 4, - 'currency' => Currency::CLF - ] + 'Currency BIF with digits 0' => ['currency' => Currency::BIF, 'expected' => 0], + 'Currency CLP with digits 0' => ['currency' => Currency::CLP, 'expected' => 0], + 'Currency DJF with digits 0' => ['currency' => Currency::DJF, 'expected' => 0], + 'Currency GNF with digits 0' => ['currency' => Currency::GNF, 'expected' => 0], + 'Currency ISK with digits 0' => ['currency' => Currency::ISK, 'expected' => 0], + 'Currency JPY with digits 0' => ['currency' => Currency::JPY, 'expected' => 0], + 'Currency KMF with digits 0' => ['currency' => Currency::KMF, 'expected' => 0], + 'Currency KRW with digits 0' => ['currency' => Currency::KRW, 'expected' => 0], + 'Currency PYG with digits 0' => ['currency' => Currency::PYG, 'expected' => 0], + 'Currency RWF with digits 0' => ['currency' => Currency::RWF, 'expected' => 0], + 'Currency UGX with digits 0' => ['currency' => Currency::UGX, 'expected' => 0], + 'Currency UYI with digits 0' => ['currency' => Currency::UYI, 'expected' => 0], + 'Currency VND with digits 0' => ['currency' => Currency::VND, 'expected' => 0], + 'Currency VUV with digits 0' => ['currency' => Currency::VUV, 'expected' => 0], + 'Currency XAF with digits 0' => ['currency' => Currency::XAF, 'expected' => 0], + 'Currency XOF with digits 0' => ['currency' => Currency::XOF, 'expected' => 0], + 'Currency XPF with digits 0' => ['currency' => Currency::XPF, 'expected' => 0], + 'Currency USD with digits 2' => ['currency' => Currency::USD, 'expected' => 2], + 'Currency EUR with digits 2' => ['currency' => Currency::EUR, 'expected' => 2], + 'Currency BHD with digits 3' => ['currency' => Currency::BHD, 'expected' => 3], + 'Currency IQD with digits 3' => ['currency' => Currency::IQD, 'expected' => 3], + 'Currency JOD with digits 3' => ['currency' => Currency::JOD, 'expected' => 3], + 'Currency KWD with digits 3' => ['currency' => Currency::KWD, 'expected' => 3], + 'Currency LYD with digits 3' => ['currency' => Currency::LYD, 'expected' => 3], + 'Currency OMR with digits 3' => ['currency' => Currency::OMR, 'expected' => 3], + 'Currency TND with digits 3' => ['currency' => Currency::TND, 'expected' => 3], + 'Currency CLF with digits 4' => ['currency' => Currency::CLF, 'expected' => 4], + 'Currency UYW with digits 4' => ['currency' => Currency::UYW, 'expected' => 4] ]; } }