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 Daikon\Money\ValueObject\Wallet; |
|
|
|
|
13
|
|
|
use InvalidArgumentException; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
final class WalletTest extends TestCase |
17
|
|
|
{ |
18
|
1 |
|
public function testMakeEmpty(): void |
19
|
|
|
{ |
20
|
1 |
|
$wallet = Wallet::makeEmpty(); |
21
|
1 |
|
$this->assertCount(0, $wallet->unwrap()); |
22
|
1 |
|
} |
23
|
|
|
|
24
|
1 |
|
public function testIsEmpty(): void |
25
|
|
|
{ |
26
|
1 |
|
$wallet = Wallet::makeEmpty(); |
27
|
1 |
|
$this->assertTrue($wallet->isEmpty()); |
28
|
|
|
|
29
|
1 |
|
$wallet = Wallet::makeEmpty()->credit(Money::fromNative('0SAT')); |
30
|
1 |
|
$this->assertTrue($wallet->isEmpty()); |
31
|
|
|
|
32
|
1 |
|
$wallet = Wallet::makeEmpty() |
33
|
1 |
|
->credit(Money::fromNative('0USD')) |
34
|
1 |
|
->credit(Money::fromNative('1MSAT')); |
35
|
1 |
|
$this->assertFalse($wallet->isEmpty()); |
36
|
1 |
|
} |
37
|
|
|
|
38
|
1 |
|
public function testCredit(): void |
39
|
|
|
{ |
40
|
1 |
|
$wallet = Wallet::makeEmpty(); |
41
|
1 |
|
$creditedWallet = $wallet->credit(Money::fromNative('100SAT')); |
42
|
1 |
|
$this->assertEquals(['SAT' => '100SAT'], $creditedWallet->unwrap()); |
43
|
|
|
|
44
|
1 |
|
$wallet = Wallet::makeEmpty(); |
45
|
1 |
|
$creditedWallet = $wallet->credit(Money::fromNative('-100SAT')); |
46
|
1 |
|
$this->assertEquals(['SAT' => '-100SAT'], $creditedWallet->unwrap()); |
47
|
1 |
|
} |
48
|
|
|
|
49
|
1 |
|
public function testDebit(): void |
50
|
|
|
{ |
51
|
1 |
|
$wallet = Wallet::makeEmpty(); |
52
|
1 |
|
$debitedWallet = $wallet->debit(Money::fromNative('100SAT')); |
53
|
1 |
|
$this->assertEquals(['SAT' => '-100SAT'], $debitedWallet->unwrap()); |
54
|
|
|
|
55
|
1 |
|
$wallet = Wallet::makeEmpty(); |
56
|
1 |
|
$debitedWallet = $wallet->debit(Money::fromNative('-100SAT')); |
57
|
1 |
|
$this->assertEquals(['SAT' => '100SAT'], $debitedWallet->unwrap()); |
58
|
1 |
|
} |
59
|
|
|
|
60
|
1 |
|
public function testGetBalance(): void |
61
|
|
|
{ |
62
|
1 |
|
$wallet = Wallet::makeEmpty(); |
63
|
1 |
|
$balance = $wallet->getBalance('X1'); |
64
|
1 |
|
$this->assertInstanceOf(Money::class, $balance); |
65
|
1 |
|
$this->assertEquals(0, $balance->getAmount()); |
66
|
1 |
|
$this->assertEquals('X1', $balance->getCurrency()); |
67
|
|
|
|
68
|
1 |
|
$wallet = Wallet::fromNative(['SAT' => '-100SAT']); |
69
|
1 |
|
$balance = $wallet->getBalance('SAT'); |
70
|
1 |
|
$this->assertEquals('-100SAT', (string)$balance); |
71
|
|
|
|
72
|
1 |
|
$wallet = Wallet::makeEmpty(); |
73
|
1 |
|
$credit = Money::fromNative('100SAT'); |
74
|
1 |
|
$creditedWallet = $wallet->credit($credit); |
75
|
1 |
|
$balance = $creditedWallet->getBalance('SAT'); |
76
|
1 |
|
$this->assertNotSame($credit, $balance); |
77
|
1 |
|
$this->assertEquals($credit, $balance); |
78
|
|
|
|
79
|
|
|
//@todo assertion on lowercase currency key |
80
|
|
|
// $this->expectException(InvalidArgumentException::class); |
81
|
|
|
// Wallet::fromNative(['sat' => '100SAT']); |
82
|
1 |
|
} |
83
|
|
|
} |
84
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths