1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\Domain\Model; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use WMDE\Fundraising\AddressChange\Domain\Model\Address; |
9
|
|
|
use WMDE\Fundraising\AddressChange\UseCases\ChangeAddress\ChangeAddressValidationException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \WMDE\Fundraising\AddressChange\Domain\Model\Address |
13
|
|
|
*/ |
14
|
|
|
class AddressTest extends TestCase { |
15
|
|
|
|
16
|
|
|
public function testWhenValidFieldValuesAreUsedForPersonalAddress_addressIsCreated() { |
17
|
|
|
$address = Address::newPersonalAddress( |
18
|
|
|
'Herr', |
19
|
|
|
'Prof. Dr.', |
20
|
|
|
'Tester', |
21
|
|
|
'Testfamily', |
22
|
|
|
'Test Street 123', |
23
|
|
|
'12345', |
24
|
|
|
'Test City', |
25
|
|
|
'Test Country' |
26
|
|
|
); |
27
|
|
|
$this->assertTrue( |
28
|
|
|
$address->isPersonalAddress() |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testWhenValidFieldValuesAreUsedForCompanyAddress_addressIsCreated() { |
33
|
|
|
$address = Address::newCompanyAddress( |
34
|
|
|
'Test Company', |
35
|
|
|
'Test Street 123', |
36
|
|
|
'12345', |
37
|
|
|
'Test City', |
38
|
|
|
'Test Country' |
39
|
|
|
); |
40
|
|
|
$this->assertTrue( |
41
|
|
|
$address->isCompanyAddress() |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @dataProvider emptyPersonFieldTestProvider |
47
|
|
|
*/ |
48
|
|
|
public function testWhenNewPersonalAddressWithEmptyFieldsIsCreated_exceptionIsThrownOnEmptyFields( |
49
|
|
|
string $testField, |
50
|
|
|
string $salutation, |
51
|
|
|
string $title, |
52
|
|
|
string $firstName, |
53
|
|
|
string $lastName, |
54
|
|
|
string $address, |
55
|
|
|
string $postcode, |
56
|
|
|
string $city, |
57
|
|
|
string $country ) { |
58
|
|
|
$this->expectException( ChangeAddressValidationException::class ); |
59
|
|
|
$this->expectExceptionMessage( sprintf( 'Invalid value for field "%s".', $testField ) ); |
60
|
|
|
Address::newPersonalAddress( $salutation, $title, $firstName, $lastName, $address, $postcode, $city, $country ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @dataProvider emptyCompanyFieldTestProvider |
65
|
|
|
*/ |
66
|
|
|
public function testWhenNewCompanyAddressWithEmptyFieldsIsCreated_exceptionIsThrownOnEmptyFields( |
67
|
|
|
string $testField, |
68
|
|
|
string $company, |
69
|
|
|
string $address, |
70
|
|
|
string $postcode, |
71
|
|
|
string $city, |
72
|
|
|
string $country ) { |
73
|
|
|
$this->expectException( ChangeAddressValidationException::class ); |
74
|
|
|
$this->expectExceptionMessage( sprintf( 'Invalid value for field "%s".', $testField ) ); |
75
|
|
|
Address::newCompanyAddress( $company, $address, $postcode, $city, $country ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function emptyPersonFieldTestProvider(): \Generator { |
79
|
|
|
yield [ 'Salutation', '', 'Prof. Dr.', 'Testdude', 'Testfamily', 'Test Address 123', '12345', 'Test City', 'Test Country' ]; |
80
|
|
|
yield [ 'First Name', 'Herr', 'Prof. Dr.', '', 'Testfamily', 'Test Address 123', '12345', 'Test City', 'Test Country' ]; |
81
|
|
|
yield [ 'Last Name', 'Herr', 'Prof. Dr.', 'Testdude', '', 'Test Address 123', '12345', 'Test City', 'Test Country' ]; |
82
|
|
|
yield [ 'Address', 'Herr', 'Prof. Dr.', 'Testdude', 'Testfamily', '', '12345', 'Test City', 'Test Country' ]; |
83
|
|
|
yield [ 'Post Code', 'Herr', 'Prof. Dr.', 'Testdude', 'Testfamily', 'Test Address 123', '', 'Test City', 'Test Country' ]; |
84
|
|
|
yield [ 'City', 'Herr', 'Prof. Dr.', 'Testdude', 'Testfamily', 'Test Address 123', '12345', '', 'Test Country' ]; |
85
|
|
|
yield [ 'Country', 'Herr', 'Prof. Dr.', 'Testdude', 'Testfamily', 'Test Address 123', '12345', 'Test City', '' ]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function emptyCompanyFieldTestProvider(): \Generator { |
89
|
|
|
yield [ 'Company', '', 'Test Street 123', '12345', 'Test City', 'Test Country' ]; |
90
|
|
|
yield [ 'Address', 'Test Company', '', '12345', 'Test City', 'Test Country' ]; |
91
|
|
|
yield [ 'Post Code', 'Test Company', 'Test Street 123', '', 'Test City', 'Test Country' ]; |
92
|
|
|
yield [ 'City', 'Test Company', 'Test Street 123', '12345', '', 'Test Country' ]; |
93
|
|
|
yield [ 'Country', 'Test Company', 'Test Street 123', '12345', 'Test City', '' ]; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|