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-2018, 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\SinglePrice; |
15
|
|
|
use hiqdev\php\billing\target\Target; |
16
|
|
|
use hiqdev\php\billing\type\Type; |
17
|
|
|
use hiqdev\php\units\Quantity; |
18
|
|
|
use Money\Money; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Andrii Vasyliev <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class SinglePriceTest extends \PHPUnit\Framework\TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var SinglePrice |
27
|
|
|
*/ |
28
|
|
|
protected $price; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Action |
32
|
|
|
*/ |
33
|
|
|
protected $action; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Money |
37
|
|
|
*/ |
38
|
|
|
protected $money; |
39
|
|
|
|
40
|
|
|
protected function setUp() |
41
|
|
|
{ |
42
|
|
|
$this->target = new Target(1, 'server'); |
|
|
|
|
43
|
|
|
$this->type = new Type(null, 'server_traf'); |
|
|
|
|
44
|
|
|
$this->quantity = Quantity::gigabyte(10); |
|
|
|
|
45
|
|
|
$this->money = Money::USD(15); |
46
|
|
|
$this->price = new SinglePrice(null, $this->type, $this->target, null, $this->quantity, $this->money); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function tearDown() |
50
|
|
|
{ |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testCalculateUsage() |
54
|
|
|
{ |
55
|
|
|
$this->assertNull($this->price->calculateUsage(Quantity::byte(1))); |
56
|
|
|
$this->assertEquals(Quantity::gigabyte(90), $this->price->calculateUsage(Quantity::gigabyte(100))); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testCalculatePrice() |
60
|
|
|
{ |
61
|
|
|
$this->assertEquals($this->money, $this->price->calculatePrice(Quantity::byte(1))); |
62
|
|
|
$this->assertEquals($this->money, $this->price->calculatePrice(Quantity::megabyte(1))); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testJsonSerialize() |
66
|
|
|
{ |
67
|
|
|
$this->assertEquals([ |
68
|
|
|
'type' => [ |
69
|
|
|
'name' => 'server_traf', |
70
|
|
|
], |
71
|
|
|
'prepaid' => [ |
72
|
|
|
'unit' => 'gigabyte', |
73
|
|
|
'quantity' => 10, |
74
|
|
|
], |
75
|
|
|
'price' => [ |
76
|
|
|
'amount' => '15', |
77
|
|
|
'currency' => 'USD', |
78
|
|
|
], |
79
|
|
|
'target' => [ |
80
|
|
|
'id' => '1', |
81
|
|
|
'type' => 'server', |
82
|
|
|
], |
83
|
|
|
], json_decode(json_encode($this->price), true)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|