1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kauri\Loan\Test; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Kauri\Loan\PaymentScheduleConfig; |
7
|
|
|
use Kauri\Loan\PaymentSchedule; |
8
|
|
|
use Kauri\Loan\PaymentScheduleFactory; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class PaymentsScheduleTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @dataProvider datesProvider |
15
|
|
|
* @param $paymentDate |
16
|
|
|
*/ |
17
|
|
|
public function testPaymentsSchedule($paymentDate) |
18
|
|
|
{ |
19
|
|
|
$startDate = new \DateTime(); |
20
|
|
|
$config = new PaymentScheduleConfig(3, $startDate, 'P1D'); |
21
|
|
|
|
22
|
|
|
$paymentSchedule = new PaymentSchedule($config); |
23
|
|
|
$paymentSchedule->add($paymentDate); |
24
|
|
|
|
25
|
|
|
$this->assertEquals(1, $paymentSchedule->getNoOfPayments()); |
26
|
|
|
|
27
|
|
|
foreach ($paymentSchedule->getPaymentDates() as $date) { |
28
|
|
|
$this->assertEquals($date, $paymentDate); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testPaymentScheduleConfig() |
33
|
|
|
{ |
34
|
|
|
$noOfPayments = 3; |
35
|
|
|
$startDate = new \DateTime(); |
36
|
|
|
$firstPaymentDate = new \DateTime(); |
37
|
|
|
$config = new PaymentScheduleConfig($noOfPayments, $startDate, 'P1D', $firstPaymentDate); |
38
|
|
|
|
39
|
|
|
$this->assertEquals(1, $config->getAverageIntervalLength()); |
40
|
|
|
|
41
|
|
|
$schedule = PaymentScheduleFactory::generate($config); |
42
|
|
|
|
43
|
|
|
$this->assertEquals($schedule->getNoOfPayments(), $noOfPayments); |
44
|
|
|
$this->assertEquals($noOfPayments, $schedule->getConfig()->getNoOfPayments()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function datesProvider() |
48
|
|
|
{ |
49
|
|
|
return [ |
50
|
|
|
[new \DateTime()] |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|