Passed
Push — master ( 43186b...d45fb7 )
by Gabriel
14:32
created

CalculateNextChargeTest::test_for()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 8
rs 10
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));
0 ignored issues
show
Bug introduced by
It seems like $subscription->getPropertyRaw('charge_at') can also be of type null; however, parameter $string of substr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        self::assertEquals($result, substr(/** @scrutinizer ignore-type */ $subscription->getPropertyRaw('charge_at'), 0, 10));
Loading history...
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
}