Completed
Pull Request — master (#683)
by Jeroen De
51:09
created

newDoctrineCompanyEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Tests\Data;
6
7
use WMDE\Euro\Euro;
8
use WMDE\Fundraising\Entities\MembershipApplication as DoctrineMembershipApplication;
9
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\Applicant;
10
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\ApplicantAddress;
11
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\ApplicantName;
12
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\Application;
13
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\EmailAddress;
14
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\Payment;
15
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\PhoneNumber;
16
use WMDE\Fundraising\Frontend\PaymentContext\Domain\Model\BankData;
17
use WMDE\Fundraising\Frontend\PaymentContext\Domain\Model\Iban;
18
19
/**
20
 * newDomainEntity and newDoctrineEntity return equivalent objects.
21
 *
22
 * @licence GNU GPL v2+
23
 * @author Jeroen De Dauw < [email protected] >
24
 */
25
class ValidMembershipApplication {
26
27
	const APPLICANT_FIRST_NAME = 'Potato';
28
	const APPLICANT_LAST_NAME = 'The Great';
29
	const APPLICANT_SALUTATION = 'Herr';
30
	const APPLICANT_TITLE = '';
31
	const APPLICANT_COMPANY_NAME = 'Evilcrop';
32
33
	const APPLICANT_DATE_OF_BIRTH = '1990-01-01';
34
35
	const APPLICANT_CITY = 'Berlin';
36
	const APPLICANT_COUNTRY_CODE = 'DE';
37
	const APPLICANT_POSTAL_CODE = '1234';
38
	const APPLICANT_STREET_ADDRESS = 'Nyan street';
39
40
	const APPLICANT_EMAIL_ADDRESS = '[email protected]';
41
	const APPLICANT_PHONE_NUMBER = '1337-1337-1337';
42
43
	const MEMBERSHIP_TYPE = Application::SUSTAINING_MEMBERSHIP;
44
	const PAYMENT_PERIOD_IN_MONTHS = 3;
45
	const PAYMENT_AMOUNT_IN_EURO = 10;
46
47
	const PAYMENT_BANK_ACCOUNT = '0648489890';
48
	const PAYMENT_BANK_CODE = '50010517';
49
	const PAYMENT_BANK_NAME = 'ING-DiBa';
50
	const PAYMENT_BIC = 'INGDDEFFXXX';
51
	const PAYMENT_IBAN = 'DE12500105170648489890';
52
53
	const TEMPLATE_CAMPAIGN = 'test161012';
54
	const TEMPLATE_NAME = 'Some_Membership_Form_Template.twig';
55
56
	public static function newDomainEntity(): Application {
57
		$self = ( new self() );
58
		return Application::newApplication(
59
			self::MEMBERSHIP_TYPE,
60
			$self->newApplicant( $self->newPersonApplicantName() ),
61
			$self->newPayment()
62
		);
63
	}
64
65
	public static function newCompanyApplication(): Application {
66
		$self = ( new self() );
67
		return Application::newApplication(
68
			self::MEMBERSHIP_TYPE,
69
			$self->newApplicant( $self->newCompanyApplicantName() ),
70
			$self->newPayment()
71
		);
72
	}
73
74
	private function newApplicant( ApplicantName $name ): Applicant {
75
		return new Applicant(
76
			$name,
77
			$this->newAddress(),
78
			new EmailAddress( self::APPLICANT_EMAIL_ADDRESS ),
79
			new PhoneNumber( self::APPLICANT_PHONE_NUMBER ),
80
			new \DateTime( self::APPLICANT_DATE_OF_BIRTH )
81
		);
82
	}
83
84
	private function newPersonApplicantName(): ApplicantName {
85
		$personName = ApplicantName::newPrivatePersonName();
86
87
		$personName->setFirstName( self::APPLICANT_FIRST_NAME );
88
		$personName->setLastName( self::APPLICANT_LAST_NAME );
89
		$personName->setSalutation( self::APPLICANT_SALUTATION );
90
		$personName->setTitle( self::APPLICANT_TITLE );
91
92
		return $personName->freeze()->assertNoNullFields();
93
	}
94
95
	private function newCompanyApplicantName(): ApplicantName {
96
		$companyName = ApplicantName::newCompanyName();
97
		$companyName->setCompanyName( self::APPLICANT_COMPANY_NAME );
98
99
		return $companyName->freeze()->assertNoNullFields();
100
	}
101
102
	private function newAddress(): ApplicantAddress {
103
		$address = new ApplicantAddress();
104
105
		$address->setCity( self::APPLICANT_CITY );
106
		$address->setCountryCode( self::APPLICANT_COUNTRY_CODE );
107
		$address->setPostalCode( self::APPLICANT_POSTAL_CODE );
108
		$address->setStreetAddress( self::APPLICANT_STREET_ADDRESS );
109
110
		return $address->freeze()->assertNoNullFields();
111
	}
112
113
	private function newPayment(): Payment {
114
		return new Payment(
115
			self::PAYMENT_PERIOD_IN_MONTHS,
116
			Euro::newFromFloat( self::PAYMENT_AMOUNT_IN_EURO ),
117
			$this->newBankData()
118
		);
119
	}
120
121
	private function newBankData(): BankData {
122
		$bankData = new BankData();
123
124
		$bankData->setAccount( self::PAYMENT_BANK_ACCOUNT );
125
		$bankData->setBankCode( self::PAYMENT_BANK_CODE );
126
		$bankData->setBankName( self::PAYMENT_BANK_NAME );
127
		$bankData->setBic( self::PAYMENT_BIC );
128
		$bankData->setIban( new Iban( self::PAYMENT_IBAN ) );
129
130
		return $bankData->freeze()->assertNoNullFields();
131
	}
132
133
	public static function newDoctrineEntity(): DoctrineMembershipApplication {
134
		$application = self::createDoctrineApplicationWithoutApplicantName();
135
136
		$application->setApplicantFirstName( self::APPLICANT_FIRST_NAME );
137
		$application->setApplicantLastName( self::APPLICANT_LAST_NAME );
138
		$application->setApplicantSalutation( self::APPLICANT_SALUTATION );
139
		$application->setApplicantTitle( self::APPLICANT_TITLE );
140
141
		return $application;
142
	}
143
144
	private static function createDoctrineApplicationWithoutApplicantName(): DoctrineMembershipApplication {
145
		$application = new DoctrineMembershipApplication();
146
147
		$application->setStatus( DoctrineMembershipApplication::STATUS_CONFIRMED );
148
149
		$application->setCity( self::APPLICANT_CITY );
150
		$application->setCountry( self::APPLICANT_COUNTRY_CODE );
151
		$application->setPostcode( self::APPLICANT_POSTAL_CODE );
152
		$application->setAddress( self::APPLICANT_STREET_ADDRESS );
153
154
		$application->setApplicantEmailAddress( self::APPLICANT_EMAIL_ADDRESS );
155
		$application->setApplicantPhoneNumber( self::APPLICANT_PHONE_NUMBER );
156
		$application->setApplicantDateOfBirth( new \DateTime( self::APPLICANT_DATE_OF_BIRTH ) );
157
158
		$application->setMembershipType( self::MEMBERSHIP_TYPE );
159
		$application->setPaymentIntervalInMonths( self::PAYMENT_PERIOD_IN_MONTHS );
160
		$application->setPaymentAmount( self::PAYMENT_AMOUNT_IN_EURO );
161
162
		$application->setPaymentBankAccount( self::PAYMENT_BANK_ACCOUNT );
163
		$application->setPaymentBankCode( self::PAYMENT_BANK_CODE );
164
		$application->setPaymentBankName( self::PAYMENT_BANK_NAME );
165
		$application->setPaymentBic( self::PAYMENT_BIC );
166
		$application->setPaymentIban( self::PAYMENT_IBAN );
167
168
		return $application;
169
	}
170
171
	public static function newDoctrineCompanyEntity(): DoctrineMembershipApplication {
172
		$application = self::createDoctrineApplicationWithoutApplicantName();
173
174
		$application->setCompany( self::APPLICANT_COMPANY_NAME );
175
		$application->setApplicantTitle( '' );
176
		$application->setApplicantSalutation( '' );
177
178
		return $application;
179
	}
180
181
}
182