1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Tests\Actions\Subscriptions\Charges; |
4
|
|
|
|
5
|
|
|
use ByTIC\Payments\Actions\Subscriptions\Charges\CalculateNextCharge; |
6
|
|
|
use ByTIC\Payments\Models\Subscriptions\Subscription; |
7
|
|
|
use ByTIC\Payments\Subscriptions\Billing\BillingPeriod; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class CalculateNextChargeTest |
11
|
|
|
* @package ByTIC\Payments\Tests\Actions\Subscriptions\Charges |
12
|
|
|
*/ |
13
|
|
|
class CalculateNextChargeTest extends \ByTIC\Payments\Tests\AbstractTestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @dataProvider data_for |
17
|
|
|
*/ |
18
|
|
|
public function test_for($data, $result) |
19
|
|
|
{ |
20
|
|
|
$subscription = new Subscription(); |
21
|
|
|
$subscription->fill($data); |
22
|
|
|
|
23
|
|
|
CalculateNextCharge::for($subscription); |
24
|
|
|
|
25
|
|
|
self::assertEquals($result, $subscription->getPropertyRaw('charge_at')); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function data_for(): array |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
[ |
32
|
|
|
[ |
33
|
|
|
'start_at' => '2020-01-01', |
34
|
|
|
'charge_count' => '', |
35
|
|
|
'billing_period' => BillingPeriod::DAILY, |
36
|
|
|
'billing_interval' => 1 |
37
|
|
|
], |
38
|
|
|
'2020-01-02 08:00:00', |
39
|
|
|
], |
40
|
|
|
[ |
41
|
|
|
[ |
42
|
|
|
'start_at' => '2020-01-01', |
43
|
|
|
'charge_count' => 4, |
44
|
|
|
'billing_period' => BillingPeriod::DAILY, |
45
|
|
|
'billing_interval' => 1 |
46
|
|
|
], |
47
|
|
|
'2020-01-05 08:00:00', |
48
|
|
|
], |
49
|
|
|
[ |
50
|
|
|
[ |
51
|
|
|
'start_at' => '2020-01-01', |
52
|
|
|
'billing_period' => BillingPeriod::MONTHLY, |
53
|
|
|
'billing_interval' => 1 |
54
|
|
|
], |
55
|
|
|
'2020-02-01 08:00:00', |
56
|
|
|
], |
57
|
|
|
[ |
58
|
|
|
[ |
59
|
|
|
'start_at' => '2021-05-31 00:00:00', |
60
|
|
|
'charge_count' => '', |
61
|
|
|
'billing_period' => BillingPeriod::MONTHLY, |
62
|
|
|
'billing_interval' => 1 |
63
|
|
|
], |
64
|
|
|
'2021-06-30 08:00:00', |
65
|
|
|
], |
66
|
|
|
[ |
67
|
|
|
[ |
68
|
|
|
'start_at' => '2021-05-30 00:00:00', |
69
|
|
|
'charge_count' => '', |
70
|
|
|
'billing_period' => BillingPeriod::MONTHLY, |
71
|
|
|
'billing_interval' => 1 |
72
|
|
|
], |
73
|
|
|
'2021-06-30 08:00:00', |
74
|
|
|
], |
75
|
|
|
[ |
76
|
|
|
[ |
77
|
|
|
'start_at' => '2021-06-30 00:00:00', |
78
|
|
|
'charge_count' => '', |
79
|
|
|
'billing_period' => BillingPeriod::MONTHLY, |
80
|
|
|
'billing_interval' => 1 |
81
|
|
|
], |
82
|
|
|
'2021-07-30 08:00:00', |
83
|
|
|
], |
84
|
|
|
[ |
85
|
|
|
[ |
86
|
|
|
'start_at' => '2021-05-31 00:00:00', |
87
|
|
|
'charge_count' => 2, |
88
|
|
|
'billing_period' => BillingPeriod::MONTHLY, |
89
|
|
|
'billing_interval' => 1 |
90
|
|
|
], |
91
|
|
|
'2021-07-31 08:00:00', |
92
|
|
|
] |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|