Passed
Push — master ( 7c7ac1...5df575 )
by Mr
02:35
created

MoneyTest::testPercentage()   A

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 1
Bugs 0 Features 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 1
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/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 Daikon\Tests\Money\ValueObject;
10
11
use Daikon\Interop\InvalidArgumentException;
12
use Daikon\Money\ValueObject\Money;
13
use Daikon\Money\ValueObject\MoneyInterface;
14
use PHPUnit\Framework\TestCase;
15
16
final class MoneyTest extends TestCase
17
{
18 1
    public function testFromNative(): void
19
    {
20 1
        $this->assertEquals('100USD', Money::fromNative('100USD')->toNative());
21 1
        $this->assertEquals('-100A', Money::fromNative('-100A')->toNative());
22
23 1
        $this->expectException(InvalidArgumentException::class);
24 1
        Money::fromNative('100');
25
    }
26
27 1
    public function testToString(): void
28
    {
29 1
        $this->assertEquals('100USD1', (string)Money::fromNative('100USD1'));
30 1
        $this->assertEquals('-100A', (string)Money::fromNative('-100A'));
31 1
    }
32
33 1
    public function testZero(): void
34
    {
35 1
        $this->assertEquals('0AB', Money::zero('AB')->toNative());
36
37 1
        $this->expectException(InvalidArgumentException::class);
38 1
        Money::zero();
39
    }
40
41 1
    public function testEquals(): void
42
    {
43 1
        $money = Money::fromNative('0SAT');
44 1
        $this->assertTrue($money->equals(Money::fromNative('0SAT')));
45 1
        $this->assertFalse($money->equals(Money::fromNative('0MSAT')));
46 1
        $this->expectException(InvalidArgumentException::class);
47
        /** @psalm-suppress InvalidArgument */
48 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

48
        $this->assertFalse($money->equals(/** @scrutinizer ignore-type */ 'nan'));
Loading history...
49
    }
50
51 1
    public function testGetAmount(): void
52
    {
53 1
        $money = Money::fromNative('0SAT');
54 1
        $this->assertSame('0', $money->getAmount());
55 1
    }
56
57 1
    public function testGetCurrency(): void
58
    {
59 1
        $money = Money::fromNative('0SAT');
60 1
        $this->assertSame('SAT', $money->getCurrency());
61 1
    }
62
63 1
    public function testPercentage(): void
64
    {
65 1
        $money = Money::fromNative('0SAT');
66 1
        $this->assertEquals('0SAT', (string)$money->percentage(0));
67 1
        $this->assertSame('0SAT', (string)$money->percentage(10));
68 1
        $this->assertSame('0', $money->percentage(10.12345, MoneyInterface::ROUND_UP)->getAmount());
69 1
        $this->assertEquals('0SAT', (string)$money->percentage(100, MoneyInterface::ROUND_DOWN));
70
71 1
        $money = Money::fromNative('100SAT');
72 1
        $this->assertEquals('0SAT', (string)$money->percentage(0));
73 1
        $this->assertSame('10SAT', (string)$money->percentage(10));
74 1
        $this->assertSame('11', $money->percentage(10.12345, MoneyInterface::ROUND_UP)->getAmount());
75 1
        $this->assertSame('10', $money->percentage(10.12345, MoneyInterface::ROUND_DOWN)->getAmount());
76 1
        $this->assertEquals('100SAT', (string)$money->percentage(100, MoneyInterface::ROUND_DOWN));
77 1
    }
78
}
79