1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
namespace Thunder\Currenz\Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Thunder\Currenz\CurrencyInterface; |
7
|
|
|
|
8
|
|
|
trait TestTrait |
9
|
|
|
{ |
10
|
|
|
private function assertCurrency(CurrencyInterface $currency, string $code, string $name, array $countries, ?int $digits, string $number) |
11
|
|
|
{ |
12
|
|
|
/** @var TestCase $this */ |
13
|
|
|
$this->assertSame($number, $currency->getNumber(), 'ID ('.$code.')'); |
14
|
|
|
$this->assertSame($code, $currency->getCode(), 'Code'); |
15
|
|
|
$this->assertSame($digits, $currency->getDigits(), 'Digits'); |
16
|
|
|
$this->assertSame($name, $currency->getName(), 'Name'); |
17
|
|
|
$this->assertSame($countries, $currency->getCountries(), 'Country'); |
18
|
|
|
|
19
|
|
|
$this->assertTrue($currency->hasCode($code)); |
20
|
|
|
$this->assertTrue($currency->hasCountry($countries[0])); |
21
|
|
|
$this->assertTrue($currency->hasName($name)); |
22
|
|
|
$this->assertTrue($currency->hasNumber($number)); |
23
|
|
|
|
24
|
|
|
$this->assertFalse($currency->hasCode('INVALID')); |
25
|
|
|
$this->assertFalse($currency->hasCountry('INVALID')); |
26
|
|
|
$this->assertFalse($currency->hasName('INVALID')); |
27
|
|
|
$this->assertFalse($currency->hasNumber('INVALID')); |
28
|
|
|
|
29
|
|
|
switch($currency->getDigits()) { |
30
|
|
|
case null: { $this->assertSame(0, $currency->getUnits()); break; } |
|
|
|
|
31
|
|
|
case 0: { $this->assertSame(0, $currency->getUnits()); break; } |
|
|
|
|
32
|
|
|
case 1: { $this->assertSame(10, $currency->getUnits()); break; } |
33
|
|
|
case 2: { $this->assertSame(100, $currency->getUnits()); break; } |
34
|
|
|
case 3: { $this->assertSame(1000, $currency->getUnits()); break; } |
35
|
|
|
case 4: { $this->assertSame(10000, $currency->getUnits()); break; } |
36
|
|
|
default: { throw new \OutOfRangeException(sprintf('Invalid number of currency digits: %s!', $currency->getDigits())); } |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|