Skip to content

Commit 98fad31

Browse files
authored
Release/2.1.0 (#10)
1 parent 82c0367 commit 98fad31

File tree

10 files changed

+136
-78
lines changed

10 files changed

+136
-78
lines changed

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/tests export-ignore
2+
/vendor export-ignore
3+
4+
/LICENSE export-ignore
5+
/Makefile export-ignore
6+
/README.md export-ignore
7+
/phpmd.xml export-ignore
8+
/phpunit.xml export-ignore
9+
/phpstan.neon.dist export-ignore
10+
/infection.json.dist export-ignore
11+
12+
/.github export-ignore
13+
/.gitignore export-ignore
14+
/.gitattributes export-ignore

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ jobs:
1616
- name: Checkout
1717
uses: actions/checkout@v3
1818

19+
- name: Use PHP 8.2
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.2'
23+
1924
- name: Install dependencies
2025
run: composer update --no-progress --optimize-autoloader
2126

@@ -33,6 +38,11 @@ jobs:
3338
- name: Checkout
3439
uses: actions/checkout@v3
3540

41+
- name: Use PHP 8.2
42+
uses: shivammathur/setup-php@v2
43+
with:
44+
php-version: '8.2'
45+
3646
- name: Install dependencies
3747
run: composer update --no-progress --optimize-autoloader
3848

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.2
22

3-
.PHONY: configure test test-no-coverage review show-reports clean
3+
.PHONY: configure test test-file test-no-coverage review show-reports clean
44

55
configure:
66
@${DOCKER_RUN} composer update --optimize-autoloader
77

8-
test: review
8+
test:
99
@${DOCKER_RUN} composer tests
1010

11-
test-no-coverage: review
11+
test-file:
12+
@${DOCKER_RUN} composer tests-file-no-coverage ${FILE}
13+
14+
test-no-coverage:
1215
@${DOCKER_RUN} composer tests-no-coverage
1316

1417
review:
@@ -19,4 +22,4 @@ show-reports:
1922

2023
clean:
2124
@sudo chown -R ${USER}:${USER} ${PWD}
22-
@rm -rf report vendor
25+
@rm -rf report vendor .phpunit.cache

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ get the default amount fraction digits for the respective currency.
3232
```php
3333
$currency = Currency::USD;
3434

35-
$currency->name; # USD
36-
$currency->value; # USD
37-
$currency->getDefaultFractionDigits(); # 2
35+
$currency->name; # USD
36+
$currency->value; # USD
37+
$currency->getFractionDigits(); # 2
3838
```
3939

4040
<div id='license'></div>

composer.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
"keywords": [
1010
"vo",
1111
"psr",
12-
"psr-4",
13-
"psr-12",
1412
"currency",
1513
"iso-4217",
1614
"tiny-blocks",
@@ -22,6 +20,10 @@
2220
"homepage": "https://github.com/gustavofreze"
2321
}
2422
],
23+
"support": {
24+
"issues": "https://github.com/tiny-blocks/currency/issues",
25+
"source": "https://github.com/tiny-blocks/currency"
26+
},
2527
"config": {
2628
"sort-packages": true,
2729
"allow-plugins": {
@@ -39,24 +41,27 @@
3941
}
4042
},
4143
"require": {
42-
"php": "^8.1||^8.2"
44+
"php": "^8.2"
4345
},
4446
"require-dev": {
45-
"infection/infection": "^0.26",
46-
"phpmd/phpmd": "^2.13",
47-
"phpunit/phpunit": "^9.6",
48-
"squizlabs/php_codesniffer": "^3.7"
47+
"phpmd/phpmd": "^2.15",
48+
"phpunit/phpunit": "^11",
49+
"phpstan/phpstan": "^1",
50+
"infection/infection": "^0.29",
51+
"squizlabs/php_codesniffer": "^3.10"
4952
},
5053
"scripts": {
5154
"phpcs": "phpcs --standard=PSR12 --extensions=php ./src",
5255
"phpmd": "phpmd ./src text phpmd.xml --suffixes php --exclude /src/Currency.php --ignore-violations-on-exit",
56+
"phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress",
5357
"test": "phpunit --log-junit=report/coverage/junit.xml --coverage-xml=report/coverage/coverage-xml --coverage-html=report/coverage/coverage-html tests",
5458
"test-mutation": "infection --only-covered --logger-html=report/coverage/mutation-report.html --coverage=report/coverage --min-msi=100 --min-covered-msi=100 --threads=4",
5559
"test-no-coverage": "phpunit --no-coverage",
5660
"test-mutation-no-coverage": "infection --only-covered --min-msi=100 --threads=4",
5761
"review": [
5862
"@phpcs",
59-
"@phpmd"
63+
"@phpmd",
64+
"@phpstan"
6065
],
6166
"tests": [
6267
"@test",

infection.json.dist

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
{
22
"timeout": 10,
33
"testFramework": "phpunit",
4-
"tmpDir": "report/",
4+
"tmpDir": "report/infection/",
55
"source": {
66
"directories": [
77
"src"
88
]
99
},
1010
"logs": {
11-
"text": "report/logs/infection-text.log",
12-
"summary": "report/logs/infection-summary.log"
11+
"text": "report/infection/logs/infection-text.log",
12+
"summary": "report/infection/logs/infection-summary.log"
1313
},
1414
"mutators": {
15-
"@default": true,
16-
"MatchArmRemoval": false
15+
"@default": true
1716
},
1817
"phpUnit": {
1918
"configDir": "",
2019
"customPath": "./vendor/bin/phpunit"
2120
}
22-
}
21+
}

phpstan.neon.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
paths:
3+
- src
4+
level: 9
5+
tmpDir: report/phpstan
6+
ignoreErrors:
7+
reportUnmatchedIgnoredErrors: false

phpunit.xml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
bootstrap="vendor/autoload.php"
4-
cacheResultFile="report/.phpunit.result.cache"
5-
backupGlobals="false"
6-
backupStaticAttributes="false"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
74
colors="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
processIsolation="false"
12-
stopOnFailure="false"
13-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
5+
bootstrap="vendor/autoload.php"
6+
failOnRisky="true"
7+
failOnWarning="true"
8+
cacheDirectory=".phpunit.cache"
9+
beStrictAboutOutputDuringTests="true">
10+
11+
<source>
12+
<include>
13+
<directory>src</directory>
14+
</include>
15+
</source>
16+
1417
<testsuites>
1518
<testsuite name="default">
16-
<directory suffix="Test.php">tests</directory>
19+
<directory>tests</directory>
1720
</testsuite>
1821
</testsuites>
1922

2023
<coverage>
21-
<include>
22-
<directory suffix=".php">src</directory>
23-
</include>
24+
<report>
25+
<text outputFile="report/coverage.txt"/>
26+
<html outputDirectory="report/html/"/>
27+
<clover outputFile="report/coverage-clover.xml"/>
28+
</report>
2429
</coverage>
30+
31+
<logging>
32+
<junit outputFile="report/execution-result.xml"/>
33+
</logging>
34+
2535
</phpunit>

src/Currency.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TinyBlocks\Currency;
46

57
/**
@@ -180,17 +182,22 @@ enum Currency: string
180182
case ZMW = 'ZMW';
181183
case ZWL = 'ZWL';
182184

183-
public function getDefaultFractionDigits(): int
185+
private const FRACTION_DIGITS_TWO = 2;
186+
private const FRACTION_DIGITS_ZERO = 0;
187+
private const FRACTION_DIGITS_FOUR = 4;
188+
private const FRACTION_DIGITS_THREE = 3;
189+
190+
public function getFractionDigits(): int
184191
{
185192
return match ($this) {
186193
Currency::BIF, Currency::CLP, Currency::DJF, Currency::GNF, Currency::ISK,
187194
Currency::JPY, Currency::KMF, Currency::KRW, Currency::PYG, Currency::RWF,
188195
Currency::UGX, Currency::UYI, Currency::VND, Currency::VUV, Currency::XAF,
189-
Currency::XOF, Currency::XPF => 0,
196+
Currency::XOF, Currency::XPF => self::FRACTION_DIGITS_ZERO,
190197
Currency::BHD, Currency::IQD, Currency::JOD, Currency::KWD, Currency::LYD,
191-
Currency::OMR, Currency::TND => 3,
192-
Currency::CLF, Currency::UYW, => 4,
193-
default => 2
198+
Currency::OMR, Currency::TND => self::FRACTION_DIGITS_THREE,
199+
Currency::CLF, Currency::UYW, => self::FRACTION_DIGITS_FOUR,
200+
default => self::FRACTION_DIGITS_TWO
194201
};
195202
}
196203
}

tests/CurrencyTest.php

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,68 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TinyBlocks\Currency;
46

7+
use PHPUnit\Framework\Attributes\DataProvider;
58
use PHPUnit\Framework\TestCase;
69

710
final class CurrencyTest extends TestCase
811
{
9-
/**
10-
* @dataProvider providerForTestValidNameAndValue
11-
*/
12+
#[DataProvider('currenciesDataProvider')]
1213
public function testValidNameAndValue(string $name, string $value): void
1314
{
14-
self::assertEquals(3, strlen($name));
15-
self::assertEquals(3, strlen($value));
15+
self::assertSame(3, strlen($name));
16+
self::assertSame(3, strlen($value));
1617
}
1718

18-
/**
19-
* @dataProvider providerForTestGetDefaultFractionDigits
20-
*/
21-
public function testGetDefaultFractionDigits(int $expected, Currency $currency): void
19+
#[DataProvider('fractionDigitsDataProvider')]
20+
public function testGetFractionDigits(int $expected, Currency $currency): void
2221
{
23-
$actual = $currency->getDefaultFractionDigits();
22+
$actual = $currency->getFractionDigits();
2423

25-
self::assertEquals($expected, $actual);
24+
self::assertSame($expected, $actual);
2625
}
2726

28-
public function providerForTestValidNameAndValue(): array
27+
public static function currenciesDataProvider(): array
2928
{
30-
return array_map(fn(Currency $currency) => [
29+
return array_map(static fn(Currency $currency): array => [
3130
'name' => $currency->name,
3231
'value' => $currency->value
3332
], Currency::cases());
3433
}
3534

36-
public function providerForTestGetDefaultFractionDigits(): array
35+
public static function fractionDigitsDataProvider(): array
3736
{
3837
return [
39-
[
40-
'expected' => 0,
41-
'currency' => Currency::CLP,
42-
],
43-
[
44-
'expected' => 2,
45-
'currency' => Currency::BRL,
46-
],
47-
[
48-
'expected' => 2,
49-
'currency' => Currency::USD,
50-
],
51-
[
52-
'expected' => 2,
53-
'currency' => Currency::EUR,
54-
],
55-
[
56-
'expected' => 3,
57-
'currency' => Currency::KWD,
58-
],
59-
[
60-
'expected' => 4,
61-
'currency' => Currency::CLF
62-
]
38+
'Currency BIF with digits 0' => ['currency' => Currency::BIF, 'expected' => 0],
39+
'Currency CLP with digits 0' => ['currency' => Currency::CLP, 'expected' => 0],
40+
'Currency DJF with digits 0' => ['currency' => Currency::DJF, 'expected' => 0],
41+
'Currency GNF with digits 0' => ['currency' => Currency::GNF, 'expected' => 0],
42+
'Currency ISK with digits 0' => ['currency' => Currency::ISK, 'expected' => 0],
43+
'Currency JPY with digits 0' => ['currency' => Currency::JPY, 'expected' => 0],
44+
'Currency KMF with digits 0' => ['currency' => Currency::KMF, 'expected' => 0],
45+
'Currency KRW with digits 0' => ['currency' => Currency::KRW, 'expected' => 0],
46+
'Currency PYG with digits 0' => ['currency' => Currency::PYG, 'expected' => 0],
47+
'Currency RWF with digits 0' => ['currency' => Currency::RWF, 'expected' => 0],
48+
'Currency UGX with digits 0' => ['currency' => Currency::UGX, 'expected' => 0],
49+
'Currency UYI with digits 0' => ['currency' => Currency::UYI, 'expected' => 0],
50+
'Currency VND with digits 0' => ['currency' => Currency::VND, 'expected' => 0],
51+
'Currency VUV with digits 0' => ['currency' => Currency::VUV, 'expected' => 0],
52+
'Currency XAF with digits 0' => ['currency' => Currency::XAF, 'expected' => 0],
53+
'Currency XOF with digits 0' => ['currency' => Currency::XOF, 'expected' => 0],
54+
'Currency XPF with digits 0' => ['currency' => Currency::XPF, 'expected' => 0],
55+
'Currency USD with digits 2' => ['currency' => Currency::USD, 'expected' => 2],
56+
'Currency EUR with digits 2' => ['currency' => Currency::EUR, 'expected' => 2],
57+
'Currency BHD with digits 3' => ['currency' => Currency::BHD, 'expected' => 3],
58+
'Currency IQD with digits 3' => ['currency' => Currency::IQD, 'expected' => 3],
59+
'Currency JOD with digits 3' => ['currency' => Currency::JOD, 'expected' => 3],
60+
'Currency KWD with digits 3' => ['currency' => Currency::KWD, 'expected' => 3],
61+
'Currency LYD with digits 3' => ['currency' => Currency::LYD, 'expected' => 3],
62+
'Currency OMR with digits 3' => ['currency' => Currency::OMR, 'expected' => 3],
63+
'Currency TND with digits 3' => ['currency' => Currency::TND, 'expected' => 3],
64+
'Currency CLF with digits 4' => ['currency' => Currency::CLF, 'expected' => 4],
65+
'Currency UYW with digits 4' => ['currency' => Currency::UYW, 'expected' => 4]
6366
];
6467
}
6568
}

0 commit comments

Comments
 (0)