-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Renamed fraction digit constants for clarity and updated me…
…thod name.
- Loading branch information
1 parent
82c0367
commit 7a37259
Showing
10 changed files
with
136 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
parameters: | ||
paths: | ||
- src | ||
level: 9 | ||
tmpDir: report/phpstan | ||
ignoreErrors: | ||
reportUnmatchedIgnoredErrors: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
bootstrap="vendor/autoload.php" | ||
cacheResultFile="report/.phpunit.result.cache" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
bootstrap="vendor/autoload.php" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
cacheDirectory=".phpunit.cache" | ||
beStrictAboutOutputDuringTests="true"> | ||
|
||
<source> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
</source> | ||
|
||
<testsuites> | ||
<testsuite name="default"> | ||
<directory suffix="Test.php">tests</directory> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
<report> | ||
<text outputFile="report/coverage.txt"/> | ||
<html outputDirectory="report/html/"/> | ||
<clover outputFile="report/coverage-clover.xml"/> | ||
</report> | ||
</coverage> | ||
|
||
<logging> | ||
<junit outputFile="report/execution-result.xml"/> | ||
</logging> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TinyBlocks\Currency; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class CurrencyTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider providerForTestValidNameAndValue | ||
*/ | ||
#[DataProvider('currenciesDataProvider')] | ||
public function testValidNameAndValue(string $name, string $value): void | ||
{ | ||
self::assertEquals(3, strlen($name)); | ||
self::assertEquals(3, strlen($value)); | ||
self::assertSame(3, strlen($name)); | ||
self::assertSame(3, strlen($value)); | ||
} | ||
|
||
/** | ||
* @dataProvider providerForTestGetDefaultFractionDigits | ||
*/ | ||
public function testGetDefaultFractionDigits(int $expected, Currency $currency): void | ||
#[DataProvider('fractionDigitsDataProvider')] | ||
public function testGetFractionDigits(int $expected, Currency $currency): void | ||
{ | ||
$actual = $currency->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] | ||
]; | ||
} | ||
} |