Passed
Pull Request — master (#1)
by Kauri
03:58
created

PaymentPeriodsFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 66
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSomething() 0 23 2
B datesProvider() 0 29 1
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 $dates
20
     * @param array $periodLength
21
     * @param array $numPeriods
22
     */
23
    public function testSomething(
24
        $noOfPayments,
25
        \DateTime $startDate,
26
        $dateIntervalPattern,
27
        array $dates,
28
        array $periodLength,
29
        array $numPeriods
30
    ) {
31
        $config = new PaymentScheduleConfig($noOfPayments, $startDate, $dateIntervalPattern);
32
        $schedule = PaymentScheduleFactory::generate($config);
33
        $paymentPeriods = PaymentPeriodsFactory::generate($schedule);
34
35
        foreach ($paymentPeriods->getPeriods() as $no => $period) {
36
            $this->assertEquals($period->getEnd()->format('Y-m-d'), $dates[$no]);
37
            $this->assertEquals($period->getLength(), $periodLength[$no]);
38
            $this->assertEquals($paymentPeriods->getNumberOfPeriods($period, $paymentPeriods::CALCULATION_TYPE_EXACT),
39
                $numPeriods[$no]);
40
            $this->assertEquals($paymentPeriods->getNumberOfPeriods($period,
41
                $paymentPeriods::CALCULATION_TYPE_EXACT_INTEREST), $noOfPayments);
42
            $this->assertEquals($paymentPeriods->getNumberOfPeriods($period, $paymentPeriods::CALCULATION_TYPE_ANNUITY),
43
                $noOfPayments);
44
        }
45
    }
46
47
    public function datesProvider()
48
    {
49
        return [
50
            'P1D' => [
51
                3,
52
                new \DateTime('2000-01-01'),
53
                'P1D',
54
                [1 => "2000-01-02", "2000-01-03", "2000-01-04"],
55
                [1 => 1, 1, 1],
56
                [1 => 3 / 1, 3 / 1, 3 / 1]
57
            ],
58
            'P3D' => [
59
                3,
60
                new \DateTime('2000-01-01'),
61
                'P3D',
62
                [1 => "2000-01-04", "2000-01-07", "2000-01-10"],
63
                [1 => 3, 3, 3],
64
                [1 => 9 / 3, 9 / 3, 9 / 3]
65
            ],
66
            'P1M' => [
67
                3,
68
                new \DateTime('2000-01-01'),
69
                'P1M',
70
                [1 => "2000-02-01", "2000-03-01", "2000-04-01"],
71
                [1 => 31, 29, 31],
72
                [1 => 91 / 31, 91 / 29, 91 / 31]
73
            ],
74
        ];
75
    }
76
77
}
78