|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +declare(strict_types=1); |
| 4 | + |
3 | 5 | namespace TinyBlocks\Currency; |
4 | 6 |
|
| 7 | +use PHPUnit\Framework\Attributes\DataProvider; |
5 | 8 | use PHPUnit\Framework\TestCase; |
6 | 9 |
|
7 | 10 | final class CurrencyTest extends TestCase |
8 | 11 | { |
9 | | - /** |
10 | | - * @dataProvider providerForTestValidNameAndValue |
11 | | - */ |
| 12 | + #[DataProvider('currenciesDataProvider')] |
12 | 13 | public function testValidNameAndValue(string $name, string $value): void |
13 | 14 | { |
14 | | - self::assertEquals(3, strlen($name)); |
15 | | - self::assertEquals(3, strlen($value)); |
| 15 | + self::assertSame(3, strlen($name)); |
| 16 | + self::assertSame(3, strlen($value)); |
16 | 17 | } |
17 | 18 |
|
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 |
22 | 21 | { |
23 | | - $actual = $currency->getDefaultFractionDigits(); |
| 22 | + $actual = $currency->getFractionDigits(); |
24 | 23 |
|
25 | | - self::assertEquals($expected, $actual); |
| 24 | + self::assertSame($expected, $actual); |
26 | 25 | } |
27 | 26 |
|
28 | | - public function providerForTestValidNameAndValue(): array |
| 27 | + public static function currenciesDataProvider(): array |
29 | 28 | { |
30 | | - return array_map(fn(Currency $currency) => [ |
| 29 | + return array_map(static fn(Currency $currency): array => [ |
31 | 30 | 'name' => $currency->name, |
32 | 31 | 'value' => $currency->value |
33 | 32 | ], Currency::cases()); |
34 | 33 | } |
35 | 34 |
|
36 | | - public function providerForTestGetDefaultFractionDigits(): array |
| 35 | + public static function fractionDigitsDataProvider(): array |
37 | 36 | { |
38 | 37 | 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] |
63 | 66 | ]; |
64 | 67 | } |
65 | 68 | } |
0 commit comments