Passed
Push — master ( 07d32f...817bfa )
by Kauri
03:00
created

PaymentPeriodsFactoryTest::datesProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
3
namespace Kauri\Loan\Test;
4
5
6
use Kauri\Loan\PaymentPeriodsFactory;
7
use Kauri\Loan\PaymentScheduleConfig;
8
use Kauri\Loan\PaymentScheduleFactory;
9
use PHPUnit\Framework\TestCase;
10
11
12
class PaymentPeriodsFactoryTest extends TestCase
13
{
14
    /**
15
     * @dataProvider datesProvider
16
     * @param $noOfPayments
17
     * @param \DateTime $startDate
18
     * @param $dateIntervalPattern
19
     * @param array $endDates
20
     * @param array $startDates
21
     * @param array $periodLength
22
     * @param array $numPeriods
23
     */
24
    public function testSomething(
25
        $noOfPayments,
26
        \DateTime $startDate,
27
        $dateIntervalPattern,
28
        array $endDates,
29
        array $startDates,
30
        array $periodLength,
31
        array $numPeriods
32
    ) {
33
        $config = new PaymentScheduleConfig($noOfPayments, $startDate, $dateIntervalPattern);
34
        $schedule = PaymentScheduleFactory::generate($config);
35
        $paymentPeriods = PaymentPeriodsFactory::generate($schedule);
36
37
        foreach ($paymentPeriods->getPeriods() as $no => $period) {
38
            $this->assertEquals($period->getEnd()->format('Y-m-d'), $endDates[$no]);
39
            $this->assertEquals($period->getStart()->format('Y-m-d'), $startDates[$no]);
40
            $this->assertEquals($period->getLength(), $periodLength[$no]);
41
            $this->assertEquals($paymentPeriods->getNumberOfPeriods($period, $paymentPeriods::CALCULATION_TYPE_EXACT),
42
                $numPeriods[$no]);
43
            $this->assertEquals($paymentPeriods->getNumberOfPeriods($period,
44
                $paymentPeriods::CALCULATION_TYPE_EXACT_INTEREST), $noOfPayments);
45
            $this->assertEquals($paymentPeriods->getNumberOfPeriods($period, $paymentPeriods::CALCULATION_TYPE_ANNUITY),
46
                $noOfPayments);
47
        }
48
    }
49
50
    public function datesProvider()
51
    {
52
        return [
53
            'P1D' => [
54
                3,
55
                new \DateTime('2000-01-01'),
56
                'P1D',
57
                [1 => "2000-01-02", "2000-01-03", "2000-01-04"],
58
                [1 => "2000-01-02", "2000-01-03", "2000-01-04"],
59
                [1 => 1, 1, 1],
60
                [1 => 3 / 1, 3 / 1, 3 / 1]
61
            ],
62
            'P3D' => [
63
                3,
64
                new \DateTime('2000-01-01'),
65
                'P3D',
66
                [1 => "2000-01-04", "2000-01-07", "2000-01-10"],
67
                [1 => "2000-01-02", "2000-01-05", "2000-01-08"],
68
                [1 => 3, 3, 3],
69
                [1 => 9 / 3, 9 / 3, 9 / 3]
70
            ],
71
            'P1M' => [
72
                3,
73
                new \DateTime('2000-01-01'),
74
                'P1M',
75
                [1 => "2000-02-01", "2000-03-01", "2000-04-01"],
76
                [1 => "2000-01-02", "2000-02-02", "2000-03-02"],
77
                [1 => 31, 29, 31],
78
                [1 => 91 / 31, 91 / 29, 91 / 31]
79
            ],
80
        ];
81
    }
82
83
}
84