1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace hiqdev\php\billing\tests\unit\charge\addons; |
6
|
|
|
|
7
|
|
|
use hiqdev\php\billing\action\Action; |
8
|
|
|
use hiqdev\php\billing\bill\Bill; |
9
|
|
|
use hiqdev\php\billing\charge\Charge; |
10
|
|
|
use hiqdev\php\billing\charge\derivative\ChargeDerivativeQuery; |
11
|
|
|
use hiqdev\php\billing\price\SinglePrice; |
12
|
|
|
use hiqdev\php\billing\target\Target; |
13
|
|
|
use hiqdev\php\billing\target\TargetInterface; |
14
|
|
|
use hiqdev\php\billing\type\Type; |
15
|
|
|
use Money\Currency; |
16
|
|
|
use Money\Money; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class ChargeDerivativeQueryTest |
21
|
|
|
* |
22
|
|
|
* @author Dmytro Naumenko <[email protected]> |
23
|
|
|
* @covers ChargeDerivativeQuery |
24
|
|
|
*/ |
25
|
|
|
class ChargeDerivativeQueryTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
protected ChargeDerivativeQuery $query; |
28
|
|
|
|
29
|
|
|
protected function setUp(): void |
30
|
|
|
{ |
31
|
|
|
parent::setUp(); |
32
|
|
|
$this->query = $this->createQuery(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function createQuery(): ChargeDerivativeQuery |
36
|
|
|
{ |
37
|
|
|
return new ChargeDerivativeQuery(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testChangeId() |
41
|
|
|
{ |
42
|
|
|
$this->query->changeId(1); |
43
|
|
|
$this->assertEquals(1, $this->query->getId()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testChangeTarget() |
47
|
|
|
{ |
48
|
|
|
$query = $this->query; |
49
|
|
|
$target = new Target(TargetInterface::ANY, 'foo'); |
50
|
|
|
$this->assertFalse($query->isChanged('target')); |
51
|
|
|
$query->changeTarget($target); |
52
|
|
|
$this->assertTrue($query->isChanged('target')); |
53
|
|
|
$this->assertEquals($target, $query->getTarget()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testChangeUsage() |
57
|
|
|
{ |
58
|
|
|
$query = $this->query; |
59
|
|
|
$target = new Target(TargetInterface::ANY, 'foo'); |
60
|
|
|
$this->assertFalse($query->isChanged('usage')); |
61
|
|
|
$query->changeTarget($target); |
62
|
|
|
$this->assertTrue($query->isChanged('target')); |
63
|
|
|
$this->assertEquals($target, $query->getTarget()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGet() |
67
|
|
|
{ |
68
|
|
|
$query = $this->query; |
69
|
|
|
|
70
|
|
|
$sum = new Money(0, new Currency('USD')); |
71
|
|
|
$this->assertSame($sum, $query->get('sum', $sum)); |
72
|
|
|
$this->assertNull($query->get('sum')); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testChangeSum() |
76
|
|
|
{ |
77
|
|
|
$query = $this->query; |
78
|
|
|
$this->assertFalse($query->isChanged('sum')); |
79
|
|
|
$sum = new Money(0, new Currency('USD')); |
80
|
|
|
$query->changeSum($sum); |
81
|
|
|
$this->assertTrue($query->isChanged('sum')); |
82
|
|
|
$this->assertEquals($sum, $query->getSum()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testChangeParent() |
86
|
|
|
{ |
87
|
|
|
$query = $this->query; |
88
|
|
|
$this->assertFalse($query->isChanged('parent')); |
89
|
|
|
|
90
|
|
|
/** @var Charge $parent */ |
91
|
|
|
$parent = (new \ReflectionClass(Charge::class))->newInstanceWithoutConstructor(); |
92
|
|
|
|
93
|
|
|
$query->changeParent($parent); |
94
|
|
|
$this->assertTrue($query->isChanged('parent')); |
95
|
|
|
$this->assertEquals($parent, $query->getParent()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testChangeType() |
99
|
|
|
{ |
100
|
|
|
$query = $this->query; |
101
|
|
|
$this->assertFalse($query->isChanged('type')); |
102
|
|
|
$type = Type::anyId('foo'); |
103
|
|
|
$query->changeType($type); |
104
|
|
|
$this->assertTrue($query->isChanged('type')); |
105
|
|
|
$this->assertEquals($type, $query->getType()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testChangeComment() |
109
|
|
|
{ |
110
|
|
|
$query = $this->query; |
111
|
|
|
$this->assertFalse($query->isChanged('comment')); |
112
|
|
|
$query->changeComment('Test comment'); |
113
|
|
|
$this->assertTrue($query->isChanged('comment')); |
114
|
|
|
$this->assertEquals('Test comment', $query->getComment()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testChangePrice() |
118
|
|
|
{ |
119
|
|
|
$query = $this->query; |
120
|
|
|
$this->assertFalse($query->isChanged('price')); |
121
|
|
|
|
122
|
|
|
/** @var SinglePrice $price */ |
123
|
|
|
$price = (new \ReflectionClass(SinglePrice::class))->newInstanceWithoutConstructor(); |
124
|
|
|
|
125
|
|
|
$query->changePrice($price); |
126
|
|
|
$this->assertTrue($query->isChanged('price')); |
127
|
|
|
$this->assertSame($price, $query->getPrice()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function testChangeAction() |
131
|
|
|
{ |
132
|
|
|
$query = $this->query; |
133
|
|
|
$this->assertFalse($query->isChanged('action')); |
134
|
|
|
|
135
|
|
|
/** @var Action $action */ |
136
|
|
|
$action = (new \ReflectionClass(Action::class))->newInstanceWithoutConstructor(); |
137
|
|
|
|
138
|
|
|
$query->changeAction($action); |
139
|
|
|
$this->assertTrue($query->isChanged('action')); |
140
|
|
|
$this->assertSame($action, $query->getAction()); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
public function testChangeBill() |
145
|
|
|
{ |
146
|
|
|
$query = $this->query; |
147
|
|
|
$this->assertFalse($query->isChanged('bill')); |
148
|
|
|
|
149
|
|
|
/** @var Bill $bill */ |
150
|
|
|
$bill = (new \ReflectionClass(Bill::class))->newInstanceWithoutConstructor(); |
151
|
|
|
|
152
|
|
|
$query->changeBill($bill); |
153
|
|
|
$this->assertTrue($query->isChanged('bill')); |
154
|
|
|
$this->assertSame($bill, $query->getBill()); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|