|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\MembershipContext\Tests\Unit\Domain\Model; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Euro\Euro; |
|
8
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\Payment; |
|
9
|
|
|
use WMDE\Fundraising\Frontend\PaymentContext\Domain\Model\BankData; |
|
10
|
|
|
use WMDE\Fundraising\Frontend\PaymentContext\Domain\Model\DirectDebitPayment; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @covers \WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\Payment |
|
14
|
|
|
* |
|
15
|
|
|
* @license GNU GPL v2+ |
|
16
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
17
|
|
|
*/ |
|
18
|
|
|
class PaymentTest extends \PHPUnit\Framework\TestCase { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @dataProvider invalidIntervalProvider |
|
22
|
|
|
*/ |
|
23
|
|
|
public function testGivenInvalidInterval_constructorThrowsException( int $invalidInterval ): void { |
|
24
|
|
|
$this->expectException( \InvalidArgumentException::class ); |
|
25
|
|
|
new Payment( |
|
26
|
|
|
$invalidInterval, |
|
27
|
|
|
Euro::newFromInt( 42 ), |
|
28
|
|
|
new DirectDebitPayment( new BankData() ) |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function invalidIntervalProvider(): array { |
|
33
|
|
|
return [ |
|
34
|
|
|
'you cant have infinity moneys' => [ 0 ], |
|
35
|
|
|
'time travel is also not allowed' => [ -1 ], |
|
36
|
|
|
'you cant pay 2.4 times per year' => [ 5 ], |
|
37
|
|
|
'you need to pay at least once per year' => [ 13 ], |
|
38
|
|
|
'you need to pay at least once per year!' => [ 24 ], |
|
39
|
|
|
]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testWhenIntervalIsTwelveMonths_yearlyPaymentIsBasePayment(): void { |
|
43
|
|
|
$payment = new Payment( 12, Euro::newFromInt( 42 ), new DirectDebitPayment( new BankData() ) ); |
|
44
|
|
|
$this->assertEquals( 42, $payment->getYearlyAmount()->getEuroFloat() ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testWhenIntervalIsOneMonth_yearlyPaymentIsTwelveTimesBasePayment(): void { |
|
48
|
|
|
$payment = new Payment( 1, Euro::newFromInt( 10 ), new DirectDebitPayment( new BankData() ) ); |
|
49
|
|
|
$this->assertEquals( 120, $payment->getYearlyAmount()->getEuroFloat() ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testWhenIntervalIsOneQuarter_yearlyPaymentIsFourTimesBasePayment(): void { |
|
53
|
|
|
$payment = new Payment( 3, Euro::newFromInt( 50 ), new DirectDebitPayment( new BankData() ) ); |
|
54
|
|
|
$this->assertEquals( 200, $payment->getYearlyAmount()->getEuroFloat() ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|