BitcoinTest::testPercentage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 14
ccs 12
cts 12
cp 1
crap 1
rs 9.9
c 0
b 0
f 0
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
'nan' of type string is incompatible with the type Daikon\Money\ValueObject\Money expected by parameter $comparator of Daikon\Money\ValueObject\Money::equals(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
        $this->assertFalse($money->equals(/** @scrutinizer ignore-type */ 'nan'));
Loading history...
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