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\action; |
12
|
|
|
|
13
|
|
|
use DateTimeImmutable; |
14
|
|
|
use hiqdev\php\billing\action\Action; |
15
|
|
|
use hiqdev\php\billing\charge\Charge; |
16
|
|
|
use hiqdev\php\billing\customer\Customer; |
17
|
|
|
use hiqdev\php\billing\price\SinglePrice; |
18
|
|
|
use hiqdev\php\billing\target\Target; |
19
|
|
|
use hiqdev\php\billing\type\Type; |
20
|
|
|
use hiqdev\php\units\Quantity; |
21
|
|
|
use Money\Money; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Andrii Vasyliev <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class ActionTest extends \PHPUnit\Framework\TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var SinglePrice |
30
|
|
|
*/ |
31
|
|
|
protected $price; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Action |
35
|
|
|
*/ |
36
|
|
|
protected $action; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Money |
40
|
|
|
*/ |
41
|
|
|
protected $money; |
42
|
|
|
|
43
|
|
|
protected function setUp() |
44
|
|
|
{ |
45
|
|
|
$this->type = new Type(null, 'server_traf'); |
46
|
|
|
$this->target = new Target(2, 'server'); |
47
|
|
|
$this->prepaid = Quantity::gigabyte(1); |
48
|
|
|
$this->money = Money::USD(10000); |
49
|
|
|
$this->price = new SinglePrice(5, $this->type, $this->target, null, $this->prepaid, $this->money); |
50
|
|
|
$this->customer = new Customer(2, 'client'); |
51
|
|
|
$this->time = new DateTimeImmutable('now'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function createAction($quantity) |
55
|
|
|
{ |
56
|
|
|
return new Action(null, $this->type, $this->target, $quantity, $this->customer, $this->time); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function tearDown() |
60
|
|
|
{ |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testCalculateCharge() |
64
|
|
|
{ |
65
|
|
|
$action = $this->createAction($this->prepaid->multiply(2)); |
66
|
|
|
$charge = $action->calculateCharge($this->price); |
67
|
|
|
$this->assertInstanceOf(Charge::class, $charge); |
68
|
|
|
$this->assertSame($action, $charge->getAction()); |
69
|
|
|
//$this->assertSame($this->target, $charge->getTarget()); |
|
|
|
|
70
|
|
|
$this->assertSame($this->type, $charge->getPrice()->getType()); |
71
|
|
|
$this->assertEquals($this->prepaid, $charge->getUsage()); |
72
|
|
|
$this->assertEquals($this->money->multiply($this->prepaid->getQuantity()), $charge->getSum()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testCalculateChargeNull() |
76
|
|
|
{ |
77
|
|
|
$action = $this->createAction($this->prepaid); |
78
|
|
|
$charge = $action->calculateCharge($this->price); |
79
|
|
|
$this->assertNull($charge); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.