Passed
Push — master ( 4b3210...ce7ac7 )
by Mr
06:36
created

MoneyTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 33
ccs 19
cts 21
cp 0.9048
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromNative() 0 7 1
A testToString() 0 4 1
A testZero() 0 6 1
A testEquals() 0 8 1
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\Money\ValueObject\Money;
12
use InvalidArgumentException;
13
use PHPUnit\Framework\TestCase;
14
15
final class MoneyTest extends TestCase
16
{
17 1
    public function testFromNative(): void
18
    {
19 1
        $this->assertEquals('100USD', Money::fromNative('100USD')->toNative());
20 1
        $this->assertEquals('-100A', Money::fromNative('-100A')->toNative());
21
22 1
        $this->expectException(InvalidArgumentException::class);
23 1
        Money::fromNative('100');
24
    }
25
26 1
    public function testToString(): void
27
    {
28 1
        $this->assertEquals('100USD1', (string)Money::fromNative('100USD1'));
29 1
        $this->assertEquals('-100A', (string)Money::fromNative('-100A'));
30 1
    }
31
32 1
    public function testZero(): void
33
    {
34 1
        $this->assertEquals('0AB', Money::zero('AB')->toNative());
35
36 1
        $this->expectException(InvalidArgumentException::class);
37 1
        Money::zero();
38
    }
39
40 1
    public function testEquals(): void
41
    {
42 1
        $money = Money::fromNative('0SAT');
43 1
        $this->assertTrue($money->equals(Money::fromNative('0SAT')));
44 1
        $this->assertFalse($money->equals(Money::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