|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\Domain\Model; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
|
|
|
|
|
|
8
|
|
|
use PHPUnit\Framework\Attributes\DataProvider; |
|
|
|
|
|
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use WMDE\Fundraising\AddressChangeContext\Domain\Model\Address; |
|
11
|
|
|
use WMDE\Fundraising\AddressChangeContext\UseCases\ChangeAddress\ChangeAddressValidationException; |
|
12
|
|
|
|
|
13
|
|
|
#[CoversClass( Address::class )] |
|
14
|
|
|
class AddressTest extends TestCase { |
|
15
|
|
|
|
|
16
|
|
|
public function testWhenValidFieldValuesAreUsedForPersonalAddress_addressIsCreated(): void { |
|
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->assertSame( 'Herr', $address->getSalutation() ); |
|
28
|
|
|
$this->assertSame( 'Prof. Dr.', $address->getTitle() ); |
|
29
|
|
|
$this->assertSame( 'Tester', $address->getFirstName() ); |
|
30
|
|
|
$this->assertSame( 'Testfamily', $address->getLastName() ); |
|
31
|
|
|
$this->assertSame( 'Test Street 123', $address->getAddress() ); |
|
32
|
|
|
$this->assertSame( '12345', $address->getPostcode() ); |
|
33
|
|
|
$this->assertSame( 'Test City', $address->getCity() ); |
|
34
|
|
|
$this->assertSame( 'Test Country', $address->getCountry() ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testWhenValidFieldValuesAreUsedForCompanyAddress_addressIsCreated(): void { |
|
38
|
|
|
$address = Address::newCompanyAddress( |
|
39
|
|
|
'Test Company', |
|
40
|
|
|
'Test Street 123', |
|
41
|
|
|
'12345', |
|
42
|
|
|
'Test City', |
|
43
|
|
|
'Test Country' |
|
44
|
|
|
); |
|
45
|
|
|
$this->assertSame( 'Test Company', $address->getCompany() ); |
|
46
|
|
|
$this->assertSame( 'Test Street 123', $address->getAddress() ); |
|
47
|
|
|
$this->assertSame( '12345', $address->getPostcode() ); |
|
48
|
|
|
$this->assertSame( 'Test City', $address->getCity() ); |
|
49
|
|
|
$this->assertSame( 'Test Country', $address->getCountry() ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
#[DataProvider( 'emptyPersonFieldTestProvider' )] |
|
53
|
|
|
public function testWhenNewPersonalAddressWithEmptyFieldsIsCreated_exceptionIsThrownOnEmptyFields( |
|
54
|
|
|
string $testField, |
|
55
|
|
|
string $salutation, |
|
56
|
|
|
string $title, |
|
57
|
|
|
string $firstName, |
|
58
|
|
|
string $lastName, |
|
59
|
|
|
string $address, |
|
60
|
|
|
string $postcode, |
|
61
|
|
|
string $city, |
|
62
|
|
|
string $country ): void { |
|
63
|
|
|
$this->expectException( ChangeAddressValidationException::class ); |
|
64
|
|
|
$this->expectExceptionMessage( sprintf( 'Invalid value for field "%s".', $testField ) ); |
|
65
|
|
|
Address::newPersonalAddress( $salutation, $title, $firstName, $lastName, $address, $postcode, $city, $country ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
#[DataProvider( 'emptyCompanyFieldTestProvider' )] |
|
69
|
|
|
public function testWhenNewCompanyAddressWithEmptyFieldsIsCreated_exceptionIsThrownOnEmptyFields( |
|
70
|
|
|
string $testField, |
|
71
|
|
|
string $company, |
|
72
|
|
|
string $address, |
|
73
|
|
|
string $postcode, |
|
74
|
|
|
string $city, |
|
75
|
|
|
string $country ): void { |
|
76
|
|
|
$this->expectException( ChangeAddressValidationException::class ); |
|
77
|
|
|
$this->expectExceptionMessage( sprintf( 'Invalid value for field "%s".', $testField ) ); |
|
78
|
|
|
Address::newCompanyAddress( $company, $address, $postcode, $city, $country ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return \Generator<string[]> |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function emptyPersonFieldTestProvider(): \Generator { |
|
85
|
|
|
yield [ 'Salutation', '', 'Prof. Dr.', 'Testdude', 'Testfamily', 'Test Address 123', '12345', 'Test City', 'Test Country' ]; |
|
86
|
|
|
yield [ 'First Name', 'Herr', 'Prof. Dr.', '', 'Testfamily', 'Test Address 123', '12345', 'Test City', 'Test Country' ]; |
|
87
|
|
|
yield [ 'Last Name', 'Herr', 'Prof. Dr.', 'Testdude', '', 'Test Address 123', '12345', 'Test City', 'Test Country' ]; |
|
88
|
|
|
yield [ 'Address', 'Herr', 'Prof. Dr.', 'Testdude', 'Testfamily', '', '12345', 'Test City', 'Test Country' ]; |
|
89
|
|
|
yield [ 'Post Code', 'Herr', 'Prof. Dr.', 'Testdude', 'Testfamily', 'Test Address 123', '', 'Test City', 'Test Country' ]; |
|
90
|
|
|
yield [ 'City', 'Herr', 'Prof. Dr.', 'Testdude', 'Testfamily', 'Test Address 123', '12345', '', 'Test Country' ]; |
|
91
|
|
|
yield [ 'Country', 'Herr', 'Prof. Dr.', 'Testdude', 'Testfamily', 'Test Address 123', '12345', 'Test City', '' ]; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return \Generator<string[]> |
|
96
|
|
|
*/ |
|
97
|
|
|
public static function emptyCompanyFieldTestProvider(): \Generator { |
|
98
|
|
|
yield [ 'Company', '', 'Test Street 123', '12345', 'Test City', 'Test Country' ]; |
|
99
|
|
|
yield [ 'Address', 'Test Company', '', '12345', 'Test City', 'Test Country' ]; |
|
100
|
|
|
yield [ 'Post Code', 'Test Company', 'Test Street 123', '', 'Test City', 'Test Country' ]; |
|
101
|
|
|
yield [ 'City', 'Test Company', 'Test Street 123', '12345', '', 'Test Country' ]; |
|
102
|
|
|
yield [ 'Country', 'Test Company', 'Test Street 123', '12345', 'Test City', '' ]; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths