1 | <?php declare(strict_types=1); |
||
2 | /** |
||
3 | * This file is part of the ngutech/money-interop project. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | */ |
||
8 | |||
9 | namespace NGUtech\Tests\Bitcoin\ValueObject; |
||
10 | |||
11 | use Daikon\Interop\InvalidArgumentException; |
||
12 | use NGUtech\Bitcoin\ValueObject\Bitcoin; |
||
13 | use PHPUnit\Framework\TestCase; |
||
14 | |||
15 | final class BitcoinTest extends TestCase |
||
16 | { |
||
17 | 1 | public function testFromNative(): void |
|
18 | { |
||
19 | 1 | $this->assertEquals('100SAT', Bitcoin::fromNative('100SAT')->toNative()); |
|
20 | 1 | $this->assertEquals('-100MSAT', Bitcoin::fromNative('-100MSAT')->toNative()); |
|
21 | |||
22 | 1 | $this->expectException(InvalidArgumentException::class); |
|
23 | 1 | Bitcoin::fromNative('100'); |
|
24 | } |
||
25 | |||
26 | 1 | public function testToString(): void |
|
27 | { |
||
28 | 1 | $this->assertEquals('100BTC', (string)Bitcoin::fromNative('100BTC')); |
|
29 | 1 | $this->assertEquals('-100XBT', (string)Bitcoin::fromNative('-100XBT')); |
|
30 | 1 | } |
|
31 | |||
32 | 1 | public function testZero(): void |
|
33 | { |
||
34 | 1 | $this->assertEquals('0MSAT', Bitcoin::zero()->toNative()); |
|
35 | 1 | $this->assertEquals('0SAT', Bitcoin::zero('SAT')->toNative()); |
|
36 | 1 | $this->expectException(InvalidArgumentException::class); |
|
37 | 1 | Bitcoin::zero('AB'); |
|
38 | } |
||
39 | |||
40 | 1 | public function testEquals(): void |
|
41 | { |
||
42 | 1 | $money = Bitcoin::fromNative('0SAT'); |
|
43 | 1 | $this->assertTrue($money->equals(Bitcoin::fromNative('0SAT'))); |
|
44 | 1 | $this->assertFalse($money->equals(Bitcoin::fromNative('0MSAT'))); |
|
45 | 1 | $this->expectException(InvalidArgumentException::class); |
|
46 | /** @psalm-suppress InvalidArgument */ |
||
47 | 1 | $this->assertFalse($money->equals('nan')); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
48 | } |
||
49 | |||
50 | 1 | public function testGetAmount(): void |
|
51 | { |
||
52 | 1 | $money = Bitcoin::fromNative('0SAT'); |
|
53 | 1 | $this->assertSame('0', $money->getAmount()); |
|
54 | 1 | } |
|
55 | |||
56 | 1 | public function testGetCurrency(): void |
|
57 | { |
||
58 | 1 | $money = Bitcoin::fromNative('0SAT'); |
|
59 | 1 | $this->assertSame('SAT', $money->getCurrency()); |
|
60 | 1 | } |
|
61 | |||
62 | 1 | public function testPercentage(): void |
|
63 | { |
||
64 | 1 | $money = Bitcoin::fromNative('0SAT'); |
|
65 | 1 | $this->assertEquals('0SAT', (string)$money->percentage(0)); |
|
66 | 1 | $this->assertSame('0SAT', (string)$money->percentage(10)); |
|
67 | 1 | $this->assertSame('0', $money->percentage(10.12345, Bitcoin::ROUND_UP)->getAmount()); |
|
68 | 1 | $this->assertEquals('0SAT', (string)$money->percentage(100, Bitcoin::ROUND_DOWN)); |
|
69 | |||
70 | 1 | $money = Bitcoin::fromNative('100SAT'); |
|
71 | 1 | $this->assertEquals('0SAT', (string)$money->percentage(0)); |
|
72 | 1 | $this->assertSame('10SAT', (string)$money->percentage(10)); |
|
73 | 1 | $this->assertSame('11', $money->percentage(10.12345, Bitcoin::ROUND_UP)->getAmount()); |
|
74 | 1 | $this->assertSame('10', $money->percentage(10.12345, Bitcoin::ROUND_DOWN)->getAmount()); |
|
75 | 1 | $this->assertEquals('100SAT', (string)$money->percentage(100, Bitcoin::ROUND_DOWN)); |
|
76 | 1 | } |
|
77 | } |
||
78 |