From 7760ab37661a70ca1707cb4a0dfdcbe358f6fd9d Mon Sep 17 00:00:00 2001 From: Gustavo Freze Date: Thu, 12 Dec 2024 09:27:35 -0300 Subject: [PATCH] feat: Updates dependencies and PHP from 8.2 to 8.3. --- .github/workflows/ci.yml | 32 +++++++++++++------------------- Makefile | 9 +++------ composer.json | 23 +++++++++++------------ infection.json.dist | 20 +++++++++++--------- phpunit.xml | 6 ++++-- src/Currency.php | 13 +++++++++---- 6 files changed, 51 insertions(+), 52 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 105bc90..358ac92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,14 @@ name: CI on: - push: pull_request: permissions: contents: read +env: + PHP_VERSION: '8.3' + jobs: auto-review: name: Auto review @@ -14,21 +16,18 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Use PHP 8.2 + - name: Configure PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: ${{ env.PHP_VERSION }} - name: Install dependencies run: composer update --no-progress --optimize-autoloader - - name: Run phpcs - run: composer phpcs - - - name: Run phpmd - run: composer phpmd + - name: Run review + run: composer review tests: name: Tests @@ -36,20 +35,15 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Use PHP 8.2 + - name: Use PHP ${{ env.PHP_VERSION }} uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: ${{ env.PHP_VERSION }} - name: Install dependencies run: composer update --no-progress --optimize-autoloader - - name: Run unit tests - env: - XDEBUG_MODE: coverage - run: composer test - - - name: Run mutation tests - run: composer test-mutation + - name: Run tests + run: composer tests diff --git a/Makefile b/Makefile index 1b3026e..e93c1fa 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.2 +DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.3 -.PHONY: configure test test-file test-no-coverage review show-reports clean +.PHONY: configure test test-no-coverage review show-reports clean configure: @${DOCKER_RUN} composer update --optimize-autoloader @@ -8,9 +8,6 @@ configure: test: @${DOCKER_RUN} composer tests -test-file: - @${DOCKER_RUN} composer tests-file-no-coverage ${FILE} - test-no-coverage: @${DOCKER_RUN} composer tests-no-coverage @@ -22,4 +19,4 @@ show-reports: clean: @sudo chown -R ${USER}:${USER} ${PWD} - @rm -rf report vendor .phpunit.cache + @rm -rf report vendor .phpunit.cache .lock diff --git a/composer.json b/composer.json index e4ed20c..19d8b4e 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "psr", "currency", "iso-4217", + "currencies", "tiny-blocks", "value-object" ], @@ -41,23 +42,22 @@ } }, "require": { - "php": "^8.2" + "php": "^8.3" }, "require-dev": { "phpmd/phpmd": "^2.15", - "phpunit/phpunit": "^11", "phpstan/phpstan": "^1", - "infection/infection": "^0.29", - "squizlabs/php_codesniffer": "^3.10" + "phpunit/phpunit": "^11", + "infection/infection": "^0", + "squizlabs/php_codesniffer": "^3.11" }, "scripts": { + "test": "phpunit --configuration phpunit.xml tests", "phpcs": "phpcs --standard=PSR12 --extensions=php ./src", - "phpmd": "phpmd ./src text phpmd.xml --suffixes php --exclude /src/Currency.php --ignore-violations-on-exit", + "phpmd": "phpmd ./src text phpmd.xml --suffixes 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", + "mutation-test": "infection --only-covered --threads=max --logger-html=report/coverage/mutation-report.html --coverage=report/coverage", + "test-no-coverage": "phpunit --configuration phpunit.xml --no-coverage tests", "review": [ "@phpcs", "@phpmd", @@ -65,11 +65,10 @@ ], "tests": [ "@test", - "@test-mutation" + "@mutation-test" ], "tests-no-coverage": [ - "@test-no-coverage", - "@test-mutation-no-coverage" + "@test-no-coverage" ] } } diff --git a/infection.json.dist b/infection.json.dist index 351e7f9..45c49fc 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -1,21 +1,23 @@ { - "timeout": 10, - "testFramework": "phpunit", + "logs": { + "text": "report/infection/logs/infection-text.log", + "summary": "report/infection/logs/infection-summary.log" + }, "tmpDir": "report/infection/", + "minMsi": 100, + "timeout": 30, "source": { "directories": [ "src" ] }, - "logs": { - "text": "report/infection/logs/infection-text.log", - "summary": "report/infection/logs/infection-summary.log" + "phpUnit": { + "configDir": "", + "customPath": "./vendor/bin/phpunit" }, "mutators": { "@default": true }, - "phpUnit": { - "configDir": "", - "customPath": "./vendor/bin/phpunit" - } + "minCoveredMsi": 100, + "testFramework": "phpunit" } diff --git a/phpunit.xml b/phpunit.xml index 7f080dd..40c80a2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,6 +6,7 @@ failOnRisky="true" failOnWarning="true" cacheDirectory=".phpunit.cache" + executionOrder="random" beStrictAboutOutputDuringTests="true"> @@ -22,14 +23,15 @@ + + - - + diff --git a/src/Currency.php b/src/Currency.php index 15093fb..e05c28f 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -182,11 +182,16 @@ enum Currency: string case ZMW = 'ZMW'; case ZWL = 'ZWL'; - private const FRACTION_DIGITS_TWO = 2; - private const FRACTION_DIGITS_ZERO = 0; - private const FRACTION_DIGITS_FOUR = 4; - private const FRACTION_DIGITS_THREE = 3; + private const int FRACTION_DIGITS_TWO = 2; + private const int FRACTION_DIGITS_ZERO = 0; + private const int FRACTION_DIGITS_FOUR = 4; + private const int FRACTION_DIGITS_THREE = 3; + /** + * Returns the number of decimal places for the current currency. + * + * @return int The number of decimal places. + */ public function getFractionDigits(): int { return match ($this) {