Failed Conditions
Pull Request — master (#5)
by Kauri
02:41
created

RatePerPeriodTest::testGetRatePerPeriod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 8
loc 8
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 3
1
<?php
2
3
namespace Kauri\Loan\Test;
4
5
6
use Kauri\Loan\PaymentPeriods;
7
use Kauri\Loan\Period;
8
use PHPUnit\Framework\TestCase;
9
10
class RatePerPeriodTest extends TestCase
11
{
12
    /**
13
     * @dataProvider expectedRateData
14
     * @param $calculationMode
15
     * @param $calculateFor
16
     * @param $expected
17
     */
18 View Code Duplication
    public function testGetRatePerPeriod($calculationMode, $calculateFor, $expected)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        $periods = $this->periodsData();
21
22
        foreach ($periods->getPeriods() as $k => $p) {
23
            $this->assertEquals($expected[$k], $periods->getRatePerPeriod($p, 360, $calculationMode, $calculateFor));
24
        }
25
    }
26
27
    /**
28
     * @dataProvider expectedPeriodsData
29
     * @param $calculationMode
30
     * @param $calculateFor
31
     * @param $expected
32
     */
33 View Code Duplication
    public function testGetNumberOfRemainingPeriods($calculationMode, $calculateFor, $expected)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $periods = $this->periodsData();
36
37
        foreach ($periods->getPeriods() as $k => $p) {
38
            $this->assertEquals($expected[$k], $periods->getNumberOfRemainingPeriods($p, $calculationMode, $calculateFor));
39
        }
40
    }
41
42
    public function expectedRateData()
43
    {
44
        return [
45
            [PaymentPeriods::CALCULATION_MODE_AVERAGE, PaymentPeriods::CALCULATE_FOR_PAYMENT, [1 => 30, 30, 30, 30, 30]],
46
            [PaymentPeriods::CALCULATION_MODE_EXACT_INTEREST, PaymentPeriods::CALCULATE_FOR_PAYMENT, [1 => 30, 30, 30, 30, 30]],
47
            [PaymentPeriods::CALCULATION_MODE_EXACT, PaymentPeriods::CALCULATE_FOR_PAYMENT, [1 => 31, 29, 31, 30, 31]],
48
            [PaymentPeriods::CALCULATION_MODE_AVERAGE, PaymentPeriods::CALCULATE_FOR_INTEREST, [1 => 30, 30, 30, 30, 30]],
49
            [PaymentPeriods::CALCULATION_MODE_EXACT_INTEREST, PaymentPeriods::CALCULATE_FOR_INTEREST, [1 => 31, 29, 31, 30, 31]],
50
            [PaymentPeriods::CALCULATION_MODE_EXACT, PaymentPeriods::CALCULATE_FOR_INTEREST, [1 => 31, 29, 31, 30, 31]]
51
        ];
52
    }
53
54
    public function expectedPeriodsData()
55
    {
56
        return [
57
            [PaymentPeriods::CALCULATION_MODE_AVERAGE, PaymentPeriods::CALCULATE_FOR_PAYMENT, [1 => 5, 5, 5, 5, 5]],
58
            [PaymentPeriods::CALCULATION_MODE_EXACT_INTEREST, PaymentPeriods::CALCULATE_FOR_PAYMENT, [1 => 5, 5, 5, 5, 5]],
59
            [PaymentPeriods::CALCULATION_MODE_EXACT, PaymentPeriods::CALCULATE_FOR_PAYMENT, [1 => 152/31, 152/29, 152/31, 152/30, 152/31]],
60
            [PaymentPeriods::CALCULATION_MODE_AVERAGE, PaymentPeriods::CALCULATE_FOR_INTEREST, [1 => 5, 5, 5, 5, 5]],
61
            [PaymentPeriods::CALCULATION_MODE_EXACT_INTEREST, PaymentPeriods::CALCULATE_FOR_INTEREST, [1 => 152/31, 152/29, 152/31, 152/30, 152/31]],
62
            [PaymentPeriods::CALCULATION_MODE_EXACT, PaymentPeriods::CALCULATE_FOR_INTEREST,  [1 => 152/31, 152/29, 152/31, 152/30, 152/31]]
63
        ];
64
    }
65
66
    private function periodsData()
67
    {
68
        $periods = new PaymentPeriods(30);
69
70
        $dates = array(
71
            ['2016-01-01', '2016-01-31'],
72
            ['2016-02-01', '2016-02-29'],
73
            ['2016-03-01', '2016-03-31'],
74
            ['2016-04-01', '2016-04-30'],
75
            ['2016-05-01', '2016-05-31']
76
        );
77
78
        foreach ($dates as $date) {
79
            $period = new Period(new \DateTime($date[0]), new \DateTime($date[1]));
80
            $periods->add($period);
81
        }
82
83
        return $periods;
84
    }
85
}
86