Passed
Push — master ( 62401f...daf94f )
by Alec
07:24
created

AssetsTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 58
dl 0
loc 115
rs 10
c 0
b 0
f 0
wmc 10
1
<?php
2
/**
3
 * User: alec
4
 * Date: 11.11.18
5
 * Time: 20:25
6
 */
7
8
namespace Tests\Unit\Assets;
9
10
use AlecRabbit\Assets\Assets;
11
use AlecRabbit\Money\Currency;
12
use AlecRabbit\Money\Money;
13
use PHPUnit\Framework\TestCase;
14
15
class AssetsTest extends TestCase
16
{
17
    /** @var Assets */
18
    private $assets;
19
20
    /**
21
     * @test
22
     * @dataProvider creationCheckDataProvider
23
     * @param $amount
24
     */
25
    public function createsCorrectly($amount): void
26
    {
27
        $this->assertTrue($this->assets->have($amount));
28
    }
29
30
    /** @test */
31
    public function subtract(): void
32
    {
33
        $this->assertEquals(Money::EUR(10.532), $this->assets->subtract(Money::EUR(1)));
34
        $this->assertEquals(Money::EUR(-0.468), $this->assets->subtract(Money::EUR(11)));
35
        $this->assertEquals(Money::ZEC(-1), $this->assets->subtract(Money::ZEC(1)));
36
    }
37
38
    /** @test */
39
    public function take(): void
40
    {
41
        $this->assertEquals(Money::BTC(1.644), $this->assets->take(Money::BTC(1)));
42
        $this->expectException(\RuntimeException::class);
43
        $this->assertEquals(Money::BTC(-0.356), $this->assets->take(Money::BTC(3)));
44
    }
45
46
    /** @test */
47
    public function add(): void
48
    {
49
        $this->assertEquals(Money::EUR(12.532), $this->assets->add(Money::EUR(1)));
50
        $this->assertEquals(Money::USD(222.777), $this->assets->add(Money::USD(1)));
51
        $this->assertEquals(Money::USDET(161.322), $this->assets->add(Money::USDET(1)));
52
        $money = Money::ZEC(1);
53
        $this->assertEquals($money, $this->assets->add($money));
54
    }
55
56
    /** @test */
57
    public function have(): void
58
    {
59
        $this->assertFalse($this->assets->have(Money::ZEC(1)));
60
        $this->assertTrue($this->assets->have(Money::LTC(1.322)));
61
        $this->assertTrue($this->assets->have(Money::EUR(10.322)));
62
        $this->assertTrue($this->assets->have(Money::EUR(10.322)));
63
        $this->assertFalse($this->assets->have(Money::LTC(1.422)));
64
    }
65
66
    /** @test */
67
    public function getAsset(): void
68
    {
69
        $this->assertEquals(Money::ZEC(0), $this->assets->getAsset(new Currency('Zec')));
70
    }
71
72
    /** @test */
73
    public function getCurrencies(): void
74
    {
75
        $this->assertEquals(
76
            [
77
                0 => 'EUR',
78
                1 => 'BTC',
79
                2 => 'LTC',
80
                3 => 'USD',
81
                4 => 'PPC',
82
                5 => 'NVC',
83
                6 => 'USDET',
84
                7 => 'BTCET',
85
                8 => 'UAH',
86
                9 => 'EURET',
87
            ],
88
            $this->assets->getCurrencies()
89
        );
90
    }
91
92
    public function creationCheckDataProvider(): array
93
    {
94
        return [
95
            [Money::EUR(11.532)],
96
            [Money::UAH(198323.322)],
97
            [Money::BTC(2.644)],
98
            [Money::LTC(1.322)],
99
            [Money::USD(1.322)],
100
            [Money::PPC(1.322)],
101
            [Money::NVC(1090.10)],
102
            [Money::USDET(160.3220)],
103
            [Money::BTCET(0.63220)],
104
            [Money::EURET(10.322)],
105
        ];
106
    }
107
108
    protected function setUp()
109
    {
110
        $this->assets = new Assets(
111
            Money::EUR(10.21),
112
            Money::EUR(1.3220),
113
            Money::BTC(1.3220),
114
            Money::BTC(1.3220),
115
            Money::LTC(1.3220),
116
            Money::USD(1.3220),
117
            Money::PPC(1.3220),
118
            Money::NVC(1090.10),
119
            Money::USD(220.455),
120
            Money::USDET(160.3220),
121
            Money::BTCET(0.63220),
122
            Money::UAH(198323.3220),
123
            Money::EURET(10.3220)
124
        );
125
    }
126
127
    protected function tearDown()
128
    {
129
        unset($this->assets);
130
    }
131
132
133
}
134