1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hiqdev\php\billing\tests\behat\bootstrap; |
4
|
|
|
use PHPUnit\Framework\Assert; |
5
|
|
|
|
6
|
|
|
class BillingContext extends BaseContext |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @Given reseller :reseller |
10
|
|
|
*/ |
11
|
|
|
public function reseller($reseller) |
12
|
|
|
{ |
13
|
|
|
$this->builder->buildReseller($reseller); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @Given customer :customer |
18
|
|
|
*/ |
19
|
|
|
public function customer($customer) |
20
|
|
|
{ |
21
|
|
|
$this->builder->buildCustomer($customer); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @Given manager :manager |
26
|
|
|
*/ |
27
|
|
|
public function manager($manager) |
28
|
|
|
{ |
29
|
|
|
$this->builder->buildManager($manager); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @Given /^(grouping )?(\S+) tariff plan (\S+)/ |
34
|
|
|
*/ |
35
|
|
|
public function plan($grouping, $type, $plan) |
36
|
|
|
{ |
37
|
|
|
$this->builder->buildPlan($plan, $type, !empty($grouping)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function fullPrice(array $data) |
41
|
|
|
{ |
42
|
|
|
$this->builder->buildPrice($data); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @Given /price for (\S+) is +(\S+) (\S+) per (\S+) for target (\S+)/ |
47
|
|
|
*/ |
48
|
|
|
public function priceWithObject($type, $price, $currency, $unit, $target) |
49
|
|
|
{ |
50
|
|
|
return $this->fullPrice(compact('type', 'price', 'currency', 'unit', 'target')); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Given /price for (\S+) is +(\S+) (\S+) per (\S+) prepaid (\S+)/ |
55
|
|
|
*/ |
56
|
|
|
public function priceWithOver($type, $price, $currency, $unit, $prepaid) |
57
|
|
|
{ |
58
|
|
|
return $this->fullPrice(compact('type', 'price', 'currency', 'unit', 'prepaid')); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Given /price for (\S+) is +(\S+) (\S+) per (\S+)$/ |
63
|
|
|
*/ |
64
|
|
|
public function price($type, $price, $currency, $unit) |
65
|
|
|
{ |
66
|
|
|
return $this->fullPrice(compact('type', 'price', 'currency', 'unit')); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Given /price for (\S+) is +(\S+) (\S+) per 1 (\S+) and (\S+) (\S+) per 2 (\S+) for target (\S+)/ |
71
|
|
|
*/ |
72
|
|
|
public function enumPrice($type, $price, $currency, $unit, $price2, $currency2, $unit2, $target) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$sums = [1 => $price, 2 => $price2]; |
75
|
|
|
return $this->fullPrice(compact('type', 'sums', 'currency', 'unit', 'target')); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @Given /^remove and recreate tariff plan (\S+)/ |
80
|
|
|
*/ |
81
|
|
|
public function recreatePlan($plan) |
82
|
|
|
{ |
83
|
|
|
$this->builder->recreatePlan($plan); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Given /sale (\S+) for (\S+) plan:(\S+) time:(\S+)/ |
88
|
|
|
*/ |
89
|
|
|
public function sale($id, $target, $plan, $time): void |
90
|
|
|
{ |
91
|
|
|
$this->builder->buildSale($id, $target, $plan, $time); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @Given /resource consumption for (\S+) is (\d+) (\S+) (\S+) for target (\S+)/ |
96
|
|
|
*/ |
97
|
|
|
public function setConsumption($type, $amount, $unit, $time, $target): void |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @Given /perform billing for time (\S+) for sales/ |
103
|
|
|
*/ |
104
|
|
|
public function performBilling($time) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
foreach ($this->sales as $sale) { |
|
|
|
|
107
|
|
|
// TODO: perform billing for sales |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @Given /bill +for (\S+) is +(\S+) (\S+) per (\d+) (\S+) for target (\S+)$/ |
113
|
|
|
*/ |
114
|
|
|
public function bill($type, $sum, $currency, $quantity, $unit, $target) |
115
|
|
|
{ |
116
|
|
|
$target = $this->builder->buildTarget($target); |
117
|
|
|
$bill = $this->builder->findBill([ |
118
|
|
|
'type' => $type, |
119
|
|
|
'target' => $target, |
120
|
|
|
'sum' => "$sum $currency", |
121
|
|
|
'quantity' => "$quantity $unit", |
122
|
|
|
]); |
123
|
|
|
Assert::assertSame($type, $bill->getType()->getName()); |
124
|
|
|
Assert::assertSame($target->getType(), $bill->getTarget()->getType()); |
125
|
|
|
Assert::assertSame($target->getName(), $bill->getTarget()->getName()); |
126
|
|
|
Assert::assertEquals($sum*100, $bill->getSum()->getAmount()); |
127
|
|
|
Assert::assertSame($currency, $bill->getSum()->getCurrency()->getCode()); |
128
|
|
|
Assert::assertEquals($quantity, $bill->getQuantity()->getQuantity()); |
129
|
|
|
Assert::assertSame($unit, $bill->getQuantity()->getUnit()->getName()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @Given /bills number is (\d+) for (\S+) for target (\S+)/ |
134
|
|
|
*/ |
135
|
|
|
public function billsNumber($number, $type, $target) |
136
|
|
|
{ |
137
|
|
|
$count = count($this->builder->findBills([ |
138
|
|
|
'type' => $type, |
139
|
|
|
'target' => $target, |
140
|
|
|
])); |
141
|
|
|
|
142
|
|
|
Assert::assertEquals($number, $count); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @Given /charge for (\S+) is +(\S+) (\S+) per (\d+) (\S+) for target (\S+)$/ |
147
|
|
|
*/ |
148
|
|
|
public function chargeWithTarget($type, $amount, $currency, $quantity, $unit, $target) |
149
|
|
|
{ |
150
|
|
|
$target = $this->builder->buildTarget($target); |
151
|
|
|
$charge = $this->builder->getNextCharge(); |
152
|
|
|
Assert::assertSame($type, $charge->getType()->getName()); |
153
|
|
|
Assert::assertSame($target->getType(), $charge->getTarget()->getType()); |
154
|
|
|
Assert::assertSame($target->getName(), $charge->getTarget()->getName()); |
155
|
|
|
Assert::assertEquals($amount*100, $charge->getSum()->getAmount()); |
156
|
|
|
Assert::assertSame($currency, $charge->getSum()->getCurrency()->getCode()); |
157
|
|
|
Assert::assertSame($quantity, $charge->getUsage()->getQuantity()); |
158
|
|
|
Assert::assertSame($unit, $charge->getUsage()->getUnit()->getName()); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @Given /charge for (\S+) is +(\S+) (\S+) per (\d+) (\S+)$/ |
163
|
|
|
*/ |
164
|
|
|
public function charge($type, $amount, $currency, $quantity, $unit) |
165
|
|
|
{ |
166
|
|
|
$this->chargeWithTarget($type, $amount, $currency, $quantity, $unit, null); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.