Passed
Push — master ( f22158...709c4a )
by Kauri
31s
created

testGetPaymentAmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 5
1
<?php
2
3
namespace Kauri\Loan\Test;
4
5
6
use Kauri\Loan\PaymentAmountCalculator;
7
use PHPUnit\Framework\TestCase;
8
9
class PaymentAmountCalculatorTest extends TestCase
10
{
11
    /**
12
     * @dataProvider loanData
13
     * @param $amountOfPrincipal
14
     * @param $totalPeriod
15
     * @param $currentPeriod
16
     * @param $yearlyInterestRate
17
     * @param $expected
18
     */
19
    public function testGetPaymentAmount(
20
        $amountOfPrincipal,
21
        $totalPeriod,
22
        $currentPeriod,
23
        $yearlyInterestRate,
24
        $expected
25
    ) {
26
        $presentValue = $amountOfPrincipal;
27
        $ratePerPeriod = $yearlyInterestRate / 360 * $currentPeriod;
28
        $numberOfPeriods = $totalPeriod / $currentPeriod;
29
30
        $calculator = new PaymentAmountCalculator();
31
        $paymentAmount = $calculator->getPaymentAmount($presentValue, $ratePerPeriod, $numberOfPeriods);
32
        $this->assertEquals($expected, round($paymentAmount, 2));
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function loanData()
39
    {
40
        return [
41
            // Exact
42
            [900, 90, 60, 0, 600],
43
            [900, 90, 30, 0, 300],
44
            [900, 90, 60, 360, 1067.42],
45
            [900, 90, 30, 360, 495.56],
46
            // Regular, 30 day month, 360 days a year
47
            [5630, 1800, 30, 9, 116.87], // 60 payments, monthly, 360 days a year
48
            [1000, 60, 30, 0, 500], // 2 payments, monthly, 360 days a year
49
        ];
50
    }
51
}
52