Completed
Push — master ( 00092a...39103d )
by wiese
86:17 queued 21:06
created

PaymentTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 40
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGivenInvalidInterval_constructorThrowsException() 0 8 1
A invalidIntervalProvider() 0 9 1
A testWhenIntervalIsTwelveMonths_yearlyPaymentIsBasePayment() 0 4 1
A testWhenIntervalIsOneMonth_yearlyPaymentIsTwelveTimesBasePayment() 0 4 1
A testWhenIntervalIsOneQuarter_yearlyPaymentIsFourTimesBasePayment() 0 4 1
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