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, substr($subscription->getPropertyRaw('charge_at'), 0, 10)); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function data_for(): array |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
[ |
32
|
|
|
[ |
33
|
|
|
'start_at' => '2020-01-01', |
34
|
|
|
'charge_at' => '', |
35
|
|
|
'billing_period' => BillingPeriod::DAILY, |
36
|
|
|
'billing_interval' => 1 |
37
|
|
|
], |
38
|
|
|
'2020-01-02', |
39
|
|
|
], |
40
|
|
|
[ |
41
|
|
|
[ |
42
|
|
|
'start_at' => '2020-01-01', |
43
|
|
|
'charge_at' => '2020-02-01', |
44
|
|
|
'billing_period' => BillingPeriod::DAILY, |
45
|
|
|
'billing_interval' => 1 |
46
|
|
|
], |
47
|
|
|
'2020-02-02', |
48
|
|
|
], |
49
|
|
|
[ |
50
|
|
|
[ |
51
|
|
|
'start_at' => '2020-01-01', |
52
|
|
|
'billing_period' => BillingPeriod::MONTHLY, |
53
|
|
|
'billing_interval' => 1 |
54
|
|
|
], |
55
|
|
|
'2020-02-01', |
56
|
|
|
], |
57
|
|
|
[ |
58
|
|
|
[ |
59
|
|
|
'start_at' => '2020-01-01', |
60
|
|
|
'charge_at' => '', |
61
|
|
|
'billing_period' => BillingPeriod::WEEKLY, |
62
|
|
|
'billing_interval' => 1 |
63
|
|
|
], |
64
|
|
|
'2020-01-08', |
65
|
|
|
] |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
} |