|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP Billing Library |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/php-billing |
|
6
|
|
|
* @package php-billing |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hiqdev\php\billing\tests\unit\price; |
|
12
|
|
|
|
|
13
|
|
|
use hiqdev\php\billing\action\Action; |
|
14
|
|
|
use hiqdev\php\billing\price\RatePrice; |
|
15
|
|
|
use hiqdev\php\billing\target\Target; |
|
16
|
|
|
use hiqdev\php\billing\type\Type; |
|
17
|
|
|
use hiqdev\php\units\Quantity; |
|
18
|
|
|
use hiqdev\php\units\QuantityInterface; |
|
19
|
|
|
use Money\Money; |
|
20
|
|
|
use PHPUnit\Framework\TestCase; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author Andrii Vasyliev <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class RatePriceTest extends TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
protected RatePrice $price; |
|
28
|
|
|
protected Action $action; |
|
29
|
|
|
protected Money $money; |
|
30
|
|
|
protected Target $target; |
|
31
|
|
|
protected Type $type; |
|
32
|
|
|
protected int $sum; |
|
33
|
|
|
protected int $rate; |
|
34
|
|
|
protected QuantityInterface $quantity; |
|
35
|
|
|
|
|
36
|
|
|
protected function setUp(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->target = new Target(1, 'client'); |
|
39
|
|
|
$this->type = new Type(null, 'referral'); |
|
40
|
|
|
$this->sum = 123; |
|
41
|
|
|
$this->rate = 5; |
|
42
|
|
|
$this->quantity = Quantity::USD($this->sum/$this->rate); |
|
43
|
|
|
$this->price = new RatePrice(null, $this->type, $this->target, null, $this->rate); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function tearDown(): void |
|
47
|
|
|
{ |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testCalculateUsage() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->assertEquals($this->quantity, $this->price->calculateUsage($this->quantity)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testCalculateSum() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->assertEquals(Money::USD(-$this->sum), $this->price->calculateSum($this->quantity)); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testJsonSerialize() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->assertEquals([ |
|
63
|
|
|
'type' => [ |
|
64
|
|
|
'name' => 'referral', |
|
65
|
|
|
], |
|
66
|
|
|
'rate' => 5, |
|
67
|
|
|
'target' => [ |
|
68
|
|
|
'id' => '1', |
|
69
|
|
|
'type' => 'client', |
|
70
|
|
|
], |
|
71
|
|
|
], json_decode(json_encode($this->price), true)); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|