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

MoneyTest::testEquals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
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\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